3.6.0 • Published 7 years ago

spike-records-loaddir v3.6.0

Weekly downloads
2
License
ISC
Repository
-
Last release
7 years ago

spike-records-loadDir

Build Status Coverage Status Greenkeeper badge

Load a directory of local data files in yaml or json format into spike-records

This module loads (merges) all yaml or json files within a given directory (and subdirectories) into a single data object (viewDat). This data object is updated with preference for the last merge over the first one. The recursive merge is implemented with lodash.

Installation

npm i spike-records -S
npm i spike-records-loadir -S

Usage in spike's app.js

const standard = require('reshape-standard')
const Records = require('spike-records')
const Datadir = require('spike-records-loaddir');
const locals = {}

// Create a config instance
var dataDir = new Datadir();

// Add all the JSON and YAML files in a directory
dataDir.source('path/to/your/data/directory');

// Add merged data object to spike-records
module.exports = {
  reshape: (ctx) => standard({ locals }),
  plugins: [new Records({
    addDataTo: locals,
    myData: { data: dataDir.get() }
  })]
}

API

new Datadir()

Constructor of a data instance.

var dataDir = new Datadir();

get(path)

Retrieve the data object.

// Get the fully merged data as an object
datadir.get();

source(path)

Loads a data file (if path targets a file), a set of data files located in a directory (if path targets a directory)

NOTE: If path targets a directory, the library merges any da file located in the directory, including subdirectory recursion.

It supports json and yaml files which are identified by the file extension.

// Add all the JSON and YAML files in a directory
dataDir.source('path/to/your/data/directory');
3.6.0

7 years ago

2.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago