js-string-escape

WebJar for js-string-escape

License

License

MIT
Categories

Categories

JavaScript Languages
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

js-string-escape
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

js-string-escape
WebJar for js-string-escape
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/joliss/js-string-escape

Download js-string-escape

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/js-string-escape/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>js-string-escape</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/js-string-escape/
implementation 'org.webjars.npm:js-string-escape:1.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/js-string-escape/
implementation ("org.webjars.npm:js-string-escape:1.0.1")
'org.webjars.npm:js-string-escape:jar:1.0.1'
<dependency org="org.webjars.npm" name="js-string-escape" rev="1.0.1">
  <artifact name="js-string-escape" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='js-string-escape', version='1.0.1')
)
libraryDependencies += "org.webjars.npm" % "js-string-escape" % "1.0.1"
[org.webjars.npm/js-string-escape "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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.

Versions

Version
1.0.1
1.0.0