Skip to content

Commit

Permalink
Adjusting pull request #10 for the Bevry coding standards. Updated re…
Browse files Browse the repository at this point in the history
…adme with global install instructions in order to use the executables.
  • Loading branch information
balupton committed May 3, 2012
1 parent 1626bae commit ea5bb2f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Which is far more lenient than JSON, nicer to write and read, and won't fail if


- With Node.js in CoffeeScript

``` coffeescript
# Include CSON
CSON = require('cson')
Expand All @@ -92,7 +92,7 @@ Which is far more lenient than JSON, nicer to write and read, and won't fail if
result = CSON.stringifySync(obj) # sync


- Via the command line
- Via the command line (requires a global installation of CSON via `npm install -g cson`)

``` bash
# JSON file to CSON String
Expand All @@ -103,7 +103,6 @@ Which is far more lenient than JSON, nicer to write and read, and won't fail if
```



## History

You can discover the version history inside the [History.md](https://github.com/bevry/cson/blob/master/History.md#files) file
Expand All @@ -121,4 +120,4 @@ Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissi

<small>Sincerely, thank you. Lots of love from the CSON Team</small>

[![Flattr this project](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/344188/balupton-on-Flattr)
[![Flattr this project](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/344188/balupton-on-Flattr)
36 changes: 20 additions & 16 deletions lib/cson.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ coffee = require('coffee-script')
js2coffee = require('js2coffee')
fs = require('fs')

# Awesomeness
wait = (delay,fn) -> setTimeout(fn,delay)

# Define
CSON =
CSON =
# Parse a CSON file
# next(err,obj)
parseFile: (filePath,next) ->
# Read the file
fs.readFile filePath, (err, data) =>
fs.readFile filePath, (err,data) =>
# Check
return next(err) if err

# Parse
dataStr = data.toString()
@parse(dataStr, next)
@parse(dataStr,next)

# Chain
@

Expand All @@ -41,20 +43,21 @@ CSON =


# Parse a CSON string
# next(err, obj)
parse: (src, next) ->
setTimeout =>
# next(err,obj)
parse: (src,next) ->
# currently the parser only exists in a synchronous version
# so we use an instant timeout to simulate async code without any overhead
wait 0, =>
# Parse
result = @parseSync(src)

# Check for error
if result instanceof Error
# Error
next(result)
else
# Success
next(null, result)
, 0
next(null,result)

# Chain
@
Expand All @@ -80,20 +83,21 @@ CSON =

# Turn an object into CSON
# next(err,str)
stringify: (obj, next) ->
setTimeout =>
stringify: (obj,next) ->
# currently the parser only exists in a synchronous version
# so we use an instant timeout to simulate async code without any overhead
wait 0, =>
# Stringify
result = @stringifySync(obj)

# Check
if result instanceof Error
# Error
next(result)
else
# Success
next(null, result)
, 0

next(null,result)

# Chain
@

Expand Down

0 comments on commit ea5bb2f

Please sign in to comment.