Node.js module to embed JSON data from files into html.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.eslintrc.json
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
index.js
package-lock.json
package.json

README.md

embed-json

Node.js module to inline/embed JSON data from files into html.

NPM

Build Status

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,
 * e.g.
 *  <script type="application/json" src="data.json"></script>
 * it will retrieve the data from the file and embed it into the tag, while removing
 * the src attribute.
 */
embedJson(htmlString, options);

Example

const embedJson = require('embed-json');
const fs = require('fs');

const html = fs.readFileSync('index.html', 'utf8');
embedJson(html);

Options

encoding string

Default: utf8

Specify the encoding of the JSON files.

mimeTypes Array<string> | string

Default: ['application/json', 'application/ld+json']

Specify the mime type(s) of scripts to embed.

minify boolean

Default: true

Specify whether or not to minify the embedded JSON data.

root string

Default: __dirname

Specify the directory in which the JSON files are stored.

Changelog

License