Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serialize-javascript

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

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
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37M
increased by2.36%
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

Keywords

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc