var implode = require'implode'var serialized = implodeobj // serializevar recovered = imploderecoverserialized // deserialize
To put the serialized object into a
<script /> tag, use
Breaking change in
>=2.0.0: Prior to
2.0.0 it was possible to use
JSON.parse() to convert the serialized object to a string presentation and vice versa. However, to get rid of
implode(obj).toString(), which is similar to JSON, except that
functions are not wrapped into double quotes. This allows to but the string presentation of the serialized object into
<script/> tags directly. Using these
JSON methods is still possible, but removes
functions from the serialized object.
To use constructors, e.g.:
varthisid = idthisname = name// when being recovered, this constructor is called without arguments,// therefore the bootstrap logic is moved to a seperate methodthisinitthisexcerpt = thisid + '-' + thisname
... they have to be registered:
imploderegister'User' // unique identifierUser // the constructor'id' 'name' // a whitelist of properties to be serialized
The following hooks are available:
// this hook allows to postprocess the object when it got recoveredobjinitreturn obj// this hook allows to preprocess the object for the implode processreturn this
Copyright (c) 2013 Markus Ast
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.