embed-json
Node.js module to inline/embed JSON data from files into html.
Installation
NPM
npm i --save embed-json
Yarn
yarn add embed-json
Usage
Synopsis
;
Embed JSON data from referenced files into the given HTML string.
When embedJson()
encounters a script tag with JSON mime type and a src attribute with htmlString
, e.g.
it will retrieve the data from the file src
and embed it into the tag. The src
attribute is removed during this operation.
Example
const embedJson = ;const fs = ; const html = fs;const htmlWithEmbeddedJSON = ;// script tags with src attribute in index.html// <script type="application/json" src="data.json"></script>// are transformed to// <script type="application/json">{dataThat:'was in data.json'}</script>
Options
string
encoding Default: utf8
Specify the encoding of the JSON files.
Array<string> | string
mimeTypes Default: ['application/json', 'application/ld+json']
Specify the mime type(s) of scripts to embed.
boolean
minify Default: true
Specify whether or not to minify the embedded JSON data.
string
root Default: path.dirname(require.main.filename)
(i.e. a best guess at the project root.)
Specify the root directory from which to resolve relative src
s.