Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bsnext/livejson
Live controller for JSON documents.
https://github.com/bsnext/livejson
controller edit json live manage nodejs typescript watch
Last synced: 7 days ago
JSON representation
Live controller for JSON documents.
- Host: GitHub
- URL: https://github.com/bsnext/livejson
- Owner: bsnext
- License: mit
- Created: 2024-04-11T11:26:35.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-12T22:21:58.000Z (9 months ago)
- Last Synced: 2024-12-15T20:20:26.690Z (about 1 month ago)
- Topics: controller, edit, json, live, manage, nodejs, typescript, watch
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LiveJSON
Package for working with "live" JSON documents, and easy get access to updates.**Case 1:**
Store some minor project settings, as example "Disabled Registration" or "Enabled Captcha". Manage this status from your code, or just by edit file with text-editor.**Case 2:**
Share and manage some variables between few Node.JS instances. Set variable from **Process #1**, and have access to that from **Process #2**.## Installing:
```bash
npm install @bsnext/livejson
```## Usage:
```ts
new LiveJSON(filePath: string [, { interval: number = 50 }])
new LiveJSONSync(filePath: string [, { interval: number = 50 }])
```* filePath - Path to your JSON file.
* interval - Delay betweeb checking file updates.```ts
import { LiveJSONSync, LiveJSON } from "@bsnext/livejson";
const exampleFile = new LiveJSONSync(`myFile.json`);// Get Value
exampleFile.get(`variableName`);// Set Value
exampleFile.set(`variableName`, 1337);// Set Multiple Values
exampleFile.set(
{
variableName: 777,
oneMoreVariable: `Hi!`
}
);
```## API:
```ts
LiveJSONSync.get(key: string) // Get Value
LiveJSONSync.getAll() // Get All Values
LiveJSONSync.save() // Manual Save File
LiveJSONSync.reload(strict: boolean = false) // Manual Reload File
LiveJSONSync.set(key: string, value: any[, save: boolean = true]) // Set Value
LiveJSONSync.set({[key: string]: any}, [, save: boolean = true]) // Set Multiple ValuesLiveJSON.get(key: string)
LiveJSON.getAll()
await LiveJSON.save()
await LiveJSON.reload(strict: boolean = false)
await LiveJSON.set(key: string, value: any[, save: boolean = true])
await LiveJSON.set({[key: string]: any}, [, save: boolean = true])
```*Save on "set" methods is enabled by default.*
*You can set it as "false", if make much changes in one moment.*
*Just disable that and use "save" method after your changes.**"strict" parameter used in "reload" method for throw Error, if JSON can not be parsed.*
## Future:
* onReload event
* onReloadError event
* Tests
* Benchmark