A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/node-base/base-data below:

base-repos/base-data: adds a `data` method to base-methods. 100% unit test coverage and browserify-friendly lazy-caching.

adds a data method to base-methods.

(TOC generated by verb using markdown-toc)

Install with npm:

$ npm install --save base-data

Adds a data method to base that can be used for setting, getting and loading data onto a specified object in your application.

var Base = require('base');
var data = require('base-data');

// instantiate `Base`
var base = new Base();
// add `data` as a plugin
base.use(data());

Examples

Add data:

app.data('a', 'b');
app.data({c: 'd'});
app.data('e', ['f']);
console.log(app.cache.data);
//=> {a: 'b', c: 'd', e: ['f']}

cache.data

By default, all data is loaded onto app.cache.data. This can be customized by passing the property to use when the plugin is initialized.

For example, the following set app.foo as object for storing data:

app.use(data('foo'));
app.data('a', 'b');
console.log(app.foo);
//=> {a: 'b'}

Register a data loader for loading data onto app.cache.data.

Params

Example

var yaml = require('js-yaml');

app.dataLoader('yml', function(str, fp) {
  return yaml.safeLoad(str);
});

app.data('foo.yml');
//=> loads and parses `foo.yml` as yaml

Load data onto app.cache.data

Params

Example

console.log(app.cache.data);
//=> {};

app.data('a', 'b');
app.data({c: 'd'});
console.log(app.cache.data);
//=> {a: 'b', c: 'd'}

// set an array
app.data('e', ['f']);

// overwrite the array
app.data('e', ['g']);

// update the array
app.data('e', ['h'], true);
console.log(app.cache.data.e);
//=> ['g', 'h']

Shallow extend an object onto app.cache.data.

Params

Example

app.data({a: {b: {c: 'd'}}});
app.data.extend('a.b', {x: 'y'});
console.log(app.get('a.b'));
//=> {c: 'd', x: 'y'}

Deeply merge an object onto app.cache.data.

Params

Example

app.data({a: {b: {c: {d: {e: 'f'}}}}});
app.data.merge('a.b', {c: {d: {g: 'h'}}});
console.log(app.get('a.b'));
//=> {c: {d: {e: 'f', g: 'h'}}}

Union the given value onto a new or existing array value on app.cache.data.

Params

Example

app.data({a: {b: ['c', 'd']}});
app.data.union('a.b', ['e', 'f']}});
console.log(app.get('a.b'));
//=> ['c', 'd', 'e', 'f']

Set the given value onto app.cache.data.

Params

Example

app.data.set('a.b', ['c', 'd']}});
console.log(app.get('a'));
//=> {b: ['c', 'd']}

Get the value of key from app.cache.data. Dot-notation may be used for getting nested properties.

Params

Example

app.data({a: {b: {c: 'd'}}});
console.log(app.get('a.b'));
//=> {c: 'd'}

Glob patterns may be passed as a string or array. All of these work:

app.data('foo.json');
app.data('*.json');
app.data(['*.json']);
// pass options to node-glob
app.data(['*.json'], {dot: true});

Namespacing allows you to load data onto a specific key, optionally using part of the file path as the key.

Example

Given that foo.json contains {a: 'b'}:

app.data('foo.json');
console.log(app.cache.data);
//=> {a: 'b'}

app.data('foo.json', {namespace: true});
console.log(app.cache.data);
//=> {foo: {a: 'b'}}

app.data('foo.json', {
  namespace: function(fp) {
    return path.basename(fp);
  }
});
console.log(app.cache.data);
//=> {'foo.json': {a: 'b'}}

v0.6.0

v0.5.0

v0.4.0

v0.3.6

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Jon Schlinkert

Copyright © 2017, Jon Schlinkert. Released under the MIT License.

This file was generated by verb-generate-readme, v0.6.0, on July 20, 2017.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4