Skip to content

Latest commit

 

History

History
295 lines (213 loc) · 9.83 KB

File metadata and controls

295 lines (213 loc) · 9.83 KB

Classes

JSONStreamEventEmitter

Class representing a JSONStream.

ParserEventEmitter

Class to parse JSON strings into tokens

RendererEventEmitter

Class representing a JSON renderer

JSONStream ⇐ EventEmitter

Class representing a JSONStream.

Kind: global class
Extends: EventEmitter

new JSONStream([opts])

Constructor

Param Type Default Description
[opts] object {} Options, @see Renderer#constructor

jsonStream.write(string) ⇒ Promise

Write a chunk of data to the stream.

Kind: instance method of JSONStream
Returns: Promise - Resolves when the chunk has been written.

Param Type Description
string string The chunk of data to write.

jsonStream.end(string) ⇒ Promise

Write a chunk of data to the stream, then close it

Kind: instance method of JSONStream
Returns: Promise - Resolves when the stream has been closed

Param Type Description
string string The chunk of data to write.

"data"

TODO

Kind: event emitted by JSONStream

"drain"

TODO

Kind: event emitted by JSONStream

"end"

TODO

Kind: event emitted by JSONStream

JSONStream.parse(string, [opts]) ⇒ string

Statically parse a JSON string.

Kind: static method of JSONStream
Returns: string - The parsed JSON string.

Param Type Default Description
string string The JSON string to parse.
[opts] object {} Options, @see Renderer#constructor

JSONStream.stringify(object, [opts]) ⇒ string

Statically parse a javascript object into a JSON string.

Kind: static method of JSONStream
Returns: string - The parsed JSON string.

Param Type Default Description
object object | Array The javascript object to parse
[opts] object {} Options, @see Renderer#constructor

Parser ⇐ EventEmitter

Class to parse JSON strings into tokens

Kind: global class
Extends: EventEmitter

new Parser()

Constructor

parser.closed : boolean

Has the stream been closed?

Kind: instance property of Parser

parser.write(chunk) ⇒ Promise

Add the following chunk to the parser's data stack

Kind: instance method of Parser
Returns: Promise - Resolves when the chunk has been parsed

Param Type
chunk string

parser.end(chunk) ⇒ Promise

Add the following chunk to the parser's data stack, and declare this the end

Kind: instance method of Parser
Returns: Promise - Resolves when the parser has finished

Param Type
chunk string

"close"

TODO

Kind: event emitted by Parser

"drain"

TODO

Kind: event emitted by Parser

"error"

TODO

Kind: event emitted by Parser

"token"

TODO

Kind: event emitted by Parser

Parser.parse(text) ⇒ Promise.<Array.<object>>

Parse the provided text into tokens

Kind: static method of Parser
Returns: Promise.<Array.<object>> - Array of tokens

Param Type
text string

Renderer ⇐ EventEmitter

Class representing a JSON renderer

Kind: global class
Extends: EventEmitter

new Renderer([options])

Constructor

Param Type Default Description
[options] object Options
[options.indent] string "' '" The string to use for indentation
[options.EOL] string "\n" The string to use for EOL
[options.colon] string ":" The string to use for colons
[options.suppress_quotes] boolean true Whether to suppress quotes
[options.escape_whitespace] boolean true Whether to escape (non-space) whitespace
[options.escape_unicode] boolean false Whether to escape unicode characters
[options.colorize] boolean true Whether to colorize the output
[options.quotes_color] string "default" -
[options.quotes_faint] boolean true -
[options.colon_color] string "default" -
[options.colon_faint] boolean true -
[options.comma_color] string "default" -
[options.comma_faint] boolean true -
[options.bracket_color] string "default" -
[options.bracket_faint] boolean true -
[options.key_color] string "white" -
[options.string_color] string "yellow" -
[options.null_color] string "cyan" -
[options.null_bold] string true -
[options.true_color] string "green" -
[options.false_color] string "red" -
[options.number_color] string "#810895" -

renderer.render(tokens) ⇒ string

Render a list of parsed tokens to a string

Kind: instance method of Renderer
Returns: string - The rendered string

Param Type Description
tokens Array.<object> The list of tokens to render

renderer.render_token(token)

Ingest a token for rendering

Kind: instance method of Renderer

Param Type Description
token object The token to render

"data"

TODO

Kind: event emitted by Renderer

Renderer.render(tokens, [opts]) ⇒ string

Render a list of parsed tokens to a string

Kind: static method of Renderer
Returns: string - The rendered string

Param Type Description
tokens Array.<object> The list of tokens to render
[opts] object Options, @see Renderer.constructor