-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is svgson an async function? #46
Comments
Yes, I tested it. The whole process is synchronous. Maybe it's better to use parseSync . const { parse, stringify } = require('svgson')
console.log('before')
parse(`
<svg>
<line
stroke= "#bada55"
stroke-width= "2"
stroke-linecap= "round"
x1= "70"
y1= "80"
x2= "250"
y2= "150">
</line>
</svg>`).then((json) => {
console.log(JSON.stringify(json, null, 2))
})
console.log('after'); svgson.cjs.js function svgson() {
// console.log('parse', 'cjs')
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return new Promise(function (resolve, reject) {
try {
var res = svgsonSync.apply(void 0, args);
console.log('resolve 前');
resolve(res);
console.log('resolve 后');
} catch (e) {
reject(e);
}
});
} result: before
resolve 前
resolve 后
after
{
"name": "svg",
"type": "element",
"value": "",
"attributes": {},
"children": [
{
"name": "line",
"type": "element",
"value": "",
"attributes": {
"stroke": "#bada55",
"stroke-width": "2",
"stroke-linecap": "round",
"x1": "70",
"y1": "80",
"x2": "250",
"y2": "150"
},
"children": []
}
]
} |
While have no impact on the main package, I am leaving both versions. However I want to hear some more examples, use cases allowing us to choose if remove the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking at the code, it seems that everything is synchronous, so I'm wondering why the export returns a promise?
The text was updated successfully, but these errors were encountered: