jsafe
v1.0.2
Published
very fast queue for JSON write queries
Downloads
7
Maintainers
Readme
JSafe
Very fast queue for JSON write queries.
Install
npm install jsafe
Import
const { write, read } = require("jsafe")
Functions
write(jsonPath, jsonData) ⇒ promise
Add JSON object to write or to stack.
Kind: global function Returns: promise - - But catch error is optional.
| Param | Type | Description | | --- | --- | --- | | jsonPath | string | The path of json file. | | jsonData | object | JSON stringable data. |
write("./file.json", json)
// Check if a writing is in progress.
// If so, overwrites the waiting stack
// with the new version of the file.
read(jsonPath, defaultJsonData) ⇒ object
Read the JSON file if it exists.
Kind: global function Returns: object - - JSON exploitable data.
| Param | Type | Description | | --- | --- | --- | | jsonPath | string | The path of json file. | | defaultJsonData | object | JSON stringable data. |
const json = read("./file.json", "Hello World")
// Require json and delete require.cache.
// To do only once in the same script.
// Returns defaultJsonData if the file is non-existent.