🚀 Socket Launch Week 🚀 Day 3: Socket Acquires Coana.Learn More

serialize-javascript

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serialize-javascript

Serialize JavaScript to a superset of JSON that includes regular expressions and functions.

6.0.2
latest
Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created

What is serialize-javascript?

The serialize-javascript npm package is used to serialize JavaScript to a superset of JSON that includes regular expressions, dates, and functions. It is typically used to safely pass data from a server to a client-side script.

What are serialize-javascript's main functionalities?

Serialize Data

This feature allows the serialization of JavaScript objects, including those containing Dates, RegExps, and functions, into a string format that can be safely transported over a network and then re-evaluated or parsed on the client side.

const serialize = require('serialize-javascript');
const user = { name: 'Alice', email: 'alice@example.com', lastLogin: new Date() };
const serializedUser = serialize(user);

Serialize with Options

This feature allows customization of the serialization process with options such as indentation for pretty-printing the serialized string.

const serialize = require('serialize-javascript');
const user = { name: 'Alice', email: 'alice@example.com', lastLogin: new Date() };
const serializedUser = serialize(user, { space: 2 });

Serialize Including Functions

This feature allows the serialization of functions within objects by setting the 'isJSON' option to false, which enables the inclusion of non-JSON-safe features in the serialized string.

const serialize = require('serialize-javascript');
const user = { greet() { return 'Hello!'; } };
const serializedUser = serialize(user, { isJSON: false });

Other packages similar to serialize-javascript

FAQs

Package last updated on 09 Jan 2024

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