1.1.7 • Published 5 years ago

bcson v1.1.7

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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 bcsonWith 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', settings

Editing .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.

1.1.7

5 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago