serialize-javascript
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Serialize-javascript is a powerful npm package that converts JavaScript to a superset of JSON that includes regular expressions, functions, dates, sets, and maps. Its initial creation was as an internal module to express-state. However, due to its wide range of applicability, it now exists as serialize-javascript
, a standalone package on npm. This tool allows seamless serialization of JavaScript on both the server and client sides and can be especially efficient for web applications using client-side URL routing.
To use serialize-javascript, firstly, install the package using npm by running npm install serialize-javascript
in your terminal. Once installed, import it in your JavaScript file with var serialize = require('serialize-javascript');
. Then you can simply call serialize()
function on your JavaScript object.
Example usage:
var serialize = require('serialize-javascript');
serialize({
str : 'string',
num : 0,
obj : {foo: 'foo'},
arr : [1, 2, 3],
bool : true,
nil : null,
undef: undefined,
inf : Infinity,
date : new Date("Thu, 28 Apr 2016 22:02:17 GMT"),
map : new Map([['hello', 'world']]),
set : new Set([123, 456]),
fn : function echo(arg) { return arg; },
re : /([^\s]+)/g,
big : BigInt(10),
});
The documentation for serialize-javascript can be found in the README file on the GitHub repository at git+https://github.com/yahoo/serialize-javascript.git. The README file is highly informative and contains a comprehensive guide on installation, usage, available options, and deserialization process.