Skip to content
Naira edited this page Jul 18, 2021 · 2 revisions

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.

Table of contents


Set

sets data to a given header. the data can be anything except a nested javascript object a normal one is fine.

Example

// 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']
  });

Get

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.

Example

// 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

Delete

Deletes a key or a header of no key is provided.

Example

// Deletes a key
jstore.delete('header', 'key');

// deletes a header
jstore.delete('header');

Clear

Clears all keys from a header. works on header classes as well.

Example

jstore.clear('header');

jstore.get('header').clear();

Push & Pop

Pushes or pops a value into an array. only works if the value of a key is an array.

Example

// 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');

Incr & Decr

Increments or decrements the value of a key if it is a number.

Example

// increases value of key by 50
jstore.incr('header', 'key', 50);

// decreases value of key by 50
jstore.decr('header', 'key' 50);

createHeader

Creates a header if it does not exist and returns it as an object.

Example

const header = jstore.createHeader('my header');

console.log(header.name); // Output: my header

headerExists

returns true if the provided header exists.

Example

jstore.headerExists('header');

keyExists

returns true if a provided key exists.

Example

jstore.keyExists('header', 'key');

Keys

Returns an array of keys from the working header.

Example

jstore.keys('header');

Values

Returns an array of values from the working header.

Example

jstore.values('header');

Headers

Returns an array of all headers from the working jstore file as classes. this is particularly useful for iterating over headers.

Example

// clears all headers in the working jstore file.
jstore.headers.forEach(header => header.clear());

Length

Returns the total amount of headers in the working jstore file

Example

jstore.headers

Entries

returns all the keys and values of a header as a JavaScript object. only works on header classes.

Example

const header = jstore.get('header');

console.log(header.entries.myKey);