Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 17, 2024 via pnpm

jsesc 3.0.2

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.
Package summary
Share
0
issues
1
license
1
MIT
Package created
27 Jul 2013
Version published
28 Oct 2020
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
jsesc@3.0.2
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
ⓘ This is a list of jsesc 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does jsesc do?

jsesc is a highly useful JavaScript library that takes any kind of data and returns a stringified representation of it. Unlike JSON.stringify(), it can generate JavaScript-based outputs and provide ASCII-safe outputs by default, thanks to its usage of escape sequences when necessary. jsesc is able to generate the shortest possible valid printable-ASCII-only output and can be used as an alternative to JSON.stringify() to avoid encoding issues or errors when transferring JSON-formatted data. Particularly, jsesc can ensure smooth handling of specific Unicode characters that may cause issues with JSON, such as U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, or lone surrogates. Above all, it is highly customizable offering many options to customize the output representation.

How do you use jsesc?

To use jsesc in your Node.js program, you first need to install it via npm using the command npm install jsesc. Once it is installed, you can require it in your program using const jsesc = require('jsesc');. Sending data through the jsesc() function will return a stringified version where all non-printable ASCII symbols are escaped.

Here are some examples:

const jsesc = require('jsesc');

jsesc('Ich ♥ Bücher');
// Output: 'Ich \\u2665 B\\xFCcher'

jsesc('foo 𝌆 bar');
// Output: 'foo \\uD834\\uDF06 bar'

// For arrays, objects, map, set, or buffer, jsesc acts similarly:
// For an array
jsesc([
  'Ich ♥ Bücher', 'foo 𝌆 bar'
]);
// Output: '[\'Ich \\u2665 B\\xFCcher\',\'foo \\uD834\\uDF06 bar\']'

// For an object
jsesc({
  'Ich ♥ Bücher': 'foo 𝌆 bar'
});
// Output: '{\'Ich \\u2665 B\\xFCcher\':\'foo \\uD834\\uDF06 bar\'}'

Where are the jsesc docs?

The complete documentation and usage guidelines for jsesc are included in the readme on the jsesc GitHub page. This contains a detailed explanation of each option and its usage along with examples. Series of executable examples are also included in the readme for a better understanding of the library's functionalities.