Class: Serialiser

Serialiser

new Serialiser()

Provides functionality to encode and decode JavaScript objects to strings and back again. This differs from JSON.stringify and JSON.parse in that special objects such as dates can be encoded to strings and back again so that the reconstituted version of the string still contains a JavaScript date object.
Source:

Methods

(private) _encode(data) → {*}

Loops the encoders and asks each one if it wants to handle encoding for the passed data object. If no value is returned (undefined) then the data will be passed to the next encoder and so on. If a value is returned the loop will break and the encoded data will be used.
Parameters:
Name Type Description
data Object The data object to handle.
Source:
Returns:
The encoded data.
Type
*

(private) _parse(data, targetopt) → {Object}

Handles restoring an object with special data markers back into it's original format.
Parameters:
Name Type Attributes Description
data Object The object to recurse.
target Object <optional>
The target object to restore data to.
Source:
Returns:
The final restored object.
Type
Object

(private) _stringify(data, targetopt) → {Object}

Recurse down an object and encode special objects so they can be stringified and later restored.
Parameters:
Name Type Attributes Description
data Object The object to parse.
target Object <optional>
The target object to store converted data to.
Source:
Returns:
The converted object.
Type
Object

parse(data) → {Object}

Converts a previously encoded string back into an object.
Parameters:
Name Type Description
data String The string to convert to an object.
Source:
Returns:
The reconstituted object.
Type
Object

registerDecoder(handles, method)

Register a decoder that can handle decoding for a particular object type.
Parameters:
Name Type Description
handles String The name of the handler e.g. $date. When an object has a field matching this handler name then this decode will be invoked to provide a decoded version of the data that was previously encoded by it's counterpart encoder method.
method function The decoder method.
Source:

registerEncoder(handles, method)

Register an encoder that can handle encoding for a particular object type.
Parameters:
Name Type Description
handles String The name of the handler e.g. $date.
method function The encoder method.
Source:

stringify(data)

Converts an object to a encoded string representation.
Parameters:
Name Type Description
data Object The object to encode.
Source: