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                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 161
This Week 820
This Month 2,685
Last Day 493
Last Week 2,905
Last Month 13,792
Dependencies (0)
None
Dev Dependencies (1)
Dependents (112)

Copyright 2014 - 2017 © taobao.org |