Comparing version 2.3.0 to 2.4.0
@@ -85,2 +85,3 @@ 'use strict'; | ||
'escapeEverything': false, | ||
'minimal': false, | ||
'isScriptContext': false, | ||
@@ -285,2 +286,6 @@ 'quotes': 'single', | ||
const charCode = character.charCodeAt(0); | ||
if (options.minimal && charCode != 0x2028 && charCode != 0x2029) { | ||
result += character; | ||
continue; | ||
} | ||
let hexadecimal = charCode.toString(16); | ||
@@ -308,4 +313,4 @@ if (!lowercaseHex) { | ||
jsesc.version = '2.3.0'; | ||
jsesc.version = '2.4.0'; | ||
module.exports = jsesc; |
{ | ||
"name": "jsesc", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "A JavaScript library for escaping JavaScript strings while generating the shortest possible valid output.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://mths.be/jsesc", |
@@ -37,3 +37,3 @@ # 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) | ||
Instead of a string, the `value` can also be an array, an object, a map, a set, or a buffer. In such cases, `jsesc` will return a stringified version of the value where any characters that are not printable ASCII symbols are escaped in the same way. | ||
Instead of a string, the `value` can also be an array, an object, a map, a set, or a buffer. In such cases, `jsesc` returns a stringified version of the value where any characters that are not printable ASCII symbols are escaped in the same way. | ||
@@ -58,3 +58,3 @@ ```js | ||
The default value for the `quotes` option is `'single'`. This means that any occurrences of `'` in the input string will be escaped as `\'`, so that the output can be used in a string literal wrapped in single quotes. | ||
The default value for the `quotes` option is `'single'`. This means that any occurrences of `'` in the input string are escaped as `\'`, so that the output can be used in a string literal wrapped in single quotes. | ||
@@ -98,3 +98,3 @@ ```js | ||
The default value for the `numbers` option is `'decimal'`. This means that any numeric values will be represented using decimal integer literals. Other valid options are `binary`, `octal`, and `hexadecimal`, which result in binary integer literals, octal integer literals, and hexadecimal integer literals, respectively. | ||
The default value for the `numbers` option is `'decimal'`. This means that any numeric values are represented using decimal integer literals. Other valid options are `binary`, `octal`, and `hexadecimal`, which result in binary integer literals, octal integer literals, and hexadecimal integer literals, respectively. | ||
@@ -125,3 +125,3 @@ ```js | ||
The `wrap` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, the output will be a valid JavaScript string literal wrapped in quotes. The type of quotes can be specified through the `quotes` setting. | ||
The `wrap` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, the output is a valid JavaScript string literal wrapped in quotes. The type of quotes can be specified through the `quotes` setting. | ||
@@ -146,3 +146,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](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`). | ||
The `es6` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, any astral Unicode symbols in the input are 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`). | ||
@@ -169,3 +169,3 @@ ```js | ||
The `escapeEverything` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, all the symbols in the output will be escaped, even printable ASCII symbols. | ||
The `escapeEverything` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, all the symbols in the output are escaped — even printable ASCII symbols. | ||
@@ -180,15 +180,26 @@ ```js | ||
This setting also affects the output for arrays and objects: | ||
This setting also affects the output for string literals within arrays and objects. | ||
#### `minimal` | ||
The `minimal` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, only a limited set of symbols in the output are escaped: | ||
* U+0000 `\0` | ||
* U+0008 `\b` | ||
* U+0009 `\t` | ||
* U+000A `\n` | ||
* U+000C `\f` | ||
* U+000D `\r` | ||
* U+005C `\\` | ||
* U+2028 `\u2028` | ||
* U+2029 `\u2029` | ||
* whatever symbol is being used for wrapping string literals (based on [the `quotes` option](#quotes)) | ||
Note: with this option enabled, jsesc output is no longer guaranteed to be ASCII-safe. | ||
```js | ||
jsesc({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, { | ||
'escapeEverything': true | ||
jsesc('foo\u2029bar\nbaz©qux𝌆flops', { | ||
'minimal': false | ||
}); | ||
// → '{\'\x49\x63\x68\x20\u2665\x20\x42\xFC\x63\x68\x65\x72\':\'\x66\x6F\x6F\x20\uD834\uDF06\x20\x62\x61\x72\'}' | ||
// → "{'\x49\x63\x68\x20\u2665\x20\x42\xFC\x63\x68\x65\x72':'\x66\x6F\x6F\x20\uD834\uDF06\x20\x62\x61\x72'}" | ||
jsesc([ 'Ich ♥ Bücher': 'foo 𝌆 bar' ], { | ||
'escapeEverything': true | ||
}); | ||
// → '[\'\x49\x63\x68\x20\u2665\x20\x42\xFC\x63\x68\x65\x72\',\'\x66\x6F\x6F\x20\uD834\uDF06\x20\x62\x61\x72\']' | ||
// → 'foo\\u2029bar\\nbaz©qux𝌆flops' | ||
``` | ||
@@ -209,3 +220,3 @@ | ||
The `compact` option takes a boolean value (`true` or `false`), and defaults to `true` (enabled). When enabled, the output for arrays and objects will be as compact as possible; it won’t be formatted nicely. | ||
The `compact` option takes a boolean value (`true` or `false`), and defaults to `true` (enabled). When enabled, the output for arrays and objects is as compact as possible; it’s not formatted nicely. | ||
@@ -277,3 +288,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](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. | ||
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) are not 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. | ||
@@ -342,3 +353,3 @@ ```js | ||
After that you will be able to escape strings from the command line: | ||
After that you’re able to escape strings from the command line: | ||
@@ -345,0 +356,0 @@ ```bash |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30956
300
407