# js-string-escape

> Escape strings for use as JavaScript string literals

Latest version **1.0.1** (published 2016-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-string-escape
pnpm add js-string-escape
yarn add js-string-escape
bun add js-string-escape
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-03-11 |
| First published | 2013-05-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/js-string-escape) |
| Module format | CommonJS |
| Node | >= 0.8 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 71 |
| Author | Jo Liss |
| Maintainers | joliss |
| Keywords | string, escape, backslash, javascript, ecmascript |

## Links

- npm: https://www.npmjs.com/package/js-string-escape
- Repository: https://github.com/joliss/js-string-escape
- Homepage: https://github.com/joliss/js-string-escape#readme
- Issues: https://github.com/joliss/js-string-escape/issues
- npm.io page: https://npm.io/package/js-string-escape

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2016-03-11
- 1.0.0 — 2013-06-17
- 0.0.1 — 2013-05-12

## README

# js-string-escape

[![Build Status](https://travis-ci.org/joliss/js-string-escape.png?branch=master)](https://travis-ci.org/joliss/js-string-escape)

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:

```js
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:

```js
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](http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4) 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.

---
_Source: https://npm.io/package/js-string-escape · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
