This repository is archived, if you'd like to fork the repo and take over the node module please contact me
Read and write CSON to the filesystem, require CSON files
npm install fs-cson
Asynchronously reads the file and parses the contents.
The callback is passed two arguments (err, data)
, where data is the parsed object.
Synchronous version: readFileSync(filePath)
Example
# sample.cson
a: 1
b: 2
# read.coffee
fsCson = require 'fs-cson'
fsCson.readFile 'sample.cson', (err, data) ->
# data will be {a: 1, b: 2}
Allows cson files to be required.
fsCson = require 'fs-cson'
fsCson.register()
# or
require 'fs-cson/register'
Asynchronously reads the file, parses the contents, calls updater, and writes the stringified object.
updater
is passed on argument (data)
and should return the updated data.
The callback is passed one argument (err)
.
Synchronous version: updateFileSync(filePath, updater)
Example
# sample.cson
a: 1
b: 2
# update.coffee
fsCson = require 'fs-cson'
updater = (data) ->
result = {}
for key, value in data
result[key] = value * 2
result.c = 6
result
fsCson.updateFile 'sample.cson', (err) ->
# sample.cson now has the content
# a: 2
# b: 4
# c: 6
Stringifies the object and then asynchronously writes to a file.
The callback is passed one argument (err)
.
Synchronous version: writeFileSync(filePath, object)
# write.coffee
fsCson = require 'fs-cson'
fsCson.writeFile 'sample.cson', {a: 1, b: 2}, (err) ->
# sample.cson now has the content
# a: 1
# b: 2
Same as writeFile
but creates parent directories if they do not exist.
Synchronous version: writeFileSafeSync(filePath, object)