๐Ÿ“ฆ EasyStorage for ZeppOS (default class)

Description

EasyStorage offers lightweight, JSON storage solution designed for managing simple data structures efficiently. Ideal for small-scale applications or temporary data holding, it automates the persistence of changes to ensure data integrity. Your data is permanently stored on the device and will be restored next time the app is open. The whole database remains in RAM and filesystem.

To install the library run (from the root of your project)

npm i @silver-zepp/easy-storage

[ ๐Ÿ“ Download examples ]

[ ๐Ÿ“ Class Map ]

[ ๐Ÿ“ API Reference ]

[ โฌ…๏ธ Back to Index ]

Example

import { EasyStorage } from "@silver-zepp/easy-storage";
const storage = new EasyStorage();

storage.setKey("name", "John Doe");
console.log(storage.getKey("user")); // "John Doe"

๐Ÿ“ EasyStorage Class Map

๐Ÿ“ EasyStorage API Reference

setKey(key, value)

Sets a value for a specified key within the storage. If the key already exists, its value is updated.

Parameters

Examples

// set a simple value
storage.setKey('username', 'johnDoe');
// set an object
storage.setKey('user', { name: 'John', age: 30 });
// updating an existing key
storage.setKey('username', 'johnDoeUpdated');

Returns

void


getKey(key, defaultValue)

Retrieves the value associated with the specified key from the storage. If the key is not found, returns the default value if provided, or undefined.

Parameters

Examples

// retrieve an existing key
console.log(storage.getKey('username')); // "johnDoeUpdated"
// retrieve a non-existing key with a default value
console.log(storage.getKey('nonexistent', 'defaultUser')); // "defaultUser"

Returns

any - The value associated with the key, or the default value if the key doesn't exist.


hasKey(key)

Checks if the specified key exists in the storage.

Parameters

Examples

// check an existing key
console.log(storage.hasKey('username')); // true
// check a non-existing key
console.log(storage.hasKey('nonexistent')); // false

Returns

boolean - true if the key exists, false otherwise.


removeKey(key)

Removes the specified key and its associated value from the storage.

Parameters

Examples

// remove an existing key
storage.removeKey('username');

Returns

void


getAllKeys(stringify)

Returns all keys stored in the storage, optionally stringified.

Parameters

Examples

// get all keys as an array
console.log(storage.getAllKeys());
// get all keys as a JSON string
console.log(storage.getAllKeys(true));

Returns

string | array - The keys in the storage as a JSON string if stringify is true, or as an array if stringify is false.