Simple local storage tools.
const { setOneWithTTL, getOneWithTTL } = require('local-js');
const key = 'your_key';
const data = [ 'your', 'data' ];
const ttl = 3000;
setOneWithTTL(key, data, ttl); // Sets data with an expiry time
const item = getOneWithTTL(key);
console.log(item) // [ 'your', 'data '];
const { setOne } = require('local-js');
const key = 'your_key';
const data = [ 'your', 'data' ];
setOne(key, data);
const { getOne } = require('local-js');
const key = 'your_key';
getOne(key); // Returns data if key exists, null if it doesnt.
const { setOneWithTTL } = require('local-js');
const key = 'your_key';
const data = [ 'your', 'data' ];
const ttl = 3000;
setOneWithTTL(key, data, ttl);
Info: Get a single item with an expiry time, if the token is expired it will be removed and return null
.
const { getOneWithTTL } = require('local-js');
const key = 'your_key';
getOneWithTTL(key); // Return data if key exists and isnt expired, else return null
const { setMany } = require('local-js');
const array = [
{ key: 'first_key', value: 'first_value' },
{ key: 'second_key', value: [ 'second', 'value' ]},
...
];
setMany(array);
const { getMany } = require('local-js');
const array = [ 'first_key', 'second_key', ...];
getMany(array); // [ 'first_value', [ 'second', 'value' ], ...];
Info: Sets many items into localStorage with ttl, array of objects containing the keys, key
, value
, ttl
.
const { setManyWithTTL } = require('local-js');
const array = [
{ key: 'first_key', value: 'first_value', ttl: 1000 },
{ key: 'second_key', value: [ 'second', 'value' ], ttl: 2000 },
...
];
setManyWithTTL(array);
Info: Gets many items into localStorage with ttl, if the item is expired or does not exist it will be returned as null.
const { getManyWithTTL } = require('local-js');
const array = [ 'first_key', 'second_key', ...];
getManyWithTTL(array); // [ 'first_value', [ 'second', 'value' ], ...];
const { deleteOne } = require('local-js');
const key = 'my_key';
deleteOne(key);
const { deleteAll } = require('local-js');
deleteAll();
const { pruneExpired } = require('local-js');
pruneExpired();
const { getAll } = require('local-js');
getAll(); // [ { key: 'your_key', data: [ 'your', 'data' ] }, ...];