-
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
A nicer CSON.stringify #9
Conversation
57686b1
to
230a814
Compare
The problem I have with bundling a CLI tool is that this library is so far most often used as a dependency/basis for others. And adding a random CLI tool 3 times nested somewhere in the dependency tree just adds bloat. For example atom/season uses As for the JSON.stringify({ a: 'b' }, null, 'xx')
// '{\nxx"a": "b"\n}' |
692c45a
to
daa53f6
Compare
Heh, ecma-262 literally does specify the first ten any-chars in the Fixed! Also, nuked cli tools and squashed history. (People really wanting either feature can grab'em off of this archival branch.) |
n = 1 unless n in [1..10] # do not bail on NaN and similar | ||
Array(n + 1).join ' ' | ||
|
||
else ' ' |
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 understand why you are defaulting to two spaces, but I'd like to opt for consistency here - CSON.stringify obj, null, 2
might be a bit more verbose but it's how JSON.stringify
works and less surprising.
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.
While it doesn't feel like CSON without any of CSON's non-JSON properties, you're probably right. Addressing.
Feedback addressed. It somehow didn't even occur to me that |
LGTM - thanks a lot! |
v0.2.0 |
CSON.stringify
CSON.stringify
produce safe CSON that looks nicer than native JSONadd minimaljson2cson
tool that does the same, given valid JSON or CSONadd minimalcson2json
tool to reproduce JSON, given valid JSON or CSONStill handles all the same features as
JSON.stringify
does, the same way, including weird inputs.The main difference between this cson output, and what the
cson
package's json2cson spits out (also what prompted this pull request) are the object literals: this codec always uses curly braces, thus making:instead of:
The latter is less safe, explicit, and convenient, for instance when you have some version controlled cson array which starts out with just one huge object in it. Given the cson-safe serialization, when you later add a new object to the array, there won't be a complete reindentation of the first object. And in the case of a human editing it by hand, the mistake of making the two objects actually become just one merged object is less likely to happen by accident.