0.0.3 • Published 8 years ago
json-interface v0.0.3
README
Adds an API layer on top of JSON config files.
Purpose
- Simplify loading and saving of json files across a nodejs project
- Utilises a cache to ensure integrity or data object across multiple node modules.
- Will return the same object instance of the data to operate upon, unless noCache = true
- Emulates permissions of read/write upon a JSON file
- if read:
{data : jsonObj}
- if write:
{data:jsonObj, save:fnc, revert:fnc}
- if read:
- Version - 0.0.2
Operation
jsonConfigInterface = require('json-config-interface')
- Config files can be loaded with or without .json extension specified
- Config files can be loaded from:
- relative dir path
jsonConfigInterface.get('./my-config')
- absolute dir path
jsonConfigInterface.get('/path/to/configs/my-config')
- explicitly defined config directory
jsonConfigInterface.setDir('/path/to/configs/'); jsonConfigInterface.get('my-config')
- relative dir path
- Get with methods to save and revert
jsonConfigInterface.get('/my-config', 'write')
- Get a fresh load of config file not from shared cahce
jsonConfigInterface.get('/my-config', 'write', true)
- Purge cache of config file
jsonConfigInterface.purge('/my-config')
- Purge entire cache
jsonConfigInterface.purge()
TODO
*json schema validation support
- sandbox object returns made where write is not specified, as currently a load in read mode can still make edits. (is this possible? some form of JSON parse clone could be used, but it would need to be updated if anywhere else makes a legit edit, how would we watch for that?)