[Pkg-javascript-commits] [node-jsesc] 01/03: Imported Upstream version 1.0.0

Julien Puydt julien.puydt at laposte.net
Fri May 13 12:53:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-jsesc.

commit f3d905e44ccc1b9ff42eb29e79b52e0537970cb6
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Fri May 13 14:42:30 2016 +0200

    Imported Upstream version 1.0.0
---
 .travis.yml     |  11 +++---
 Gruntfile.js    |   5 +--
 LICENSE-MIT.txt |   2 +-
 README.md       |  36 ++++++++++++-------
 bin/jsesc       |  11 ++++--
 bower.json      |   2 +-
 component.json  |   2 +-
 jsesc.js        |  20 +++++++----
 man/jsesc.1     |  10 ++++--
 package.json    |  35 +++++++------------
 src/jsesc.js    |  18 +++++++---
 tests/tests.js  | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 12 files changed, 192 insertions(+), 66 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 37eb3b4..7b45eb0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,18 @@
 language: node_js
 node_js:
   - "0.10"
+  - "0.12"
+  - "4"
+  - "5"
 before_script:
   - "npm install -g grunt-cli"
   # Narwhal uses a hardcoded path to openjdk v6, so use that version
   - "sudo apt-get update -qq"
   - "sudo apt-get install -qq openjdk-6-jre"
-  - "PACKAGE=rhino1_7R3; wget http://ftp.mozilla.org/pub/mozilla.org/js/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
-  - "PACKAGE=rhino1_7R3; echo -e '#!/bin/sh\\njava -jar /opt/'$PACKAGE'/js.jar $@' | sudo tee /usr/local/bin/rhino && sudo chmod +x /usr/local/bin/rhino"
-  - "PACKAGE=ringojs-0.9; wget http://ringojs.org/downloads/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
-  - "PACKAGE=ringojs-0.9; sudo ln -s /opt/$PACKAGE/bin/ringo /usr/local/bin/ringo && sudo chmod +x /usr/local/bin/ringo"
+  - "PACKAGE=rhino1_7R5; wget https://github.com/mozilla/rhino/releases/download/Rhino1_7R5_RELEASE/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
+  - "PACKAGE=rhino1_7R5; echo -e '#!/bin/sh\\njava -jar /opt/'$PACKAGE'/js.jar $@' | sudo tee /usr/local/bin/rhino && sudo chmod +x /usr/local/bin/rhino"
+  - "PACKAGE=ringojs-0.11; wget https://github.com/ringo/ringojs/releases/download/v0.11.0/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
+  - "PACKAGE=ringojs-0.11; sudo ln -s /opt/$PACKAGE/bin/ringo /usr/local/bin/ringo && sudo chmod +x /usr/local/bin/ringo"
   - "PACKAGE=v0.3.2; wget https://github.com/280north/narwhal/archive/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
   - "PACKAGE=narwhal-0.3.2; sudo ln -s /opt/$PACKAGE/bin/narwhal /usr/local/bin/narwhal && sudo chmod +x /usr/local/bin/narwhal"
   # If the enviroment stores rt.jar in a different directory, find it and symlink the directory
