Type-accurate serialization of javascript objects
JavaScript HTML Makefile
Latest commit b60d971 May 21, 2016 @carlos8f 1.0.0
Failed to load latest commit information.
test reorg, custom type support May 20, 2016
.gitignore Initial commit Jun 10, 2012
.travis.yml add travis file Aug 19, 2012
Makefile use component.js Jun 22, 2013
Readme.md update thanks May 21, 2016
component.json bump component version to 0.5.0 Jun 22, 2013
hydration.js use component.js Jun 22, 2013
index.js reorg, custom type support May 20, 2016
package.json 1.0.0 May 21, 2016

Readme.md

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