htmlescape
Properly escape JSON for usage as an object literal inside of a `<script>` tag
Last updated 10 years ago by zertosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install htmlescape 
SYNC missed versions from official npm registry.

htmlescape

Properly escape JSON for usage as an object literal inside of a <script> tag. Use htmlescape in place of JSON.stringify. For more info see JSON: The JavaScript subset that isn't.

Transformations

from to
& \\u0026
> \\u003e
< \\u003c
\u2028 \\u2028
\u2029 \\u2029

Usage

var htmlescape = require('htmlescape');
htmlescape({prop:'value'});
//=> '{"prop":"value"}'

Or in your templates:

<script>
var payload = <%= htmlescape(payload) %>;
</script>

Current Tags

  • 1.1.1                                ...           latest (10 years ago)

4 Versions

  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.0                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (4)

Copyright 2013 - present © cnpmjs.org | Home |