Class CSON

Defined in: src/lib/cson.coffee

Overview

Public: The exported CSON singleton

Instance Method Summary

Instance Method Details

String ::createCSONString(data, opts) 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) :visitor - Boolean The visitor 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) data — Object The data to convert
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (Boolean) visitor — Boolean The visitor 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) 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) :visitor - Boolean The visitor 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) data — Object The data to convert
  • (Object) opts — Object The options (options may also be forwarded onto the parser library)
    • (Boolean) visitor — Boolean The visitor 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) 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) 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(data, opts) 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) 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 ::parse(data, opts) 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) 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 ::parseCSFile(file, opts) 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) 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) 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) data — The CSON String to parse
  • (Object) opts — Object The options, unused

Returns:

Object ::parseCSString(data, opts) 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) data — The CoffeeScript String to parse
  • (Object) opts — Object The options, forwarded onto require('coffee-scriot').eval

Returns:

Object ::parseFile(data, opts) 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) 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) 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) 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) 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) data — The JSON String to parse
  • (Object) opts — Object The options, unused

Returns:

Object ::parseJSString(data, opts) Source

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

Parameters:

  • (String) data — The JavaScript String to parse
  • (Object) opts — Object The options
    • (Object) content — Object The context option that is used in require('vm').runInNewContext, defaults to an empty object {}
    • (Object) filename — Object The filename option that is used in require('vm').runInNewContext, defaults to the filename if specified

Returns:

Object ::parseString(data, opts) 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) 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 ::require(data, opts) 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) 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 ::requireCSFile(file, opts) 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) data — String The file path to require
  • (Object) opts — Object The options, unused

Returns:

Object ::requireCSONFile(file, opts) 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) 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) 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) 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) data — String The file path to require
  • (Object) opts — Object The options, unused

Returns:

Object ::requireJSONFile(file, opts) 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) 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) 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: