1.1.7 • Published 7 years ago
bcson v1.1.7
Bind Cson - "bcson"
Bind Cson: Reactive way to read/write cson files using ES6 Proxies.
Shamelessly forked from bjson.
How it works
What do you need to do when you need to edit a cson file programmatically?
| Without bcson | With bcson |
|---|---|
| Create cson file if not exists | |
| Read cson file. | Read cson file (Will create if not exists) |
| Deserialize cson file. | |
| Edit parsed object. | Edit object (Will reactively save in cson file) |
| Serialize new object. | |
| Write back into file. |
Examples
Editing .cson file without bcson
fs = require('fs')
unless fs.existsSync('settings.cson')
cson.writeFileSync 'settings.cson', {}
settings = cson.readFileSync('settings.cson')
settings.foo = 'bar'
cson.writeFileSync 'settings.cson', settingsEditing .cson file with bcson
bcson = require('bcson')
settings = bcson('settings.cson')
settings.foo = 'bar'Getting started
Binding cson
settings.cson
{}whatever.coffee
bcson = require('bcson')
settings = bcson('settings') # will read or create settings.cson
settings.prop = 'bar'
# one liner:
# settings = require('bcson', prop: 'bar')settings.cson:
prop: "bar"whatever.coffee
bcson = require('bcson')
settings = bcson 'settings', {}, (object) ->
console.log JSON.stringify(object)
return
settings.prop = 'foo'
settings.otherprop = 'bar'Test suite
Run npm test. Uses mocha and chai.