2.0.0 • Published 7 years ago
json-from-script v2.0.0
json-from-script
Tiny JSON parser for your Content Security Policy aware script tags.
Installation
$ npm install --save json-from-scriptUsage
When your HTML contains any script tag like this;
<script type="application/json" class="data" data-attr="foo">{"bar":"baz"}</script>You can parse it in your Javascript application like this;
import jsonFromScript from 'json-from-script';
// Parsed will be { foo: { bar: 'baz' } }
const parsed = jsonFromScript();API
jsonFromScript(selector, attribute)
Creates a new instance of the parser with the given options. The following options can alternatively be provided to configure the parser for your specific needs:
selector <String>: The selector for the script tags to parse. (default: script.data)attribute <String>: The data attribute to use when setting the attribute on the parsed object. (default: data-attr)
License
MIT © Robin van der Vleuten