Skip to content

Commit

Permalink
README: Add jsesc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Jul 26, 2013
1 parent 6ae242b commit 61b583a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ A string representing the semantic version number.
To use the `jsesc` binary in your shell, simply install javascript-string-escape globally using npm:

```bash
npm install -g javascript-string-escape
npm install -g string-escape
```

After that you will be able to escape strings from the command line:
Expand All @@ -273,6 +273,39 @@ $ jsesc 'föo ♥ bår 𝌆 baz'
f\xF6o \u2665 b\xE5r \uD834\uDF06 baz
```

To escape flat arrays containing only string values or flat objects containing only string values, use the `-o`/`--object` option:

```bash
$ jsesc --object '{ "föo": "♥", "bår": "𝌆 baz" }'
{'f\xF6o':'\u2665','b\xE5r':'\uD834\uDF06 baz'}
```

To prettify the output in such cases, use the `-p`/`--pretty` option:

```bash
$ jsesc --pretty '{ "föo": "♥", "bår": "𝌆 baz" }'
{
'f\xF6o': '\u2665',
'b\xE5r': '\uD834\uDF06 baz'
}
```

For valid JSON output, use the `-j`/`--json` option:

```bash
$ jsesc --json --pretty '{ "föo": "♥", "bår": "𝌆 baz" }'
{
"f\u00F6o": "\u2665",
"b\u00E5r": "\uD834\uDF06 baz"
}
```

To create a version of a JSON file (representing a flat array containing only string values or a flat object containing only string values) where any non-ASCII symbols are escaped:

```bash
$ cat data-raw.json | jsesc --json --object > data-escaped.json
```

See `jsesc --help` for the full list of options.

## Support
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "A JavaScript library for escaping JavaScript strings while generating the shortest possible valid output.",
"homepage": "http://mths.be/stringescape",
"main": "string-escape.js",
"bin": "bin/jsesc",
"bin": {
"jsesc": "bin/jsesc"
},
"man": "man/jsesc.1",
"keywords": [
"string",
Expand All @@ -30,7 +32,9 @@
},
"files": [
"LICENSE-MIT.txt",
"string-escape.js"
"string-escape.js",
"bin/",
"man/"
],
"directories": {
"test": "tests"
Expand Down

0 comments on commit 61b583a

Please sign in to comment.