diff --git a/Gruntfile.js b/Gruntfile.js
index d3c8079..d9a8cb0 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -11,7 +11,7 @@ module.exports = function(grunt) {
 				'command': 'istanbul cover --report "html" --verbose --dir "coverage" "tests/tests.js"'
 			},
 			'cover-coveralls': {
-				'command': 'istanbul cover --verbose --dir "coverage" "tests/tests.js" && cat coverage/lcov.info | coveralls; rm -rf coverage/lcov*'
+				'command': 'istanbul cover --verbose --dir "coverage" "tests/tests.js" && coveralls < coverage/lcov.info; rm -rf coverage/lcov*'
 			},
 			'test-narwhal': {
 				'command': 'echo "Testing in Narwhal..."; export NARWHAL_OPTIMIZATION=-1; narwhal "tests/tests.js"'
@@ -19,9 +19,6 @@ module.exports = function(grunt) {
 			'test-phantomjs': {
 				'command': 'echo "Testing in PhantomJS..."; phantomjs "tests/tests.js"'
 			},
-			// Rhino 1.7R4 has a bug that makes it impossible to test in.
-			// https://bugzilla.mozilla.org/show_bug.cgi?id=775566
-			// To test, use Rhino 1.7R3, or wait (heh) for the 1.7R5 release.
 			'test-rhino': {
 				'command': 'echo "Testing in Rhino..."; rhino -opt -1 "tests.js"',
 				'options': {
diff --git a/LICENSE-MIT.txt b/LICENSE-MIT.txt
index 97067e5..a41e0a7 100644
--- a/LICENSE-MIT.txt
+++ b/LICENSE-MIT.txt
@@ -1,4 +1,4 @@
-Copyright Mathias Bynens <http://mathiasbynens.be/>
+Copyright Mathias Bynens <https://mathiasbynens.be/>
 
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
diff --git a/README.md b/README.md
index 7a083c7..eb8be1a 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
-# 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.
 
 Feel free to fork if you see possible improvements!
 
@@ -20,7 +20,7 @@ Via [Component](https://github.com/component/component):
 component install mathiasbynens/jsesc
 ```
 
-Via [npm](http://npmjs.org/):
+Via [npm](https://www.npmjs.com/):
 
 ```bash
 npm install jsesc
@@ -32,7 +32,7 @@ In a browser:
 <script src="jsesc.js"></script>
 ```
 
-In [Node.js](http://nodejs.org/) and [RingoJS](http://ringojs.org/):
+In [Node.js](https://nodejs.org/) and [RingoJS](http://ringojs.org/):
 
 ```js
 var jsesc = require('jsesc');
@@ -70,7 +70,7 @@ require(
 
 ### `jsesc(value, options)`
 
-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:
 
 ```js
 jsesc('Ich ♥ Bücher');
@@ -159,7 +159,7 @@ jsesc('Lorem ipsum "dolor" sit \'amet\' etc.', {
 
 #### `es6`
 
-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 valu [...]
+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 val [...]
 
 ```js
 // By default, the `es6` option is disabled:
@@ -257,7 +257,7 @@ This setting has no effect on the output for strings.
 
 #### `json`
 
-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 [...]
+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  [...]
 
 ```js
 jsesc('foo\x00bar\xFF\uFFFDbaz', {
@@ -290,6 +290,18 @@ jsesc([ undefined, -Infinity ], {
 
 **Note:** Using this option on objects or arrays that contain non-string values relies on `JSON.stringify()`. For legacy environments like IE ≤ 7, use [a `JSON` polyfill](http://bestiejs.github.io/json3/).
 
+#### `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`
 
 A string representing the semantic version number.
@@ -352,9 +364,9 @@ See `jsesc --help` for the full list of options.
 
 ## Support
 
-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/).
 
 ## Unit tests & code coverage
 
@@ -368,8 +380,8 @@ To generate the code coverage report, use `grunt cover`.
 
 | [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
 |---|
-| [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.
diff --git a/bin/jsesc b/bin/jsesc
index 5900dd4..d7bffd6 100755
--- a/bin/jsesc
+++ b/bin/jsesc
@@ -16,7 +16,7 @@
 
 		if (/^(?:-h|--help|undefined)$/.test(option)) {
 			log(
-				'jsesc v%s - http://mths.be/jsesc',
+				'jsesc v%s - https://mths.be/jsesc',
 				stringEscape.version
 			);
 			log([
@@ -27,6 +27,7 @@
 				'\tjsesc [-w | --wrap] [string]',
 				'\tjsesc [-e | --escape-everything] [string]',
 				'\tjsesc [-6 | --es6] [string]',
+				'\tjsesc [-l | --lowercase-hex] [string]',
 				'\tjsesc [-j | --json] [string]',
 				'\tjsesc [-o | --object] [stringified_object]', // `JSON.parse()` the argument
 				'\tjsesc [-p | --pretty] [string]', // `compact: false`
@@ -61,12 +62,16 @@
 				options.wrap = true;
 				return;
 			}
+			if (/^(?:-e|--escape-everything)$/.test(string)) {
+				options.escapeEverything = true;
+				return;
+			}
 			if (/^(?:-6|--es6)$/.test(string)) {
 				options.es6 = true;
 				return;
 			}
-			if (/^(?:-e|--escape-everything)$/.test(string)) {
-				options.escapeEverything = true;
+			if (/^(?:-l|--lowercase-hex)$/.test(string)) {
+				options.lowercaseHex = true;
 				return;
 			}
 			if (/^(?:-j|--json)$/.test(string)) {
diff --git a/bower.json b/bower.json
index 45e6233..16c88f6 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
 {
 	"name": "jsesc",
-	"version": "0.5.0",
+	"version": "1.0.0",
 	"main": "jsesc.js",
 	"ignore": [
 		"bin",
diff --git a/component.json b/component.json
index 3d26a68..9367afa 100644
--- a/component.json
+++ b/component.json
@@ -1,6 +1,6 @@
 {
 	"name": "jsesc",
-	"version": "0.5.0",
+	"version": "1.0.0",
 	"description": "A JavaScript library for escaping JavaScript strings while generating the shortest possible ASCII-only output.",
 	"repo": "mathiasbynens/jsesc",
 	"license": "MIT",
diff --git a/jsesc.js b/jsesc.js
index 03bbd68..da289b0 100644
--- a/jsesc.js
+++ b/jsesc.js
@@ -1,4 +1,4 @@
-/*! http://mths.be/jsesc v0.5.0 by @mathias */
+/*! https://mths.be/jsesc v1.0.0 by @mathias */
 ;(function(root) {
 
 	// Detect free variables `exports`
@@ -68,7 +68,7 @@
 
 	/*--------------------------------------------------------------------------*/
 
-	// http://mathiasbynens.be/notes/javascript-escapes#single
+	// https://mathiasbynens.be/notes/javascript-escapes#single
 	var singleEscapes = {
 		'"': '\\"',
 		'\'': '\\\'',
@@ -95,6 +95,7 @@
 			'es6': false,
 			'json': false,
 			'compact': true,
+			'lowercaseHex': false,
 			'indent': '\t',
 			'__indent__': ''
 		};
@@ -187,9 +188,13 @@
 				) {
 					second = string.charCodeAt(index + 1);
 					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++;
 						continue;
 					}
@@ -225,7 +230,10 @@
 				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;
 			var escaped = '\\' + (longhand ? 'u' : 'x') +
 				('0000' + hexadecimal).slice(longhand ? -4 : -2);
@@ -238,7 +246,7 @@
 		return result;
 	};
 
-	jsesc.version = '0.5.0';
+	jsesc.version = '1.0.0';
 
 	/*--------------------------------------------------------------------------*/
 
diff --git a/man/jsesc.1 b/man/jsesc.1
index 5257768..70da148 100644
--- a/man/jsesc.1
+++ b/man/jsesc.1
@@ -11,9 +11,11 @@
 .br
 .Op Fl w | -wrap Ar string
 .br
+.Op Fl e | -escape-everything Ar string
+.br
 .Op Fl 6 | -es6 Ar string
 .br
-.Op Fl e | -escape-everything Ar string
+.Op Fl l | -lowercase-hex Ar string
 .br
 .Op Fl j | -json Ar string
 .br
@@ -53,6 +55,8 @@ settings.
 Treat the input as a JavaScript object rather than a string. Accepted values are flat arrays containing only string values, and flat objects containing only string values.
 .It Sy "-p, --pretty"
 Pretty-print the output for objects, using whitespace to make it more readable. Setting this flag enables the
+.It Sy "-l, --lowercase-hex"
+Use lowercase for alphabetical hexadecimal digits in escape sequences.
 .Ar -o | --object
 setting.
 .It Sy "-v, --version"
@@ -85,6 +89,6 @@ Print an escaped version of the string that gets piped in.
 .Sh BUGS
 jsesc's bug tracker is located at <https://github.com/mathiasbynens/jsesc/issues>.
 .Sh AUTHOR
-Mathias Bynens <http://mathiasbynens.be/>
+Mathias Bynens <https://mathiasbynens.be/>
 .Sh WWW
-<http://mths.be/jsesc>
+<https://mths.be/jsesc>
diff --git a/package.json b/package.json
index 1216eef..9469fb1 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
 {
 	"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",
 	"bin": "bin/jsesc",
 	"man": "man/jsesc.1",
@@ -12,44 +12,35 @@
 		"javascript",
 		"tool"
 	],
-	"licenses": [
-		{
-			"type": "MIT",
-			"url": "http://mths.be/mit"
-		}
-	],
+	"license": "MIT",
 	"author": {
 		"name": "Mathias Bynens",
-		"url": "http://mathiasbynens.be/"
+		"url": "https://mathiasbynens.be/"
 	},
 	"repository": {
 		"type": "git",
 		"url": "https://github.com/mathiasbynens/jsesc.git"
 	},
-	"bugs": {
-		"url": "https://github.com/mathiasbynens/jsesc/issues"
-	},
+	"bugs": "https://github.com/mathiasbynens/jsesc/issues",
 	"files": [
 		"LICENSE-MIT.txt",
 		"jsesc.js",
 		"bin/",
 		"man/"
 	],
-	"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"
 	}
 }
diff --git a/src/jsesc.js b/src/jsesc.js
index 9b5c4a0..f8bed02 100644
--- a/src/jsesc.js
+++ b/src/jsesc.js
@@ -1,4 +1,4 @@
-/*! http://mths.be/jsesc v<%= version %> by @mathias */
+/*! https://mths.be/jsesc v<%= version %> by @mathias */
 ;(function(root) {
 
 	// Detect free variables `exports`
@@ -68,7 +68,7 @@
 
 	/*--------------------------------------------------------------------------*/
 
-	// http://mathiasbynens.be/notes/javascript-escapes#single
+	// https://mathiasbynens.be/notes/javascript-escapes#single
 	var singleEscapes = {
 		'"': '\\"',
 		'\'': '\\\'',
@@ -95,6 +95,7 @@
 			'es6': false,
 			'json': false,
 			'compact': true,
+			'lowercaseHex': false,
 			'indent': '\t',
 			'__indent__': ''
 		};
@@ -187,9 +188,13 @@
 				) {
 					second = string.charCodeAt(index + 1);
 					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++;
 						continue;
 					}
@@ -225,7 +230,10 @@
 				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;
 			var escaped = '\\' + (longhand ? 'u' : 'x') +
 				('0000' + hexadecimal).slice(longhand ? -4 : -2);
diff --git a/tests/tests.js b/tests/tests.js
index 774556a..092bd7d 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -35,7 +35,7 @@
 
 	// Quick and dirty test to see if we’re in PhantomJS or Node
 	var isNode = typeof process != 'undefined' && process.argv &&
-		process.argv[0] == 'node';
+		process.argv[0].slice(-4) == 'node';
 	var runExtendedTests = root.phantom || isNode;
 
 	// explicitly call `QUnit.module()` instead of `module()`
@@ -287,6 +287,68 @@
 			'{"hello":"world","\\uD83D\\uDCA9":"foo","pile":"\\uD83D\\uDCA9"}',
 			'`toJSON` methods are not called when `json: false`'
 		);
+		equal(
+			jsesc('\u2192\xE9', {
+				'lowercaseHex': true
+			}),
+			'\\u2192\\xe9',
+			'Alphabetical hexadecimal digits are lowercase when `lowercaseHex: true`'
+		);
+		equal(
+			jsesc('\u2192\xE9', {
+				'lowercaseHex': false
+			}),
+			'\\u2192\\xE9',
+			'Alphabetical hexadecimal digits are uppercase when `lowercaseHex: false`'
+		);
+		equal(
+			jsesc('\u2192\xE9', {
+				'lowercaseHex': true,
+				'json': true
+			}),
+			'"\\u2192\\u00e9"',
+			'Alphabetical hexadecimal digits are lowercase when `lowercaseHex: false` and `json: true`'
+		);
+		equal(
+			jsesc('\u2192\xe9', {
+				'lowercaseHex': false,
+				'json': true
+			}),
+			'"\\u2192\\u00E9"',
+			'Alphabetical hexadecimal digits are uppercase when `lowercaseHex: false` and `json: true`'
+		);
+		equal(
+			jsesc('\xE7\xE7a\xE7\xE7', {
+				'lowercaseHex': true,
+				'escapeEverything': true
+			}),
+			'\\xe7\\xe7\\x61\\xe7\\xe7',
+			'Alphabetical hexadecimal digits are lowercase when `lowercaseHex: true` and `escapeEverything: true`'
+		);
+		equal(
+			jsesc('\xE7\xE7a\xE7\xE7', {
+				'lowercaseHex': false,
+				'escapeEverything': true
+			}),
+			'\\xE7\\xE7\\x61\\xE7\\xE7',
+			'Alphabetical hexadecimal digits are uppercase when `lowercaseHex: false` and `escapeEverything: true`'
+		);
+		equal(
+			jsesc('\u2192\xE9\uD83D\uDCA9', {
+				'lowercaseHex': true,
+				'es6': true
+			}),
+			'\\u2192\\xe9\\u{1f4a9}',
+			'Alphabetical hexadecimal digits are lowercase when `lowercaseHex: true` and `es6: true`'
+		);
+		equal(
+			jsesc('\u2192\xE9\uD83D\uDCA9', {
+				'lowercaseHex': false,
+				'es6': true
+			}),
+			'\\u2192\\xE9\\u{1F4A9}',
+			'Alphabetical hexadecimal digits are uppercase when `lowercaseHex: false` and `es6: true`'
+		);
 	});
 
 	if (runExtendedTests) {
@@ -299,7 +361,7 @@
 				return array;
 			};
 
-			// taken from http://mths.be/punycode
+			// taken from https://mths.be/punycode
 			var stringFromCharCode = String.fromCharCode;
 			var ucs2encode = function(value) {
 				var output = '';
@@ -316,8 +378,8 @@
 			var codePoint;
 			var symbol = '';
 			// Generate strings based on code points. Trickier than it seems:
-			// http://mathiasbynens.be/notes/javascript-encoding
-			for (codePoint = 0x000000; codePoint <= 0x10FFFF; codePoint++) {
+			// https://mathiasbynens.be/notes/javascript-encoding
+			for (codePoint = 0x000000; codePoint <= 0x10FFFF; codePoint += 0xF) {
 				symbol = ucs2encode(codePoint);
 				// ok(
 				// 	eval('\'' + jsesc(symbol) + '\'') == symbol,
@@ -646,6 +708,42 @@
 					}
 				},
 				{
+					'description': '-l option',
+					'command': './bin/jsesc -l a\uD834\uDF06b\uD83D\uDCA9c',
+					'expected': {
+						'stdout': 'a\\ud834\\udf06b\\ud83d\\udca9c\n',
+						'stderr': '',
+						'exitStatus': 0
+					}
+				},
+				{
+					'description': '-l option, piping content',
+					'command': 'echo a\uD834\uDF06b\uD83D\uDCA9c | ./bin/jsesc -l',
+					'expected': {
+						'stdout': 'a\\ud834\\udf06b\\ud83d\\udca9c\n',
+						'stderr': '',
+						'exitStatus': 0
+					}
+				},
+				{
+					'description': '--lowercase-hex option',
+					'command': './bin/jsesc --lowercase-hex a\uD834\uDF06b\uD83D\uDCA9c',
+					'expected': {
+						'stdout': 'a\\ud834\\udf06b\\ud83d\\udca9c\n',
+						'stderr': '',
+						'exitStatus': 0
+					}
+				},
+				{
+					'description': '--lowercase-hex option, piping content',
+					'command': 'echo a\uD834\uDF06b\uD83D\uDCA9c | ./bin/jsesc --lowercase-hex',
+					'expected': {
+						'stdout': 'a\\ud834\\udf06b\\ud83d\\udca9c\n',
+						'stderr': '',
+						'exitStatus': 0
+					}
+				},
+				{
 					'description': '-j option',
 					'command': './bin/jsesc -j f\xF6o\\ \u2665\\ \\\'\\"\\\'\\"\\ b\xE5r\\ \uD834\uDF06\\ baz',
 					'expected': {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jsesc.git



More information about the Pkg-javascript-commits mailing list