jsontxt
v0.1.9
Published
Read, write, and delete JSON stored in a `.txt` file.
Maintainers
Readme
jsontxt
Read, write, and delete JSON stored in a .txt file.
Installation
npm install jsontxt
# or
yarn add jsontxtUsage
const jsontxt = require("jsontxt"); // commonjs
// or
import jsontxt from "jsontxt"; // esmWrite
jsontxt.write([{ key: "value" }, "item"], { filename: "test" });
// { success: true, error: null }Read
jsontxt.read({ filename: "test" });
// { success: true, error: null, data: [{ key: "value" }, "item"] }Delete
jsontxt.delete({ filename: "test" });
// { success: true, error: null }File Size
jsontxt.filesize({ filename: "test" });
// { b: 1500, kb: 1.5, mb: 0.0015, ..., bytes: "1,500 bytes", kilobytes: "1.5kb", ... }File Path
The .txt file is resolved in the following order:
option.filepathpassed directly to the functionJSONTXT_PATHenvironment variablePWDenvironment variableprocess.cwd()
File Name
The .txt filename is resolved in the following order:
option.filenamepassed directly to the functionJSONTXT_NAMEenvironment variablejson_<NODE_ENV>.txt(e.g.json_development.txt)json.txt
Options
All functions accept an optional FilePathOptions object:
| Option | Type | Description |
| ---------- | -------- | ------------------------------------------- |
| filepath | string | Absolute path to the directory or file |
| filename | string | Name of the .txt file (without extension) |
License
MIT
