GhomKrosmonaute / jsafe

safely queue for JSON write queries

Home Page:https://www.npmjs.com/package/jsafe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

read(jsonPath, defaultJsonData)object

Read the JSON file if it exists.

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.

About

safely queue for JSON write queries

https://www.npmjs.com/package/jsafe


Languages

Language:JavaScript 100.0%