"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/cson-parser/README.md" (11 Apr 2017, 2228 Bytes) of package /windows/misc/atom-windows.zip:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.


A minimalistic CSON parser. Offers:

In addition of pure data it allows for simple arithmetic expressions like addition and multiplication. This allows more readable configuration of numbers, the following is a valid strict CSON file:

  refreshIntervalMs: 5 * 60 * 1000


npm install --save cson-parser


CSON = require 'cson-parser'
# This will print { a: '123' }
console.log CSON.parse "a: '123'"

High-level APIs

cson-parser only offers basic parsing and serialization. But there are some great tools if you want more than that:

You can find more on the npm website.


Why not just use YAML?

YAML allows for some pretty complex constructs like anchor and alias, which can behave in unexpected ways, especially with nested objects. CSON is simpler while still offering most of the niceties of YAML.

Why not just use JSON?

JSON doesn't offer multi-line strings and is generally a little noisier. Also sometimes it can be nice to have comments in config files.

Why not just use CoffeeScript directly?

You don't want data files being able to run arbitrary code. Even when ran in a proper sandbox, while(true) is still possible.