alpha-serializer
TypeScript icon, indicating that this package has built-in type declarations

0.5.6 • Public • Published

Alpha-serializer

CircleCI Coverage Status

  • Serializer with support for multiple serialization formats
  • Allows symmetric serialization
  • Support serialization of custom types
  • Properly serializes Map, Set and Date (more in future)

Install

npm install --save alpha-serializer

Usage with global functions

Simples possible example

const {serialize, deserialize} = require('alpha-serializer');
 
const object = {
    map: new Map([['key', 'value']]),
    set: new Set(['value1', 'value2']),
    date: new Date(),
    foo: 'bar'
};
 
const serialized = serialize(object);
// send serialized data to the browser or somewhere else
 
const result = deserialize(object);
 
result.map instanceof Map; // true
result.set instanceof Set; // true
result.date instanceof Date; // true
result.foo; // 'bar'
 
 
const {Serializable, registerNormalization} = require('alpha-serializer');
@Serializable()
class Foo {
    
}
 
// same as above
registerNormalization({clazz: Foo});

Usage as object

Using global object

const {serializer} = require('alpha-serializer');
 
const s = serializer.serialize(new Date());
serializer.deserialize(s);

Use cases

alpha-serializer is particularly usefull when you need to serialize:

  • Simple errors or errors with special properties
  • Value objects (for example ObjectId, Money or Date)
  • Maps, sets and other data structures

More

Dependents (4)

Package Sidebar

Install

npm i alpha-serializer

Weekly Downloads

521

Version

0.5.6

License

MIT

Unpacked Size

59 kB

Total Files

69

Last publish

Collaborators

  • wookieb