Data/Config
This utility provides a Data and Config class, the Data class allows for the manipulation of a data object using a dot deliminated path. While the Config class extends the Data class with load and save functionality.
Installation
$ npm install data-config
Usage
const Data = Data; let myData = value1: "hello" value2: value3: "world" ; // > "hello"console; // > "world"console; // > nullconsole; // > "hello world"console;
The Data class provides the a get, set, del and has methods to get, set, delete and check for properties.
const Data = Data; // Create the Data object, and use '.' for the deliminator.let myData = {} '.'; // > falsemyData; // > nullmyData; myData; // > truemyData; // > "hello world"myData; myData; // > falsemyData; // > nullmyData;
Setting the data using the Data object also updates the provided data object, for example:
const Data = Data; let data = {};let myData = data; myData; // > {"value1": {"value2": "hello world"}}consoledirdata;
Finally, you can also create references from a larger data object, which will kepp each other updated:
const Data = Data; let data = 'settings': 'module1': 'value1': 'hello world' 'module2': 'value1': 'foo bar' ;let myData = data; let ref1 = myData;let ref2 = myData; // > "hello world"console;console; // > "foo bar"console;console; ref1; // > "foo bar"console;console; // > "foo bar"console;console; // > {"settings": {"module1": {"value1": "foo bar"}}, "module2": {"value1": "foo bar"}}}consoledirdata;
Config object
The config object extends from the Data class, but provides the load/loadSync and save/saveSync methods.
const Config = Config; let config = 'path/to/config-file.json';config;
Testing
A mocha test suite has been provided and can be run by:
$ npm test