Serialize ImmutableJS data
Installation
yarn add remotedev-serialize
Usage with ImmutableJS data structures
Just pass the Immutable library to our class:
;;const stringify parse = Serialize; const data = Immutable;const serialized = ;console;// {"data":{"foo":"bar","baz":{"data":{"qux":42},"__serializedType__":"ImmutableMap"}},"__serializedType__":"ImmutableMap"}const parsed = ;console;// true
See the tests for more examples of usage.
Usage with ImmutableJS Record classes
To parse a Record class back, you need to specify a reference to it:
;; const ABRecord = Immutable;const stringify parse = Serialize; const myRecord = b: 3 ;const serialized = ;console;// {"data":{"a":1,"b":3},"__serializedType__":"ImmutableRecord","__serializedRef__":0}const parsed = ;console;// true
Passing custom serialization functions
You can pass custom replacer and reviver functions to Serialize:
;; { if value === 1 return data: 'one' __serializedType__: 'number' ; return ;} { if typeof value === 'object' && value__serializedType__ === 'number' && valuedata === 'one' return 1; return ;} const stringify parse = Serialize; const map = Immutable;const serialized = ;console;// {"data":{"a":{"data":"one","__serializedType__":"number"},"b":2},"__serializedType__":"ImmutableMap"}const parsed = ;console;// true
Supported
ImutableJS
- Record
- Range
- Repeat
- Map
- OrderedMap
- List
- Set
- OrderedSet
- Seq
- Stack
ES6
- Symbol
- Map
- Set
- Typed Array
License
MIT