0.6.0 • Published 5 years ago

json-store-promise v0.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

JSON Store Promise

Async local file storage with promises.

Usage

Promise

import { JsonStore } from 'json-store-promise';

JsonStore.create('./file.json').then(store => {
	// Use, may throw errors
	store.set('key', 'value');
	store.get('key');
	// Catch errors
	store.remove('key').catch(e => console.log(e));
});

async/await

import { JsonStore } from 'json-store-promise';

try {
	let store = await JsonStore.create('./file.json');

	await store.set('key', 'value')
	let value = await store.get('key')
	await store.remove('key')
} catch (Error e) {
	// Handle error
	console.log(e)
}

API

Create store object

JsonStore.create('file.json'): Promise<JsonStore>

Add value

store.set('key', 'value'): Promise<void>
  • .then(() => ...) no value, when saved to file
  • .catch(error => ...) file errors

Get value

store.get('key'): Promise<any>
  • .then(value => ...) the value
  • .catch(error => ...) no errors thrown

Remove value

store.set('key', 'value'): Promise<void>
  • .then(() => ...) no value, when saved to file
  • .catch(error => ...) file errors
0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago