htmlescape
Properly escape JSON for usage as an object literal inside of a `<script>` tag
Last updated 4 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 (4 years ago)

4 Versions

  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 16
This Week 681
This Month 4,552
Last Day 323
Last Week 2,015
Last Month 6,868
Dependencies (0)
None
Dev Dependencies (1)
Dependents (111)

Copyright 2014 - 2016 © taobao.org |