Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haensl/embed-json
Node.js module to embed JSON data from files into html.
https://github.com/haensl/embed-json
embed html inline inline-json json json-data json-files json-schema minify
Last synced: about 2 months ago
JSON representation
Node.js module to embed JSON data from files into html.
- Host: GitHub
- URL: https://github.com/haensl/embed-json
- Owner: haensl
- License: mit
- Created: 2018-03-14T19:36:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T18:30:40.000Z (almost 2 years ago)
- Last Synced: 2024-10-06T10:19:01.619Z (3 months ago)
- Topics: embed, html, inline, inline-json, json, json-data, json-files, json-schema, minify
- Language: JavaScript
- Size: 124 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# embed-json
Node.js module to inline/embed JSON data from files into html.[![NPM](https://nodei.co/npm/embed-json.png?downloads=true)](https://nodei.co/npm/embed-json/)
[![npm version](https://badge.fury.io/js/embed-json.svg)](http://badge.fury.io/js/embed-json)
[![CircleCI](https://circleci.com/gh/haensl/embed-json.svg?style=svg)](https://circleci.com/gh/haensl/embed-json)
## Installation
### NPM
`npm i --save embed-json`### Yarn
`yarn add embed-json`## Usage
### Synopsis
```javascript
embedJson(htmlString, options);
```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.
```html```
it will retrieve the data from the file `src` and embed it into the tag. The `src` attribute is removed during this operation.### Example
```javascript
const embedJson = require('embed-json');
const fs = require('fs');const html = fs.readFileSync('index.html', 'utf8');
const htmlWithEmbeddedJSON = embedJson(html);
// script tags with src attribute in index.html
//
// are transformed to
// {dataThat:'was in data.json'}
```### Options
### encoding `string`
**Default:** `utf8`
Specify the [encoding](https://stackoverflow.com/a/14551669/5061949) of the JSON files.
### mimeTypes `Array | 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:** [`path.dirname(require.main.filename)`](https://stackoverflow.com/a/18721515/5061949) _(i.e. a best guess at the project root.)_
Specify the root directory from which to resolve relative `src`s.
### [Changelog](CHANGELOG.md)
### [License](LICENSE)