npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

embed-json

1.1.2 • Public • Published

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

install

npm i embed-json

Downloadsweekly downloads

15

version

1.1.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability