Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

alpha-serializer

0.4.0 • 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

install

npm i alpha-serializer

Downloadsweekly downloads

2

version

0.4.0

license

MIT

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability