Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshmerlino/filestore-json
Easily sync JSON objects of any shape with the filesystem.
https://github.com/joshmerlino/filestore-json
filestore filesystem json json-config npm persistant
Last synced: about 1 month ago
JSON representation
Easily sync JSON objects of any shape with the filesystem.
- Host: GitHub
- URL: https://github.com/joshmerlino/filestore-json
- Owner: JoshMerlino
- License: mit
- Created: 2021-05-28T18:22:03.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-21T12:11:17.000Z (4 months ago)
- Last Synced: 2024-10-21T17:47:18.414Z (4 months ago)
- Topics: filestore, filesystem, json, json-config, npm, persistant
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/filestore-json
- Size: 1.99 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filestore-json
### Checks
* [![Build](https://github.com/JoshMerlino/filestore-json/actions/workflows/build.yml/badge.svg)](https://github.com/JoshMerlino/filestore-json/actions/workflows/build.yml)
* [![Code Style Analysis](https://github.com/JoshMerlino/filestore-json/actions/workflows/code-style-analysis.yml/badge.svg)](https://github.com/JoshMerlino/filestore-json/actions/workflows/code-style-analysis.yml)
* [![Test CI](https://github.com/JoshMerlino/filestore-json/actions/workflows/test-ci.yml/badge.svg)](https://github.com/JoshMerlino/filestore-json/actions/workflows/test-ci.yml)![](https://img.shields.io/npm/dt/filestore-json)
![](https://img.shields.io/github/issues/JoshMerlino/filestore-json)
![](https://img.shields.io/github/issues-pr/JoshMerlino/filestore-json)Easily sync JSON objects of any shape with the filesystem.
# Features
* Read & write to JSON files on a storage device without the need to interact with the filesystem.
* Persistant data between process restarts.
* Ability to determine age (ms since last write).
* Cache JSON responses from network requests.
* Automaticly updates internal value when JSON file is modified.
* Strong type internal value with type annotations.# Examples
## Creating a store
```ts
import JSONStore from "filestore-json";
import path from "path";// Initialize the store.
const store = JSONStore.from(path.resolve("path/to/your/store.json"));// With types
type Type = Record;
const store = JSONStore.from(path.resolve("path/to/your/store.json"));
```## Reading & writing to the store
```ts
// Read value of store.
console.log(store.value); // -> {}// Update store value.
store.value = { myObject: false };// Read new value of store.
console.log(store.value); // -> { myObject: false }
```## Creating a store with default values
```ts
// Create object with store defaults
const defaults = { defaultValue: true };// Initialize store.
const store = JSONStore.from(path.resolve("path/to/your/store.json"), defaults);// Read value of store.
console.log(store.value); // -> { defaultValue: true }// Update store value.
store.value = { myObject: false };// Read new value of store.
console.log(store.value); // -> { myObject: false, defaultValue: true }
```## Resetting a stores value back to the default
```ts
// Update store value.
store.value = { myObject: false };// Read new value of store.
console.log(store.value); // -> { myObject: false }// Clear value
store.clear();// Read value of store.
console.log(store.value); // -> {}
```## Getting the age of the store (ms since last write)
```ts
// Read age of store.
console.log(store.age); // -> 0
```