-
Notifications
You must be signed in to change notification settings - Fork 0
API
Jstore commands were made to mimic a key value databases api so if you've ever used one you can figure out how to use them fairly easily.
- Set
- Get
- Delete
- Clear
- Push & Pop
- Incr & Decr
- createHeader
- headerExists
- keyExists
- Keys
- Values
- Headers
- Length
- Entries
sets data to a given header. the data can be anything except a nested javascript object a normal one is fine.
// setting a string to the key header
jstore.set('header', 'key', 'value');
// uniformly setting data using an object.
jstore.set('header', {
key: 'value',
bool: true,
number: 42,
array: ['e0', 'e1, 'e2', 'e3']
});
Gets data from a provided header and key. if no key is provided then it will get the header as a class that has most of the normal jstore commands.
// getting a key from a header
jstore.get('header', 'key');
// getting a header as an object.
const header = jstore.get('header');
header.set('key', 'value);
console.log(header.get('key'); // Output: value
Deletes a key or a header of no key is provided.
// Deletes a key
jstore.delete('header', 'key');
// deletes a header
jstore.delete('header');
Clears all keys from a header. works on header classes as well.
jstore.clear('header');
jstore.get('header').clear();
Pushes or pops a value into an array. only works if the value of a key is an array.
// pushes a value to the end of the array
jstore.push('header', 'key', 'value to push');
// removes the last element of an array
jstore.pop('header', 'key', 'value to pop');
Increments or decrements the value of a key if it is a number.
// increases value of key by 50
jstore.incr('header', 'key', 50);
// decreases value of key by 50
jstore.decr('header', 'key' 50);
Creates a header if it does not exist and returns it as an object.
const header = jstore.createHeader('my header');
console.log(header.name); // Output: my header
returns true if the provided header exists.
jstore.headerExists('header');
returns true if a provided key exists.
jstore.keyExists('header', 'key');
Returns an array of keys from the working header.
jstore.keys('header');
Returns an array of values from the working header.
jstore.values('header');
Returns an array of all headers from the working jstore file as classes. this is particularly useful for iterating over headers.
// clears all headers in the working jstore file.
jstore.headers.forEach(header => header.clear());
Returns the total amount of headers in the working jstore file
jstore.headers
returns all the keys and values of a header as a JavaScript object. only works on header classes.
const header = jstore.get('header');
console.log(header.entries.myKey);