Git Product home page Git Product logo

cson-parser's Introduction

cson-parser

A minimalistic CSON parser. Offers:

  • A strict subset of CSON that allows only data
  • Interface is identical to JSON.{parse,stringify}
  • Does not run the code, free of intermediate string representations
  • Sane parse error messages with line/column
  • Regular Expressions are considered data and will be accepted as well

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:

cachedData:
  refreshIntervalMs: 5 * 60 * 1000

Install

npm install --save cson-parser

Usage

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:

  • fs-cson, read and write CSON files
  • CSON, provides file, coffeescript, javascript handling and a CLI
  • season, atom.io's CSON package. Includes CLI tool to convert CSON to JSON
  • grunt-cson, converts CSON to JSON as a grunt task
  • load-grunt-configs, loads grunt config from CSON files (among other formats)
  • fetcher, a declarative way to download (frontend) libraries, supports CSON configs
  • csonschema, parses JSON Schema files written in CSON

You can find more on the npm website.

FAQ

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.

cson-parser's People

Contributors

jkrems avatar i-tier-bot avatar johan avatar abloom avatar balupton avatar bwin avatar kikobeats avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.