Socket
Socket
Sign inDemoInstall

jsesc

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsesc - npm Package Compare versions

Comparing version 0.5.0 to 1.0.0

20

jsesc.js

@@ -1,2 +0,2 @@

/*! http://mths.be/jsesc v0.5.0 by @mathias */
/*! https://mths.be/jsesc v1.0.0 by @mathias */
;(function(root) {

@@ -71,3 +71,3 @@

// http://mathiasbynens.be/notes/javascript-escapes#single
// https://mathiasbynens.be/notes/javascript-escapes#single
var singleEscapes = {

@@ -99,2 +99,3 @@ '"': '\\"',

'compact': true,
'lowercaseHex': false,
'indent': '\t',

@@ -192,5 +193,9 @@ '__indent__': ''

if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
result += '\\u{' + codePoint.toString(16).toUpperCase() + '}';
var hexadecimal = codePoint.toString(16);
if (!options.lowercaseHex) {
hexadecimal = hexadecimal.toUpperCase();
}
result += '\\u{' + hexadecimal + '}';
index++;

@@ -231,3 +236,6 @@ continue;

var charCode = character.charCodeAt(0);
var hexadecimal = charCode.toString(16).toUpperCase();
var hexadecimal = charCode.toString(16);
if (!options.lowercaseHex) {
hexadecimal = hexadecimal.toUpperCase();
}
var longhand = hexadecimal.length > 2 || json;

@@ -245,3 +253,3 @@ var escaped = '\\' + (longhand ? 'u' : 'x') +

jsesc.version = '0.5.0';
jsesc.version = '1.0.0';

@@ -248,0 +256,0 @@ /*--------------------------------------------------------------------------*/

@@ -1,2 +0,2 @@

Copyright Mathias Bynens <http://mathiasbynens.be/>
Copyright Mathias Bynens <https://mathiasbynens.be/>

@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining

{
"name": "jsesc",
"version": "0.5.0",
"version": "1.0.0",
"description": "A JavaScript library for escaping JavaScript strings while generating the shortest possible valid output.",
"homepage": "http://mths.be/jsesc",
"homepage": "https://mths.be/jsesc",
"main": "jsesc.js",

@@ -15,11 +15,6 @@ "bin": "bin/jsesc",

],
"licenses": [
{
"type": "MIT",
"url": "http://mths.be/mit"
}
],
"license": "MIT",
"author": {
"name": "Mathias Bynens",
"url": "http://mathiasbynens.be/"
"url": "https://mathiasbynens.be/"
},

@@ -30,5 +25,3 @@ "repository": {

},
"bugs": {
"url": "https://github.com/mathiasbynens/jsesc/issues"
},
"bugs": "https://github.com/mathiasbynens/jsesc/issues",
"files": [

@@ -40,19 +33,17 @@ "LICENSE-MIT.txt",

],
"directories": {
"test": "tests"
},
"scripts": {
"test": "node tests/tests.js"
"test": "node tests/tests.js",
"build": "grunt template"
},
"devDependencies": {
"coveralls": "^2.10.0",
"coveralls": "^2.11.6",
"grunt": "^0.4.5",
"grunt-shell": "^0.7.0",
"grunt-shell": "^1.1.2",
"grunt-template": "^0.2.3",
"istanbul": "^0.3.0",
"qunit-extras": "^1.2.0",
"istanbul": "^0.4.2",
"qunit-extras": "^1.4.5",
"qunitjs": "~1.11.0",
"regenerate": "^0.6.2",
"requirejs": "^2.1.14"
"regenerate": "^1.2.1",
"requirejs": "^2.1.22"
}
}

@@ -1,6 +0,6 @@

# jsesc [![Build status](https://travis-ci.org/mathiasbynens/jsesc.svg?branch=master)](https://travis-ci.org/mathiasbynens/jsesc) [![Code coverage status](http://img.shields.io/coveralls/mathiasbynens/jsesc/master.svg)](https://coveralls.io/r/mathiasbynens/jsesc) [![Dependency status](https://gemnasium.com/mathiasbynens/jsesc.svg)](https://gemnasium.com/mathiasbynens/jsesc)
# jsesc [![Build status](https://travis-ci.org/mathiasbynens/jsesc.svg?branch=master)](https://travis-ci.org/mathiasbynens/jsesc) [![Code coverage status](https://coveralls.io/repos/mathiasbynens/jsesc/badge.svg)](https://coveralls.io/r/mathiasbynens/jsesc) [![Dependency status](https://gemnasium.com/mathiasbynens/jsesc.svg)](https://gemnasium.com/mathiasbynens/jsesc)
This is a JavaScript library for [escaping JavaScript strings](http://mathiasbynens.be/notes/javascript-escapes) while generating the shortest possible valid ASCII-only output. [Here’s an online demo.](http://mothereff.in/js-escapes)
This is a JavaScript library for [escaping JavaScript strings](https://mathiasbynens.be/notes/javascript-escapes) while generating the shortest possible valid ASCII-only output. [Here’s an online demo.](https://mothereff.in/js-escapes)
This can be used to avoid [mojibake](http://en.wikipedia.org/wiki/Mojibake) and other encoding issues, or even to [avoid errors](https://twitter.com/annevk/status/380000829643571200) when passing JSON-formatted data (which may contain U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, or [lone surrogates](http://esdiscuss.org/topic/code-points-vs-unicode-scalar-values#content-14)) to a JavaScript parser or an UTF-8 encoder, respectively.
This can be used to avoid [mojibake](https://en.wikipedia.org/wiki/Mojibake) and other encoding issues, or even to [avoid errors](https://twitter.com/annevk/status/380000829643571200) when passing JSON-formatted data (which may contain U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, or [lone surrogates](https://esdiscuss.org/topic/code-points-vs-unicode-scalar-values#content-14)) to a JavaScript parser or an UTF-8 encoder, respectively.

@@ -23,3 +23,3 @@ Feel free to fork if you see possible improvements!

Via [npm](http://npmjs.org/):
Via [npm](https://www.npmjs.com/):

@@ -36,3 +36,3 @@ ```bash

In [Node.js](http://nodejs.org/) and [RingoJS](http://ringojs.org/):
In [Node.js](https://nodejs.org/) and [RingoJS](http://ringojs.org/):

@@ -75,3 +75,3 @@ ```js

This function takes a value and returns an escaped version of the value where any characters that are not printable ASCII symbols are escaped using the shortest possible (but valid) [escape sequences for use in JavaScript strings](http://mathiasbynens.be/notes/javascript-escapes). The first supported value type is strings:
This function takes a value and returns an escaped version of the value where any characters that are not printable ASCII symbols are escaped using the shortest possible (but valid) [escape sequences for use in JavaScript strings](https://mathiasbynens.be/notes/javascript-escapes). The first supported value type is strings:

@@ -165,3 +165,3 @@ ```js

The `es6` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, any astral Unicode symbols in the input will be escaped using [ECMAScript 6 Unicode code point escape sequences](http://mathiasbynens.be/notes/javascript-escapes#unicode-code-point) instead of using separate escape sequences for each surrogate half. If backwards compatibility with ES5 environments is a concern, don’t enable this setting. If the `json` setting is enabled, the value for the `es6` setting is ignored (as if it was `false`).
The `es6` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, any astral Unicode symbols in the input will be escaped using [ECMAScript 6 Unicode code point escape sequences](https://mathiasbynens.be/notes/javascript-escapes#unicode-code-point) instead of using separate escape sequences for each surrogate half. If backwards compatibility with ES5 environments is a concern, don’t enable this setting. If the `json` setting is enabled, the value for the `es6` setting is ignored (as if it was `false`).

@@ -264,3 +264,3 @@ ```js

The `json` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, the output is valid JSON. [Hexadecimal character escape sequences](http://mathiasbynens.be/notes/javascript-escapes#hexadecimal) and [the `\v` or `\0` escape sequences](http://mathiasbynens.be/notes/javascript-escapes#single) will not be used. Setting `json: true` implies `quotes: 'double', wrap: true, es6: false`, although these values can still be overridden if needed — but in such cases, the output won’t be valid JSON anymore.
The `json` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, the output is valid JSON. [Hexadecimal character escape sequences](https://mathiasbynens.be/notes/javascript-escapes#hexadecimal) and [the `\v` or `\0` escape sequences](https://mathiasbynens.be/notes/javascript-escapes#single) will not be used. Setting `json: true` implies `quotes: 'double', wrap: true, es6: false`, although these values can still be overridden if needed — but in such cases, the output won’t be valid JSON anymore.

@@ -298,2 +298,14 @@ ```js

#### `lowercaseHex`
The `lowercaseHex` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, the alphabetical hexadecimal digits in escape sequences in the output are in lowercase.
```js
jsesc('Ich ♥ Bücher', {
'lowercaseHex': true,
});
// → 'Ich \\u2665 B\\xfccher'
// ^^
```
### `jsesc.version`

@@ -361,5 +373,5 @@

This library has been tested in at least Chrome 27-29, Firefox 3-22, Safari 4-6, Opera 10-12, IE 6-10, Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, and Rhino 1.7RC4.
This library has been tested in at least Chrome 27, Firefox 3, Safari 4, Opera 10, IE 6, Node.js v0.10.0, io.js v1.0.0, Narwhal 0.3.2, RingoJS 0.8-0.11, PhantomJS 1.9.0, and Rhino 1.7RC4.
**Note:** Using the `json` option on objects or arrays that contain non-string values relies on `JSON.parse()`. For legacy environments like IE ≤ 7, use [a `JSON` polyfill](http://bestiejs.github.io/json3/).
**Note:** Using the `json` option on objects or arrays that contain non-string values relies on `JSON.parse()`. For legacy environments like IE ≤ 7, use [a `JSON` polyfill](https://bestiejs.github.io/json3/).

@@ -378,6 +390,6 @@ ## Unit tests & code coverage

|---|
| [Mathias Bynens](http://mathiasbynens.be/) |
| [Mathias Bynens](https://mathiasbynens.be/) |
## License
This library is available under the [MIT](http://mths.be/mit) license.
This library is available under the [MIT](https://mths.be/mit) license.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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