Class CSON

Defined in: source/index.coffee

Overview

The exported CSON singleton

Instance Method Summary

Instance Method Details

String ::createCSONString(data, opts, next) Source

Converts an Object into a CSON String

Parameters:

  • (Object) data — Object The data to convert
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (Boolean) replacer — Boolean The replacer option for require('cson-parser').stringify (defaults to null)
    • (Boolean) indent — Boolean The indent option for require('cson-parser').stringify (defaults to a single tab '\t')

Returns:

String ::createJSONString(data, opts, next) Source

Converts an Object into a JSON String

Parameters:

  • (Object) data — Object The data to convert
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (Boolean) replacer — Boolean The replacer option for JSON.stringify (defaults to null)
    • (Boolean) indent — Boolean The indent option for JSON.stringify (defaults to two spaces )

Returns:

String ::createString(data, opts, next) Source

Converts an Object into a String of the desired format

If the format option is not specified, we default to CSON

Parameters:

  • (Object) data — Object The data to convert
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (String) format — String The format to use: "cson" (default), "json", "coffeescript", or "javascript"
    • (Boolean) cson — Boolean Whether or not the CSON format should be allowed (defaults to true)
    • (Boolean) json — Boolean Whether or not the JSON format should be allowed (defaults to true)

Returns:

Object ::load(file, opts, next) Source

Parses a CSON file into an Object

Parameters:

Returns:

Object ::parse(data, opts, next) Source

Parses a CSON String into an Object

Parameters:

  • (String) data — The CSON String to parse
  • (Object) opts — Object The options, unused

Returns:

Object ::parseCSFile(file, opts, next) Source

Parses a CoffeeScript file into an Object

Parameters:

Returns:

Object ::parseCSONFile(file, opts, next) Source

Parses a CSON file into an Object

Parameters:

Returns:

Object ::parseCSONString(data, opts, next) Source

Parses a CSON String into an Object

Parameters:

  • (String) data — The CSON String to parse
  • (Object) opts — Object The options, unused

Returns:

Object ::parseCSString(data, opts, next) Source

Parses a CoffeeScript String into an Object

Parameters:

  • (String) data — The CoffeeScript String to parse
  • (Object) opts — Object The options, forwarded onto require('coffee-script').eval

Returns:

Object ::parseFile(data, opts, next) Source

Parses a file path of the desired format into an Object

If the format option is not specified, we use the filename to detect what it should be, otherwise we default to CSON

Parameters:

  • (String) data — String The file path to parse
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (String) format — String The format to use: "cson" (default), "json", "coffeescript", or "javascript"
    • (Boolean) cson — Boolean Whether or not the CSON format should be allowed (defaults to true)
    • (Boolean) json — Boolean Whether or not the JSON format should be allowed (defaults to true)
    • (Boolean) coffeescript — Boolean Whether or not the CoffeeScript format should be allowed (defaults to false)
    • (Boolean) json — Boolean Whether or not the CoffeeScript format should be allowed (defaults to json)

Returns:

Object ::parseJSFile(file, opts, next) Source

Parses a JAvaScript file into an Object

Parameters:

Returns:

Object ::parseJSONFile(file, opts, next) Source

Parses a JSON file into an Object

Parameters:

Returns:

Object ::parseJSONString(data, opts, next) Source

Parses a JSON String into an Object

Parameters:

  • (String) data — The JSON String to parse
  • (Object) opts — Object The options, unused

Returns:

Object ::parseJSString(data, opts, next) Source

Parses a JavaScript String into an Object

Parameters:

  • (String) data — The JavaScript String to parse
  • (Object) opts — Object The options (also passed to require('vm').runInNewContex)
    • (Object) context — Object The context option that is used in require('vm').runInNewContext, defaults to an empty object {}

Returns:

Object ::parseString(data, opts, next) Source

Converts a String of the desired format into an Object

If the format option is not specified, we default to CSON

Parameters:

  • (String) data — String The string to parse
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (String) format — String The format to use: "cson" (default), "json", "coffeescript", or "javascript"
    • (Boolean) cson — Boolean Whether or not the CSON format should be allowed (defaults to true)
    • (Boolean) json — Boolean Whether or not the JSON format should be allowed (defaults to true)
    • (Boolean) coffeescript — Boolean Whether or not the CoffeeScript format should be allowed (defaults to false)
    • (Boolean) json — Boolean Whether or not the CoffeeScript format should be allowed (defaults to json)

Returns:

Object ::requireCSFile(file, opts, next) Source

Requires a CoffeeScript file and returns the result Object

Parameters:

  • (String) data — String The file path to require
  • (Object) opts — Object The options, unused

Returns:

Object ::requireCSONFile(file, opts, next) Source

Parses a CSON file into an Object

Parameters:

Returns:

Object ::requireFile(data, opts, next) Source

Requires or parses a file path of the desired format into an Object

If the format option is not specified, we use the filename to detect what it should be, otherwise we default to CSON

Parameters:

  • (String) data — String The file path to require or parse
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (String) format — String The format to use: "cson" (default), "json", "coffeescript", or "javascript"
    • (Boolean) cson — Boolean Whether or not the CSON format should be allowed (defaults to true)
    • (Boolean) json — Boolean Whether or not the JSON format should be allowed (defaults to true)
    • (Boolean) coffeescript — Boolean Whether or not the CoffeeScript format should be allowed (defaults to false)
    • (Boolean) json — Boolean Whether or not the CoffeeScript format should be allowed (defaults to json)

Returns:

Object ::requireJSFile(file, opts, next) Source

Requires a JavaScript file and returns the result Object

Parameters:

  • (String) data — String The file path to require
  • (Object) opts — Object The options, unused

Returns:

Object ::requireJSONFile(file, opts, next) Source

Parses a JSON file into an Object

Parameters:

Returns:

String ::stringify(data, opts, next) Source

Converts an Object into a String of the desired format

If the format option is not specified, we default to CSON

Parameters:

  • (Object) data — Object The data to convert
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (String) format — String The format to use: "cson" (default), "json", "coffeescript", or "javascript"
    • (Boolean) cson — Boolean Whether or not the CSON format should be allowed (defaults to true)
    • (Boolean) json — Boolean Whether or not the JSON format should be allowed (defaults to true)

Returns: