UNPKG

unserializable

Version:

Utilities for converting unserializable JavaScript objects and instances to serializable objects and vice versa.

40 lines (21 loc) 1.69 kB
# unserializable [![build status](https://img.shields.io/travis/loggur/unserializable/master.svg?style=flat-square)](https://travis-ci.org/loggur/unserializable) [![npm version](https://img.shields.io/npm/v/unserializable.svg?style=flat-square)](https://www.npmjs.com/package/unserializable) [![npm downloads](https://img.shields.io/npm/dm/unserializable.svg?style=flat-square)](https://www.npmjs.com/package/unserializable) Utilities for converting unserializable JavaScript objects and instances to serializable objects and vice versa. ## Installation ``` npm install unserializable --save ``` ## Usage This package exports the following: - `unserializable` - An object containing functions that will convert a serializable value to its unserializable form based on its `type` key. - `serializable` - An object containing functions that will convert an unserializable value to its serializable form based on its `type` key. - `getType(value)` - Gets the `type` of some value if it's unserializable. Currently, the following types are supported: - `Map` - ES6 [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance - `Set` - ES6 [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance - `Date` - [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance - `RegExp` - [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instance **Feel free to submit pull requests for more types!** ## Example See [`redux-replicate-localforage`](https://github.com/loggur/redux-replicate-localforage).