-
-
Notifications
You must be signed in to change notification settings - Fork 208
Allow non alpha keys #34
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
Conversation
|
I think you should have an helper that spits out I think the problem you are encountering is because the same logic works for both object and arrays. |
|
Wouldn't this be a problem for all keys not being Aa-Zz? |
|
@SimenB very probably. |
|
I'm a bit stuck here... Why is key prefixed with |
|
@mcollina I made it green at least. Not too happy with the implementation though... Ideas? |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use the dot notation wherever possible. It should be faster.
Is this impacting benchmarks anyhow?
| // see https://github.com/mcollina/fast-json-stringify/pull/3 for discussion. | ||
| code += ` | ||
| if (obj.${key} !== undefined) { | ||
| if (obj['${key}'] !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use the same accessor here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accessor is in the nested function, not up here.
|
Benchmarks (on [email protected]): This branch: |
|
I tested it out (because why not). Result Diff: diff --git i/index.js w/index.js
index ff80f46..d51febb 100644
--- i/index.js
+++ w/index.js
@@ -1,6 +1,7 @@
'use strict'
const fastSafeStringify = require('fast-safe-stringify')
+const uglify = require('uglify-es')
let isLong
try {
@@ -74,10 +75,16 @@ function build (schema, options) {
;
return ${main}
`
+
+ const uglified = uglify.minify(code, {parse: {bare_returns: true}})
+
+ if (uglified.error) {
+ throw uglified.error
+ }
if (schema.additionalProperties === true) {
- return (new Function('fastSafeStringify', code))(fastSafeStringify)
+ return (new Function('fastSafeStringify', uglified.code))(fastSafeStringify)
}
- return (new Function(code))()
+ return (new Function(uglified.code))()
}
function $asNull () {
diff --git i/package.json w/package.json
index 5ebd8a8..0fb85b9 100644
--- i/package.json
+++ w/package.json
@@ -32,6 +32,7 @@
"tap": "^10.3.0"
},
"dependencies": {
- "fast-safe-stringify": "^1.1.11"
+ "fast-safe-stringify": "^1.1.11",
+ "uglify-es": "^3.0.9"
}
} |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Regarding uglify, I'm definitely +1, as the numbers look nice. I would like to have that but avoid a direct dependency to uglify, as this module is tight and nice. Would you like to send a PR?
|
How would we pass it through a minimizer without depending on the minimizer? Try to require it in case it's available? |
|
you can try requiring it, and if it is there use it. Plus, we can put it
under an option as well.
Il giorno sab 20 mag 2017 alle 20:43 Simen Bekkhus <[email protected]>
ha scritto:
… How would we pass it through a minimizer without depending on the
minimizer?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#34 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADL4zT9T9oZSSRFx2DmOWKevYgWnu1Pks5r7zRjgaJpZM4NgZ7F>
.
|
|
Cool, PR sent 😄 Will you be able to merge and release this and #35 by Monday? |

I tried this:
The top part worked fine, it failed a bunch of tests with the second one, though