Sha256: f84b3043d688a7ecab595634b22f144ca7a16798674f983800cc5fb03a085c96
Contents?: true
Size: 663 Bytes
Versions: 7
Compression:
Stored size: 663 Bytes
Contents
# 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](http://timelessrepo.com/json-isnt-a-javascript-subset). ## Transformations | from | to | | -------- |:---------:| | `&` | `\\u0026` | | `>` | `\\u003e` | | `<` | `\\u003c` | | `\u2028` | `\\u2028` | | `\u2029` | `\\u2029` | ## Usage ```js var htmlescape = require('htmlescape'); htmlescape({prop:'value'}); //=> '{"prop":"value"}' ``` Or in your templates: ```html <script> var payload = <%= htmlescape(payload) %>; </script> ```
Version data entries
7 entries across 7 versions & 2 rubygems