bkuri / bcson

Reactively edit cson files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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', 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.

About

Reactively edit cson files.

License:MIT License


Languages

Language:CoffeeScript 100.0%