{"bin":{"jsesc":"bin/jsesc"},"man":["man/jsesc.1"],"bugs":{"url":"https://github.com/mathiasbynens/javascript-string-escape/issues"},"dist":{"shasum":"124c99ba65474063248a754436b70cfd329e6b23","tarball":"https://registry.npmjs.org/string-escape/-/string-escape-0.2.3.tgz","integrity":"sha512-JsEXGFtoYpAobY17RMRNnSTIDKDWxI2AheRX/3zo8uI9hcBqhcrpNKg4YSQshd1oh8JnZNc/CLAQuws6TBbatg==","signatures":[{"sig":"MEYCIQCM+W2Ty6eArX64h/dYgwpHkPweOGvRWYpwzx1M+Z8pBQIhAI4AZ5zV13zy7GhrpAzCXRR4XObVY90L9V223yujuPS4","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"string-escape.js","name":"string-escape","_from":".","files":["LICENSE-MIT.txt","string-escape.js","bin/","man/"],"author":{"url":"http://mathiasbynens.be/","name":"Mathias Bynens"},"readme":"# JavaScript string escape [![Build status](https://travis-ci.org/mathiasbynens/javascript-string-escape.png?branch=master)](https://travis-ci.org/mathiasbynens/javascript-string-escape) [![Dependency status](https://gemnasium.com/mathiasbynens/javascript-string-escape.png)](https://gemnasium.com/mathiasbynens/javascript-string-escape)\n\nThis is a JavaScript library for escaping JavaScript strings while generating the shortest possible valid output. [Here’s an online demo.](http://mothereff.in/js-escapes)\n\nFeel free to fork if you see possible improvements!\n\n## Installation\n\nVia [Bower](http://bower.io/):\n\n```bash\nbower install string-escape\n```\n\nVia [Component](https://github.com/component/component):\n\n```bash\ncomponent install mathiasbynens/javascript-string-escape\n```\n\nVia [npm](http://npmjs.org/):\n\n```bash\nnpm install string-escape\n```\n\nIn a browser:\n\n```html\n<script src=\"string-escape.js\"></script>\n```\n\nIn [Node.js](http://nodejs.org/) and [RingoJS](http://ringojs.org/):\n\n```js\nvar stringEscape = require('string-escape');\n```\n\nIn [Narwhal](http://narwhaljs.org/):\n\n```js\nvar stringEscape = require('string-escape').stringEscape;\n```\n\nIn [Rhino](http://www.mozilla.org/rhino/):\n\n```js\nload('string-escape.js');\n```\n\nUsing an AMD loader like [RequireJS](http://requirejs.org/):\n\n```js\nrequire(\n  {\n    'paths': {\n      'string-escape': 'path/to/string-escape'\n    }\n  },\n  ['string-escape'],\n  function(stringEscape) {\n    console.log(stringEscape);\n  }\n);\n```\n\n## API\n\n### `stringEscape(value, options)`\n\nThis 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:\n\n```js\nstringEscape('Ich ♥ Bücher');\n// → 'Ich \\\\u2665 B\\\\xFCcher'\n\nstringEscape('foo 𝌆 bar');\n// → 'foo \\\\uD834\\\\uDF06 bar'\n```\n\nInstead of a string, the `value` can also be a flat object containing only string values. In that case, `stringEscape` will return a stringified version of the object where any characters that are not printable ASCII symbols are escaped in the same way.\n\n```js\nstringEscape({\n  'Ich ♥ Bücher': 'foo 𝌆 bar'\n});\n// → '{\\'Ich \\\\u2665 B\\\\xFCcher\\':\\'foo \\\\uD834\\\\uDF06 bar\\'}'\n```\n\nInstead of a string or an object, the `value` can also be a flat array containing only string values. In that case, `stringEscape` will return a stringified version of the array where any characters that are not printable ASCII symbols are escaped in the same way.\n\n```js\nstringEscape([\n  'Ich ♥ Bücher': 'foo 𝌆 bar'\n]);\n// → '[\\'Ich \\\\u2665 B\\\\xFCcher\\',\\'foo \\\\uD834\\\\uDF06 bar\\']'\n```\n\nThe optional `options` argument accepts an object with the following options:\n\n#### `quotes`\n\nThe default value for the `quotes` option is `'single'`. This means that any occurences of `'` in the input string will be escaped as `\\'`, so that the output can be used in a string literal wrapped in single quotes.\n\n```js\nstringEscape('Lorem ipsum \"dolor\" sit \\'amet\\' etc.');\n// → 'Lorem ipsum \"dolor\" sit \\\\\\'amet\\\\\\' etc.'\n\nstringEscape('Lorem ipsum \"dolor\" sit \\'amet\\' etc.', {\n  'quotes': 'single'\n});\n// → 'Lorem ipsum \"dolor\" sit \\\\\\'amet\\\\\\' etc.'\n// → \"Lorem ipsum \\\"dolor\\\" sit \\\\'amet\\\\' etc.\"\n```\n\nIf you want to use the output as part of a string literal wrapped in double quotes, set the `quotes` option to `'double'`.\n\n```js\nstringEscape('Lorem ipsum \"dolor\" sit \\'amet\\' etc.', {\n  'quotes': 'double'\n});\n// → 'Lorem ipsum \\\\\"dolor\\\\\" sit \\'amet\\' etc.'\n// → \"Lorem ipsum \\\\\\\"dolor\\\\\\\" sit 'amet' etc.\"\n```\n\nThis setting also affects the output for arrays and objects:\n\n```js\nstringEscape({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, {\n  'quotes': 'double'\n});\n// → '{\"Ich \\\\u2665 B\\\\xFCcher\":\"foo \\\\uD834\\\\uDF06 bar\"}'\n\nstringEscape([ 'Ich ♥ Bücher', 'foo 𝌆 bar' ], {\n  'quotes': 'double'\n});\n// → '[\"Ich \\\\u2665 B\\\\xFCcher\",\"foo \\\\uD834\\\\uDF06 bar\"]'\n```\n\n#### `wrap`\n\nThe `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.\n\n```js\nstringEscape('Lorem ipsum \"dolor\" sit \\'amet\\' etc.', {\n  'quotes': 'single',\n  'wrap': true\n});\n// → '\\'Lorem ipsum \"dolor\" sit \\\\\\'amet\\\\\\' etc.\\''\n// → \"\\'Lorem ipsum \\\"dolor\\\" sit \\\\\\'amet\\\\\\' etc.\\'\"\n\nstringEscape('Lorem ipsum \"dolor\" sit \\'amet\\' etc.', {\n  'quotes': 'double',\n  'wrap': true\n});\n// → '\"Lorem ipsum \\\\\"dolor\\\\\" sit \\'amet\\' etc.\"'\n// → \"\\\"Lorem ipsum \\\\\\\"dolor\\\\\\\" sit \\'amet\\' etc.\\\"\"\n```\n\n#### `escapeEverything`\n\nThe `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.\n\n```js\nstringEscape('lolwat\"foo\\'bar', {\n  'escapeEverything': true\n});\n// → '\\\\x6C\\\\x6F\\\\x6C\\\\x77\\\\x61\\\\x74\\\\\"\\\\x66\\\\x6F\\\\x6F\\\\\\'\\\\x62\\\\x61\\\\x72'\n// → \"\\\\x6C\\\\x6F\\\\x6C\\\\x77\\\\x61\\\\x74\\\\\\\"\\\\x66\\\\x6F\\\\x6F\\\\'\\\\x62\\\\x61\\\\x72\"\n```\n\nThis setting also affects the output for arrays and objects:\n\n```js\nstringEscape({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, {\n  'escapeEverything': true\n});\n// → '{\\'\\x49\\x63\\x68\\x20\\u2665\\x20\\x42\\xFC\\x63\\x68\\x65\\x72\\':\\'\\x66\\x6F\\x6F\\x20\\uD834\\uDF06\\x20\\x62\\x61\\x72\\'}'\n// → \"{'\\x49\\x63\\x68\\x20\\u2665\\x20\\x42\\xFC\\x63\\x68\\x65\\x72':'\\x66\\x6F\\x6F\\x20\\uD834\\uDF06\\x20\\x62\\x61\\x72'}\"\n\nstringEscape([ 'Ich ♥ Bücher': 'foo 𝌆 bar' ], {\n  'escapeEverything': true\n});\n// → '[\\'\\x49\\x63\\x68\\x20\\u2665\\x20\\x42\\xFC\\x63\\x68\\x65\\x72\\',\\'\\x66\\x6F\\x6F\\x20\\uD834\\uDF06\\x20\\x62\\x61\\x72\\']'\n```\n\n#### `compact`\n\nThe `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.\n\n```js\nstringEscape({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, {\n  'compact': true // this is the default\n});\n// → '{\\'Ich \\u2665 B\\xFCcher\\':\\'foo \\uD834\\uDF06 bar\\'}'\n\nstringEscape({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, {\n  'compact': false\n});\n// → '{\\n\\t\\'Ich \\u2665 B\\xFCcher\\': \\'foo \\uD834\\uDF06 bar\\'\\n}'\n\nstringEscape([ 'Ich ♥ Bücher', 'foo 𝌆 bar' ], {\n  'compact': false\n});\n// → '[\\n\\t\\'Ich \\u2665 B\\xFCcher\\',\\n\\t\\'foo \\uD834\\uDF06 bar\\'\\n]'\n```\n\nThis setting has no effect on the output for strings.\n\n#### `indent`\n\nThe `indent` option takes a string value, and defaults to `'\\t'`. When the `compact` setting is enabled (`true`), the value of the `indent` option is used to format the output for arrays and objects.\n\n```js\nstringEscape({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, {\n  'compact': false,\n  'indent': '\\t' // this is the default\n});\n// → '{\\n\\t\\'Ich \\u2665 B\\xFCcher\\': \\'foo \\uD834\\uDF06 bar\\'\\n}'\n\nstringEscape({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, {\n  'compact': false,\n  'indent': '  '\n});\n// → '{\\n  \\'Ich \\u2665 B\\xFCcher\\': \\'foo \\uD834\\uDF06 bar\\'\\n}'\n\nstringEscape([ 'Ich ♥ Bücher', 'foo 𝌆 bar' ], {\n  'compact': false,\n  'indent': '  '\n});\n// → '[\\n  \\'Ich \\u2665 B\\xFCcher\\',\\n\\  t\\'foo \\uD834\\uDF06 bar\\'\\n]'\n```\n\nThis setting has no effect on the output for strings.\n\n#### `json`\n\nThe `json` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, the output will always be valid JSON. [Hexadecimal character escape sequences](http://mathiasbynens.be/notes/javascript-escapes#hexadecimal) and the `\\v` or `\\0` escape sequences will not be used. Setting `json: true` implies `quotes: 'double', wrap: true`.\n\n```js\nstringEscape('foo\\x00bar\\xFF\\uFFFDbaz', {\n  'json': true\n});\n// → '\"foo\\\\u0000bar\\\\u00FF\\\\uFFFDbaz\"'\n\nstringEscape({ 'foo\\x00bar\\xFF\\uFFFDbaz': 'foo\\x00bar\\xFF\\uFFFDbaz' }, {\n  'json': true\n});\n// → '{\"foo\\\\u0000bar\\\\u00FF\\\\uFFFDbaz\":\"foo\\\\u0000bar\\\\u00FF\\\\uFFFDbaz\"}'\n\nstringEscape([ 'foo\\x00bar\\xFF\\uFFFDbaz', 'foo\\x00bar\\xFF\\uFFFDbaz' ], {\n  'json': true\n});\n// → '[\"foo\\\\u0000bar\\\\u00FF\\\\uFFFDbaz\",\"foo\\\\u0000bar\\\\u00FF\\\\uFFFDbaz\"]'\n```\n\n### `stringEscape.version`\n\nA string representing the semantic version number.\n\n### Using the `jsesc` binary\n\nTo use the `jsesc` binary in your shell, simply install javascript-string-escape globally using npm:\n\n```bash\nnpm install -g string-escape\n```\n\nAfter that you will be able to escape strings from the command line:\n\n```bash\n$ jsesc 'föo ♥ bår 𝌆 baz'\nf\\xF6o \\u2665 b\\xE5r \\uD834\\uDF06 baz\n```\n\nTo escape flat arrays containing only string values or flat objects containing only string values, use the `-o`/`--object` option:\n\n```bash\n$ jsesc '{ \"föo\": \"♥\", \"bår\": \"𝌆 baz\" }'\nf\\xF6o \\u2665 b\\xE5r \\uD834\\uDF06 baz\n```\n\nCreate a version of a JSON file where any non-ASCII symbols are escaped:\n\n```bash\n$ cat data-raw.json | jsesc --json --object > data-escaped.json\n```\n\nSee `jsesc --help` for the full list of options.\n\n## Support\n\nThis 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.\n\n## Unit tests & code coverage\n\nAfter cloning this repository, run `npm install` to install the dependencies needed for development and testing. You may want to install Istanbul _globally_ using `npm install istanbul -g`.\n\nOnce that’s done, you can run the unit tests in Node using `npm test` or `node tests/tests.js`. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use `grunt test`.\n\nTo generate [the code coverage report](http://rawgithub.com/mathiasbynens/javascript-string-escape/master/coverage/javascript-string-escape/string-escape.js.html), use `grunt cover`.\n\n## Author\n\n| [![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](http://twitter.com/mathias \"Follow @mathias on Twitter\") |\n|---|\n| [Mathias Bynens](http://mathiasbynens.be/) |\n\n## License\n\nThis library is available under the [MIT](http://mths.be/mit) license.\n","scripts":{"test":"node tests/tests.js"},"_npmUser":{"name":"mathias","email":"mathias@qiwi.be"},"homepage":"http://mths.be/stringescape","keywords":["string","escape","tool"],"licenses":[{"url":"http://mths.be/mit","type":"MIT"}],"deprecated":"Package has been deprecated in favor of `jsesc`. Please `npm install jsesc` instead.","repository":{"url":"https://github.com/mathiasbynens/javascript-string-escape.git","type":"git"},"_npmVersion":"1.2.32","description":"A JavaScript library for escaping JavaScript strings while generating the shortest possible valid output.","directories":{"test":"tests"},"maintainers":[{"name":"mathias","email":"mathias@qiwi.be"}],"dependencies":{},"readmeFilename":"README.md","devDependencies":{"grunt":"~0.4.1","qunitjs":"~1.11.0","istanbul":"~0.1.37","requirejs":"~2.1.6","qunit-clib":"~1.3.0","regenerate":"~0.5.1","grunt-shell":"~0.2.2","grunt-template":"~0.1.0"},"_id":"string-escape@0.2.3","version":"0.2.3"}