Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

embed-json

1.1.5 • 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

5

Version

1.1.5

License

MIT

Unpacked Size

6.47 kB

Total Files

5

Last publish

Collaborators

  • avatar