2.0.0 • Published 6 years ago

json-from-script v2.0.0

Weekly downloads
34
License
MIT
Repository
github
Last release
6 years ago

json-from-script

Tiny JSON parser for your Content Security Policy aware script tags.

NPM version Build Status Gzip size Install size

Installation

$ npm install --save json-from-script

Usage

Real Example on JSFiddle ➡️

When your HTML contains any script tag like this;

<script type="application/json" class="data" data-attr="foo">{&quot;bar&quot;:&quot;baz&quot;}</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

2.0.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago