1.0.1 • Published 9 years ago

js-string-escape v1.0.1

Weekly downloads
2,160,306
License
MIT
Repository
github
Last release
9 years ago

js-string-escape

Build Status

Escape any string to be a valid JavaScript string literal between double quotes or single quotes.

Installation

npm install js-string-escape

Example

If you need to generate JavaScript output, this library will help you safely put arbitrary data in JavaScript strings:

jsStringEscape = require('js-string-escape')

console.log('"' + jsStringEscape('Quotes (\", \'), newlines (\n), etc.') + '"')
// => "Quotes (\", \'), newlines (\n), etc."

In other words, given any string s, the following invariants hold:

eval('"' + jsStringEscape(s) + '"') === s
eval("'" + jsStringEscape(s) + "'") === s

These eval expressions are safe with untrusted strings s.

Non-strings will be cast to strings.

Compliance

This library has been checked against ECMAScript 5.1 and tested against all Unicode code points.

Note that the returned string is not necessarily valid JSON, since JSON disallows control characters, and \' is illegal in JSON.

@ianlucas/service-analyticsdokztestmkdir-nativedas-builddokz-docs-3drupenucly-templatevue-webpack-index@drupe/cherry@drupe/env@drupe/html-plugin@you54f/serverless-offlinezy-ember-cli-stylelint@scrumble/appsync-emulator-serverlessyak-shave@xavo/cypress-cucumber-preprocessor@saaspe/componentsvisionr-dev@everything-registry/sub-chunk-1978cypress-cucumber-predecessortc-clitc-cli-majdyswagger-test-templatessvelvet-customwd-serverless-offlinewebant-handler-lesswebant-handler-scsswebant-handler-styluswebant-handler-textwebantwebant-handler-csswebant-handler-dustjswebant-handler-hbswebant-handler-jsserverless-dockerserverless-plugin-simulateserverless-offline-tempserverless-offline-reasintserverless-offline-scalewayserverless-offline-hot-reloadserverless-offline-imartinezserverless-offline-pythonserverless-offline-node-14sf-sketch-rpcsails-viewifyscriptless-cliscript-timing-proxyresxprocessorretellreplayriad-ai-imagegenreco.ioredful-verdacciosequelcomponentsemantic-release-gitmoji-actionsvelte-component-libvitaminjsvitaminjs-runtimeverdaccio-localvoluptasvelitmetalsmith-angular-templatecachemodule-generatormocha-stylus-compilerminibook-loadermocha-imguri-compilerlaravel-blade-jsjavascript-obfuscatorjavascript-obfuscator-codegenjavascript-obfuscator-unstring-arrayjavascript-obfuscator-xjade-cache-brunchjagerjson-columnsjs-string-escape-clijsperfibm-wch-sdk-cliinteractive-libsinteractive-decks-libitsa-react-servermodunitmplayer-wrapperjunglistjsreport-assetsks-serverless-offlinehtml-templateifyhtml-inlinifyhxng-loadergulp-hot-ng-templatesgulp-ng-templatecachegulp-ng-templatesgulp-resource-cachegulp-inject-stringified-htmlgulp-angular-svg-dgulp-angular-templatecache-hfgulp-angular-templatecache-n3utrinogulp-angular-templatecache-noconcatgulp-js-stringgulp-js-inlinegulp-ng-directive-templategulp-ng-jsoncache
1.0.1

9 years ago

1.0.0

12 years ago

0.0.1

12 years ago