@delucis/reading-data-json-loader
v0.2.0
Published
JSON file loader plugin for @delucis/reading-data.
Downloads
7
Readme
@delucis/reading-data-json-loader
A plugin for @delucis/reading-data
that loads JSON files over the network or from the local file system.
Installation
npm install --save @delucis/reading-data-json-loader
Usage
const RD = require('@delucis/reading-data')
const JSON_LOADER = require('@delucis/reading-data-json-loader')
RD.use(JSON_LOADER, {
scope: 'myJSONFile',
path: 'https://unpkg.com/@delucis/reading-data/package.json'
})
RD.run().then((res) => {
console.log(res.data.myJSONFile)
})
Using reading-data-json-loader
to load multiple files
RD.use(JSON_LOADER, {
scope: [local, github, unpkg]
path: {
local: 'package.json',
github: 'https://raw.githubusercontent.com/delucis/reading-data/master/package.json',
unpkg: 'https://unpkg.com/@delucis/reading-data/package.json'
}
})
RD.run().then((res) => {
for (var key in res.data) {
console.log(key) // 'local', 'github', 'unpkg'
}
})
Options
name | type | default | required? | description
--------|----------------------|---------------|:---------:|-------------------------------------------------------------------------------------------------------------------------------------------
hooks
| String
, Object
| | | The reading-data
hook that should load the JSON file. Can be scoped by passing a object with scopes as keys, hooks as values.
path
| String
, Object
| | ✔︎ | The path or URL of the JSON file to load. Can be an object, where the keys match the scope(s) set in the scope
option.
scope
| String
, Array
| 'json-loader' | ✔︎ | The scope under which reading-data
will store this plugin’s data. Can be an array to return multiple filepaths/URLs, to multiple scopes.