Requires
- module:winston
- module:lodash.clonedeep
Members
(inner) data :Object
Contains the reading data currently available.
Type:
-
Object
Methods
(inner) addHook(hook, prepositionopt, locationopt) → {Object}
Adds a hook to be called during ReadingData’s
.run()
cycle.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hook |
String
|
The name of the new hook to register. |
|
preposition |
String
|
<optional> |
Either |
location |
String
|
<optional> |
The name of the existing hook to register the new hook before or after. |
Examples
const RD = require('@delucis/reading-data')
RD.addHook('postProcess')
const RD = require('@delucis/reading-data')
RD.addHook('init', 'before')
const RD = require('@delucis/reading-data')
RD.addHook('preProcess', 'before', 'process')
(inner) clean(scopeopt) → {Object}
Clean up .data
, wiping parts or all of it.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
scope |
String
|
<optional> |
The scope to be cleaned. |
Examples
const RD = require('@delucis/reading-data')
// ... Following several .run() cycles, RD.data is cluttered
// ... and you want to start from a clean slate.
console.log(RD.data) // => { plugin1Data: { ... }, preloadData: [ ... ] }
RD.clean()
console.log(RD.data) // => {}
const RD = require('@delucis/reading-data')
// ...
console.log(RD.data) // => { plugin1Data: { ... }, preloadData: [ ... ] }
RD.clean('plugin1Data')
console.log(RD.data) // => { preloadData: [ ... ] }
(inner) config() → {Object}
Get the current configuration.
Returns:
- Type:
-
Object
An object containing the current configuration.
(inner) hooks() → {Array.<String>}
Get an array of currently registered hooks.
Returns:
- Type:
-
Array.<String>
An array of registered hook names.
(inner) meta() → {Object}
Get the metadata object for this instance of reading-data.
Returns:
- Type:
-
Object
Object containing metadata about reading-data, e.g. how long .run()
took to complete.
(inner) plugins() → {Array.<Object>}
Get an array of the currently installed plugins.
Returns:
- Type:
-
Array.<Object>
An array of the currently installed plugins.
(inner) preloadData(arg) → {Object}
Configure ReadingData’s preload options.
Utility for configuring the .preload
and .preloadData
properties of .config
.
Parameters:
Name | Type | Description |
---|---|---|
arg |
Object
|
Boolean
|
Passing an object will register this object as the data to be preloaded and enable preloading. Passing true/false will enable/disable preloading. |
Example
const RD = require('@delucis/reading-data')
const EXISTING_DATA = require('./some-data-i-saved-earlier.json')
RD.preloadData(EXISTING_DATA)
// Equivalent to:
// RD.config.preload = true
// RD.config.preloadData = EXISTING_DATA
RD.preloadData(false)
// Equivalent to:
// RD.config.preload = false
(inner) run() → {Object}
Trigger ReadingData
’s data gathering cycle:
preload
, fetch
, process
.
Examples
const RD = require('@delucis/reading-data')
const helpfulPlugin = require('helpful-reading-data-plugin')
RD.use(helpfulPlugin)
RD.run().then((result) => {
console.log(result.data)
})
const RD = require('@delucis/reading-data')
const helpfulPlugin = require('helpful-reading-data-plugin')
RD.use(helpfulPlugin)
let asynchronousDataLogger = async function () {
await RD.run()
console.log(RD.data)
}
asynchronousDataLogger()
(inner) uninstall(pluginopt) → {Object}
Remove plugins from the ReadingData
instance
that were installed with .use()
.
It will unlist plugins from .plugins
and remove their settings from .config.plugins
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
plugin |
Object
|
<optional> |
A previously installed plugin object. |
Examples
const RD = require('@delucis/reading-data')
const plugin1 = require('unhelpful-reading-data-plugin')
const plugin2 = require('really-unhelpful-reading-data-plugin')
// Tell ReadingData to use some plugins.
RD.use(plugin1)
RD.use(plugin2)
// Remove all plugins currently added to the ReadingData instance.
RD.uninstall()
const RD = require('@delucis/reading-data')
const plugin1 = require('unhelpful-reading-data-plugin')
const plugin2 = require('helpful-reading-data-plugin')
// Tell ReadingData to use some plugins.
RD.use(plugin1)
RD.use(plugin2)
// Remove a specific plugin.
RD.uninstall(plugin1)
(inner) use(plugin, optsopt) → {Object}
Tell ReadingData
to use a plugin.
Adds the provided plugin
to .plugins
and merges any provided opts
with plugin.config
before adding it to
.config.plugins
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
plugin |
Object
|
The plugin to be installed. |
|
opts |
Object
|
<optional> |
Configuration parameters for the plugin. |
Example
const RD = require('@delucis/reading-data')
const plugin = require('helpful-reading-data-plugin')
const myPluginOptions = {
numberOption: 5,
stringOption: 'Five!'
}
// Tell ReadingData instance to use the plugin.
RD.use(plugin, myPluginOptions)
// Trigger ReadingData’s run() cycle, which will call all installed plugins.
RD.run()