The Serially Function Serialization Javascript Library
What it does
Serializes circular references and other unserializable types like Dates, .prototype and functions to JSON.
What is supported
Type | JSON.stringify | Serially.serialize |
---|---|---|
Strings | Yes | Yes |
Numbers | Yes | Yes |
Dates | As a string | Yes |
NaN / Infinity / Undefined | No | Yes |
Circular references | No | Yes |
Functions | No | Yes |
Native functions | No | Yes* |
- *Native functions can be optionally ignored, but should be avoided in serialized graphs as a best practice.
Installation
npm install --save serially
Example Usage
As a module:
var should = ;var expect = chaiexpect;chai; var serially = ; var toBeSerialized = int: 1 float: 299e81 str: "test" obj: int: 1 str: "test" nullValue: null arrayValue: {} infinityValue: Infinity negInfinityValue: -Infinity nanValue: NaN dateValue: { return a + b; } ;toBeSerializedcircularReference = toBeSerialized; //Serialize the whole graph to a stringvar str = serially; //Deserialize the graphvar deserialized = serially; toBeSerializedintshould;toBeSerializedstrshould;toBeSerializedfloatshould;toBeSerializedobjintshould;toBeSerializedobjstrshould;to;toBeSerializedinfinityValueshould;toBeSerializednegInfinityValueshould;tobeNaN;toBeSerializedfuncshould;deserializedshould;deserializedcircularReferencecircularReferencecircularReferencecircularReferenceshould;
Contributing
Pull requests are welcome, please file any bugs on https://github.com/tsavo/serially