reading-data

Requires

  • module:winston
  • module:lodash.clonedeep

Members

(inner) data :Object

Contains the reading data currently available.

Since:
  • 0.0.1
Source:
Type:
  • Object

Methods

(inner) addHook(hook, prepositionopt, locationopt) → {Object}

Adds a hook to be called during ReadingData’s .run() cycle.

Since:
  • 0.2.0
Source:
Parameters:
Name Type Attributes Description
hook String

The name of the new hook to register.

preposition String <optional>

Either 'before' or 'after'.

location String <optional>

The name of the existing hook to register the new hook before or after.

Returns:
Type:
Object

Returns ReadingData to allow for method chaining.

Examples

Add a new hook after all existing hooks.

const RD = require('@delucis/reading-data')
RD.addHook('postProcess')

Add a new hook before all existing hooks.

const RD = require('@delucis/reading-data')
RD.addHook('init', 'before')

Add a “preProcess” hook before the existing “process” hook.

const RD = require('@delucis/reading-data')
RD.addHook('preProcess', 'before', 'process')

(inner) clean(scopeopt) → {Object}

Clean up .data, wiping parts or all of it.

Since:
  • 0.0.1
Source:
Parameters:
Name Type Attributes Description
scope String <optional>

The scope to be cleaned.

Returns:
Type:
Object

Returns ReadingData to allow for method chaining.

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.

Since:
  • 0.6.0
Source:
Returns:
Type:
Object

An object containing the current configuration.

(inner) hooks() → {Array.<String>}

Get an array of currently registered hooks.

Since:
  • 0.2.0
Source:
Returns:
Type:
Array.<String>

An array of registered hook names.

(inner) meta() → {Object}

Get the metadata object for this instance of reading-data.

Since:
  • 0.8.0
Source:
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.

Since:
  • 0.5.0
Source:
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.

Since:
  • 0.0.1
Source:
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.

Returns:
Type:
Object

Returns ReadingData to allow for method chaining.

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.

Since:
  • 0.0.1
Source:
Returns:
Type:
Object

Returns ReadingData to allow for method chaining.

Examples

Use with Promise-style syntax

const RD = require('@delucis/reading-data')
const helpfulPlugin = require('helpful-reading-data-plugin')

RD.use(helpfulPlugin)

RD.run().then((result) => {
  console.log(result.data)
})

Use in an asynchronous function

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.

Since:
  • 0.0.1
Source:
Parameters:
Name Type Attributes Description
plugin Object <optional>

A previously installed plugin object.

Returns:
Type:
Object

Returns ReadingData to allow for method chaining.

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.

Since:
  • 0.0.1
Source:
Parameters:
Name Type Attributes Description
plugin Object

The plugin to be installed.

opts Object <optional>

Configuration parameters for the plugin.

Returns:
Type:
Object

Returns ReadingData to allow for method chaining.

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()