Class CSON

Defined in: src/lib/cson.coffee

Overview

Public: The exported CSON singleton

Instance Method Summary

Instance Method Details

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

Public: Converts an Object into a CSON String data - Object The data to convert opts - Object The options (options may also be forwarded onto the parser library) :replacer - Boolean The replacer option for `require('cson-parser').stringify` (defaults to `null`) :indent - Boolean The indent option for `require('cson-parser').stringify` (defaults to a single tab `'\t'`) Returns String or Error

Parameters:

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

Returns:

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

Public: Converts an Object into a JSON String data - Object The data to convert opts - Object The options (options may also be forwarded onto the parser library) :replacer - Boolean The replacer option for `JSON.stringify` (defaults to `null`) :indent - Boolean The indent option for `JSON.stringify` (defaults to two spaces ` `) Returns String or Error

Parameters:

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

Returns:

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

Public: Converts an Object into a String of the desired format If the format option is not specified, we default to CSON data - Object The data to convert opts - Object The options (options may also be forwarded onto the parser library) :format - String The format to use: "cson" (default), "json", "coffeescript", or "javascript" :cson - Boolean Whether or not the CSON format should be allowed (defaults to `true`) :json - Boolean Whether or not the JSON format should be allowed (defaults to `true`) Returns String or Error

Parameters:

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

Returns:

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

Public: Parses a CSON file into an Object data - String The file path to parse opts - Object The options, forwarded onto ::parseCSONString Returns Object or Error

Parameters:

Returns:

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

Public: Parses a CSON String into an Object data - The CSON String to parse opts - Object The options, unused Returns Object or Error

Parameters:

  • (String) dataThe CSON String to parse
  • (Object) optsObject The options, unused

Returns:

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

Public: Parses a CoffeeScript file into an Object data - String The file path to parse opts - Object The options, forwarded onto ::parseCSString Returns Object or Error

Parameters:

Returns:

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

Public: Parses a CSON file into an Object data - String The file path to parse opts - Object The options, forwarded onto ::parseCSONString Returns Object or Error

Parameters:

Returns:

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

Public: Parses a CSON String into an Object data - The CSON String to parse opts - Object The options, unused Returns Object or Error

Parameters:

  • (String) dataThe CSON String to parse
  • (Object) optsObject The options, unused

Returns:

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

Public: Parses a CoffeeScript String into an Object data - The CoffeeScript String to parse opts - Object The options, forwarded onto `require('coffee-scriot').eval` Returns Object or Error

Parameters:

  • (String) dataThe CoffeeScript String to parse
  • (Object) optsObject The options, forwarded onto require('coffee-scriot').eval

Returns:

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

Public: 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 data - String The file path to parse opts - Object The options (options may also be forwarded onto the parser library) :format - String The format to use: "cson" (default), "json", "coffeescript", or "javascript" :cson - Boolean Whether or not the CSON format should be allowed (defaults to `true`) :json - Boolean Whether or not the JSON format should be allowed (defaults to `true`) :coffeescript - Boolean Whether or not the CoffeeScript format should be allowed (defaults to `false`) :json - Boolean Whether or not the CoffeeScript format should be allowed (defaults to `json`) Returns Object or Error

Parameters:

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

Returns:

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

Public: Parses a JAvaScript file into an Object data - String The file path to parse opts - Object The options, forwarded onto ::parseJSString Returns Object or Error

Parameters:

Returns:

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

Public: Parses a JSON file into an Object data - String The file path to parse opts - Object The options, forwarded onto ::parseJSONString Returns Object or Error

Parameters:

Returns:

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

Public: Parses a JSON String into an Object data - The JSON String to parse opts - Object The options, unused Returns Object or Error

Parameters:

  • (String) dataThe JSON String to parse
  • (Object) optsObject The options, unused

Returns:

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

Public: Parses a JavaScript String into an Object data - The JavaScript String to parse opts - Object The options (also passed to require('vm').runInNewContex) :context - Object The context option that is used in `require('vm').runInNewContext`, defaults to an empty object `` Returns Object or Error

Parameters:

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

Returns:

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

Public: Converts a String of the desired format into an Object If the format option is not specified, we default to CSON data - String The string to parse opts - Object The options (options may also be forwarded onto the parser library) :format - String The format to use: "cson" (default), "json", "coffeescript", or "javascript" :cson - Boolean Whether or not the CSON format should be allowed (defaults to `true`) :json - Boolean Whether or not the JSON format should be allowed (defaults to `true`) :coffeescript - Boolean Whether or not the CoffeeScript format should be allowed (defaults to `false`) :json - Boolean Whether or not the CoffeeScript format should be allowed (defaults to `json`) Returns Object or Error

Parameters:

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

Returns:

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

Public: Requires a CoffeeScript file and returns the result Object data - String The file path to require opts - Object The options, unused Returns Object or Error

Parameters:

  • (String) dataString The file path to require
  • (Object) optsObject The options, unused

Returns:

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

Public: Parses a CSON file into an Object data - String The file path to parse opts - Object The options, forwarded onto ::parseCSONString Returns Object or Error

Parameters:

Returns:

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

Public: 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 data - String The file path to require or parse opts - Object The options (options may also be forwarded onto the parser library) :format - String The format to use: "cson" (default), "json", "coffeescript", or "javascript" :cson - Boolean Whether or not the CSON format should be allowed (defaults to `true`) :json - Boolean Whether or not the JSON format should be allowed (defaults to `true`) :coffeescript - Boolean Whether or not the CoffeeScript format should be allowed (defaults to `false`) :json - Boolean Whether or not the CoffeeScript format should be allowed (defaults to `json`) Returns Object or Error

Parameters:

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

Returns:

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

Public: Requires a JavaScript file and returns the result Object data - String The file path to require opts - Object The options, unused Returns Object or Error

Parameters:

  • (String) dataString The file path to require
  • (Object) optsObject The options, unused

Returns:

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

Public: Parses a JSON file into an Object data - String The file path to parse opts - Object The options, forwarded onto ::parseJSONString Returns Object or Error

Parameters:

Returns:

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

Public: Converts an Object into a String of the desired format If the format option is not specified, we default to CSON data - Object The data to convert opts - Object The options (options may also be forwarded onto the parser library) :format - String The format to use: "cson" (default), "json", "coffeescript", or "javascript" :cson - Boolean Whether or not the CSON format should be allowed (defaults to `true`) :json - Boolean Whether or not the JSON format should be allowed (defaults to `true`) Returns String or Error

Parameters:

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

Returns: