You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

hydration

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hydration

Type-accurate serialization of javascript objects

1.0.0
latest
npmnpm
Version published
Weekly downloads
1.9K
0.78%
Maintainers
1
Weekly downloads
 
Created
Source

hydration

Type-accurate serialization of javascript objects

build status

Usage

Basic

out-of-the-box support for Date, RegExp, arrays, buffers

var hydra = require('hydration')
var obj = {
  date: new Date(),
  regex: /^something/,
  array: ['of', 747]
}

// basic

var dehydrated = hydra.dehydrate(obj)
// JSON.stringify + JSON.parse if you like
var hydrated = hydra.hydrate(dehydrated)

// hydrated deepEquals obj

Advanced

you can add support for custom types yourself

var hydra = require('hydration')

function OogaBooga (name) {
  this.name = name
}

var custom = hydra()
custom.addType('oogabooga', {
  test: function (val) {
    return val instanceof OogaBooga
  },
  dehydrate: function (val) {
    return val.name
  },
  hydrate: function (val) {
    return new OogaBooga(val)
  }
})

var obj = {
  //...
  someprop: new OogaBooga('yum')
  //...
}

var dehydrated = hydra.dehydrate(obj)
// JSON.stringify + JSON.parse if you like
var hydrated = hydra.hydrate(dehydrated)

Thanks

Thanks to @mvayngrib for Buffer and custom type support, and documentation.

License

MIT

FAQs

Package last updated on 21 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts