<!-- TITLE/ -->
# CSON
<!-- /TITLE -->
<!-- BADGES/ -->
[![Build Status](https://img.shields.io/travis/bevry/cson/master.svg)](http://travis-ci.org/bevry/cson "Check this project's build status on TravisCI")
[![NPM version](https://img.shields.io/npm/v/cson.svg)](https://npmjs.org/package/cson "View this project on NPM")
[![NPM downloads](https://img.shields.io/npm/dm/cson.svg)](https://npmjs.org/package/cson "View this project on NPM")
[![Dependency Status](https://img.shields.io/david/bevry/cson.svg)](https://david-dm.org/bevry/cson)
[![Dev Dependency Status](https://img.shields.io/david/dev/bevry/cson.svg)](https://david-dm.org/bevry/cson#info=devDependencies)<br/>
[![Gratipay donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gratipay.com/bevry/ "Donate weekly to this project using Gratipay")
[![Flattr donate button](https://img.shields.io/badge/flattr-donate-yellow.svg)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![BitCoin donate button](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin")
[![Wishlist browse button](https://img.shields.io/badge/wishlist-donate-yellow.svg)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us")
<!-- /BADGES -->
CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.
[Projects using CSON.](https://www.npmjs.org/browse/depended/cson)
[Projects using CSON Parser directly.](https://www.npmjs.org/browse/depended/cson-parser)
<!-- INSTALL/ -->
## Install
### [NPM](http://npmjs.org/)
- Use: `require('cson')`
- Install: `npm install --save cson`
<!-- /INSTALL -->
## What is CSON?
Everyone knows JSON, it's the thing that looks like this:
``` javascript
{
"greatDocumentaries": [
"earthlings.com",
"forksoverknives.com",
"cowspiracy.com"
],
"importantFacts": {
"emissions": "Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.\nGoodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”\nWorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.\nhttp://www.worldwatch.org/node/6294",
"landuse": "Livestock covers 45% of the earth’s total land.\nThornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).\nhttps://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf",
"burger": "One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.\nCatanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.\nhttp://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/\n“50 Ways to Save Your River.” Friends of the River.\nhttp://www.friendsoftheriver.org/site/PageServer?pagename=50ways",
"milk": "1,000 gallons of water are required to produce 1 gallon of milk.\n“Water trivia facts.” United States Environmental Protection Agency.\nhttp://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11",
"more": "http://cowspiracy.com/facts"
}
}
```
Now let's write the same thing in CSON:
``` coffeescript
# Comments!!!
# An Array with no commas!
greatDocumentaries: [
'earthlings.com'
'forksoverknives.com'
'cowspiracy.com'
]
# An Object without braces!
importantFacts:
# Multi-Line Strings! Without Quote Escaping!
emissions: '''
Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
Goodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”
WorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.
http://www.worldwatch.org/node/6294
'''
landuse: '''
Livestock covers 45% of the earth’s total land.
Thornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).
https://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf
'''
burger: '''
One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.
Catanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.
http://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/
“50 Ways to Save Your River.” Friends of the River.
http://www.friendsoftheriver.org/site/PageServer?pagename=50ways
'''
milk: '''
1,000 gallons of water are required to produce 1 gallon of milk.
“Water trivia facts.” United States Environmental Protection Agency.
http://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11
'''
more: 'http://cowspiracy.com/facts'
```
Which is far more lenient that JSON, way nicer to write and read, no need to quote and escape everything, has comments and readable multi-line strings, and won't fail if you forget a comma.
## Using CSON
### Via the Command Line
Use CSON with the command line with:
``` bash
# Convert a JSON file into a CSON file
json2cson in.json > out.cson
# Same thing via piping
cat in.json | json2cson > out.cson
# Convert a CSON file into a JSON file
cson2json in.cson > out.json
# Same thing via piping
cat in.cson | cson2json > out.json
```
Requires a global CSON install: `npm install -g cson`
### Via the API
Each method can be executed without a callback like so:
``` javascript
result = require('CSON').createCSONString({a:{b:'c'}}, {/* optional options argument */})
if ( result instanceof Error ) {
console.log(result.stack)
} else {
console.log(result)
}
```
Or via a callback like so:
``` javascript
CSON.createCSONString({a:{b:'c'}}, {/* optional options argument */}, function(err,result){
console.log(err, result)
})
```
Executing the method with a callback still executes the method synchronously.
Click the below function names to open more detailed documentation.
#### Create Strings
- <a href='http://rawgit.com/bevry/cson/master/docs/classes/CSON.html#stringify-instance'>
String <strong>CSON.stringify</strong>(data, replacer?, indent?)
</a> <br/> Converts an <a href='https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object'>Object</a> into a <a href='https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String'>String</a> of the desired format If the format option is not specified, we default to CSON
- <a href='http://rawgit.com/bevry/cson/master/docs/classes/CSON.html#createString-instance'>
String <strong>CSON.createString</strong>(data, opts?, next?)
</a> <br/> Converts an <a href='https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object'>Object</a> into a <a href='https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String'>String</a> of the desired format If the format option is not specified, we default to CSON
- <a href='http://rawgit.com/bevry/cson/master/docs/classes/CSON.html#createCSONString-instance'>
String <strong>CSON.createCSONString</strong>(data, opts?, next?)
</a> <br/> Converts an <a href='https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object'>Object</a> into a CSON <a href='https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String'>String</a>
- <a href='http://rawgit.com/bevry/cson/master/docs/classes/CSON.html
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Atom(新一代编辑神器)汉化包 (125个子文件)
cake 284B
cake 195B
coffee.cmd 196B
cake.cmd 192B
json2cson.cmd 184B
cson2json.cmd 184B
CNAME 16B
settings.coffee 8KB
main.coffee 2KB
memo.coffee 417B
coffee 288B
coffee 198B
menu_win32.cson 11KB
menu_darwin.cson 7KB
settings.cson 7KB
menu_linux.cson 7KB
context.cson 4KB
cson2json 276B
cson2json 61B
biscotto.css 16KB
.editorconfig 85B
CSON.html 70KB
README.md.html 25KB
HISTORY.md.html 9KB
method_list.html 5KB
LICENSE.md.html 5KB
class_index.html 3KB
extra_list.html 1021B
class_list.html 864B
mixin_list.html 704B
file_list.html 703B
index.html 422B
biscotto.js 163KB
nodes.js 106KB
parser.js 77KB
lexer.js 34KB
grammar.js 20KB
rewriter.js 18KB
command.js 18KB
nakefile.js 13KB
nakefile.js 13KB
cson.js 12KB
coffee-script.js 12KB
helpers.js 7KB
parse.js 7KB
graceful-fs.js 7KB
polyfills.js 6KB
repl.js 6KB
stringify.js 5KB
sourcemap.js 5KB
scope.js 4KB
browser.js 4KB
optparse.js 4KB
typechecker.js 4KB
safefs.js 4KB
safefs.js 3KB
typechecker.js 3KB
cake.js 3KB
cson-cli.js 3KB
legacy-streams.js 3KB
register.js 2KB
search_data.js 2KB
cson-parser.js 2KB
extract-opts.js 1KB
example.js 592B
requirefresh.js 547B
es6guardian.js 465B
fs.js 429B
es6guardian.js 301B
index.js 192B
repl.js 54B
register.js 41B
package.json 10KB
package.json 4KB
package.json 3KB
package.json 3KB
package.json 2KB
package.json 2KB
package.json 2KB
package.json 2KB
package.json 2KB
bower.json 475B
json2cson 276B
json2cson 61B
LICENSE 1KB
LICENSE 1KB
LICENSE 781B
HISTORY.md 21KB
README.md 18KB
README.md 7KB
README.md 5KB
README.md 5KB
README.md 5KB
HISTORY.md 4KB
CHANGELOG.md 3KB
README.md 2KB
README.md 2KB
README.md 2KB
CHANGELOG.md 2KB
LICENSE.md 1KB
共 125 条
- 1
- 2
资源评论
- 毒行江湖2019-12-09东西是不错,只不过后来还是用sumlime了
陈帅同学
- 粉丝: 5
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功