- Source:
The config manager for WSH (Windows Script Host) that reads/writes configuration values in a JSON file.
Requires
Members
(static) clear
- Source:
Deletes all items.
Example
var conf = new Wsh.ConfigStore();
conf.path; // %CD%\.wsh\settings.json
conf.store; // { a: [{ b: { c: 3 } }], d: 'D' }
conf.has('a'); // true
conf.has(['a', 0, 'b', 'c']); // true
conf.has('d'); // true
console.clear();
conf.store; // Returns: {}
(static) del
- Source:
Deletes an item. I wanted to name delete to this method. But on JScript, can not use .delete as Object property name.
Example
var conf = new Wsh.ConfigStore();
conf.path; // %CD%\.wsh\settings.json
conf.store; // { a: [{ b: { c: 3 } }], d: 'D' }
conf.has('a'); // true
conf.has('d'); // true
conf.del('d');
conf.has('d'); // false
conf.store; // { a: [{ b: { c: 3 } }] }
(static) get
- Source:
Gets an item.
Example
var conf = new Wsh.ConfigStore();
conf.path; // %CD%\.wsh\settings.json
conf.store; // { a: [{ b: { c: 3 } }], d: 'D' }
conf.get(); // undefined
conf.get('a'); // [{ b: { c: 3 } }]
conf.get('a.0.b'); // { c: 3 }
conf.get(['a', 0, 'b', 'c']); // 3
conf.get('n'); // undefined
conf.get('n', 'Default Value'); // 'Default Value'
(static) has
- Source:
Checks if store has an item.
Example
var conf = new Wsh.ConfigStore();
conf.path; // %CD%\.wsh\settings.json
conf.store; // { a: [{ b: { c: 3 } }], d: 'D' }
conf.has('a'); // true
conf.has('a.0.b'); // true
conf.has(['a', 0, 'b', 'c']); // true
conf.has('n'); // false
(static) set
- Source:
Sets an item and writes the JSON file.
Example
var conf = new Wsh.ConfigStore();
conf.path; // %CD%\.wsh\settings.json
conf.store; // Returns: {}
// Set values and update the JSON file.
conf.set({ a: [{ b: { c: 3 } }], d: 'D' });
conf.store;
// Returns: { a: [{ b: { c: 3 } }], d: 'D' }
conf.set('n', 'New Value');
conf.store;
// Returns: { a: [{ b: { c: 3 } }], d: 'D', n: 'New Value' }
conf.set('o.p.q', 'Deep Val');
conf.store;
// Returns:
// { a: [{ b: { c: 3 } }],
// d: 'D',
// n: 'New Value',
// o: { p: { q: 'Deep Val' } } }
(static) store
- Source:
Returns the object in read JSON file.
Example
var conf = new Wsh.ConfigStore();
conf.store; // { a: [{ b: { c: 3 } }], d: 'D' }