Giter Club home page Giter Club logo

cson's Introduction

CSON

Build Status NPM version Gittip donate button Flattr donate button PayPayl donate button

CoffeeScript-Object-Notation Parser. Same as JSON but for CoffeeScript objects.

Projects using CSON.

Install

  • Use: require('cson')
  • Install: npm install --save cson
  • Use: require('cson')
  • Install: ender add cson

What is CSON?

Everyone knows JSON, it's the thing that looks like this:

{
	"abc": [
		"a",
		"b",
		"c"
	],
	"a": {
		"b": "c"
	}
}

But with the invention of CoffeeScript you can also write the same thing in CSON which looks like this:

{
	# an array
	abc: [
		'a'
		'b'
		'c'
	]

	# an object
	a:
		b: 'c'
}

Which is far more lenient than JSON, way nicer to write and read, no need to quote everything, has comments and readable multi-line strings, and won't fail if you forget a comma.

Using CSON

  • With Node.js in JavaScript

     // Include CSON
     CSON = require('cson');
    
     // Parse a file path
     CSON.parseFile('data.cson', function(err,obj){});  // async
     result = CSON.parseFileSync('data.cson');  // sync
    
     // Parse a String
     CSON.parse(src, function(err,obj){});  // async
     result = CSON.parseSync(src);  // sync
    
     // Stringify an object to CSON
     CSON.stringify(obj, function(err,str){});  // async
     result = CSON.stringifySync(obj);  // sync
  • With Node.js in CoffeeScript

     # Include CSON
     CSON = require('cson')
    
     # Parse a file path
     CSON.parseFile 'data.cson', (err,obj) ->  # async
     result = CSON.parseFileSync('data.cson')  # sync
    
     # Parse a string
     CSON.parse src, (err,obj) ->  # async
     result = CSON.parseSync(src)  # sync
    
     # Stringify an object to CSON
     CSON.stringify data, (err,str) ->  # async
     result = CSON.stringifySync(obj)  # sync
    
    
  • Via the command line (requires a global installation of CSON via npm install -g cson)

     # JSON file to CSON String
     json2cson filePath > out.cson
    
     # CSON file to JSON String
     cson2json filePath > out.json

Use Case

CSON is fantastic for developers writing their own configuration to be executed on their own machines, but bad for configuration you can't trust. This is because parsing CSON will execute the CSON input as CoffeeScript code (making it unsafe, so while true would work) but it does so inside a node virtual machine for isolation (making it secure, so require('fs') won't work) resulting in the evaluated JavaScript object. This is a non-issue for the only use case which CSON actually makes sense for (developers writing their own configuration to be executed on their own machines). Issue #32 has more information.

History

Discover the change history by heading on over to the History.md file.

Contribute

Discover how you can contribute by heading on over to the Contributing.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Gittip donate button Flattr donate button PayPayl donate button

Contributors

These amazing people have contributed code to this project:

Become a contributor!

License

Licensed under the incredibly permissive MIT license

Copyright © 2012+ Bevry Pty Ltd [email protected] (http://bevry.me)
Copyright © 2011 Benjamin Lupton [email protected] (http://balupton.com)

cson's People

Contributors

balupton avatar linus avatar zhangcheng avatar jasonkarns avatar jperras avatar meltingice avatar

Watchers

James Cloos 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.