storage-manager-ts
A storage manager that supports storage managing with local and Redis storages
Last updated a month ago by danitseitlin .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install storage-manager-ts 
SYNC missed versions from official npm registry.

storage-manager-ts

A storage manager that supports storage managing in local-storage and redis

Initialize your storage manager:

import { LocalStorage } from 'storage-manager-ts';
const storage = new LocalStorage();

Get a key:

const keyAsString = storage.get('myKey', false);

//by default the response is in json form
const keyAsJson = storage.get('myKey');

//or you could give it a true value
const keyAsJson2 = storage.get('myKey', true);

Set a key:

The value type is any and that means you have the flexibily to set any value you want!

//Set a key with string as value
storage.set('myKey', 'myValue');

//Set a key with number as value
storage.set('myKey', 5);

//Set a key with JSON as value
storage.set('myKey', { 'arg1': 'value1' });

Remove a key:

//Removing the key from the storage
storage.remove('myKey');

Filtering keys by regex:

storage.set('myKey1', '1');
storage.set('myKey2', '2');
storage.set('myKey3', '3');
//use * to mention a start of the key
//Getting all of the key names starting with 'myKey'
const keys: string[] = storage.filterKeys({start: 'myKey'});

Getting key values by list:

storage.set('myKey1', '1');
storage.set('myKey2', '2');
storage.set('myKey3', '3');
//Getting all of the key names starting with 'myKey'
const keys: string[] = storage.filterKeys({start: 'myKey'});
//Getting all of their values
const values: any[] = storage.getKeysByList(keys);

Comparing keys by regex:

storage.set('myKey1', '1');
storage.set('myBoy', 'yay');
//Getting all of the key names starting with 'my'
const keys: string[] = storage.filterKeys({ start: 'my'});
const regex: string = '*myKey';
//printing all of the comparisons of the keys to the second regex 
for(let i = 0; i < keys.length; i++) {
    //checking which keys starting with 'my' also start with 'myKey'
    const comparison: boolean = storage.compareKeys({start: 'myKey'}, keys[i]);
    console.log(`key ${keys[i]} comparison for regex {start: 'myKey'} is ${comparison}`);
}

Unit testing

Current Tags

  • 1.0.2                                ...           latest (a month ago)

11 Versions

  • 1.0.2                                ...           a month ago
  • 1.0.1                                ...           a month ago
  • 0.0.9                                ...           2 months ago
  • 0.0.8                                ...           2 months ago
  • 0.0.7                                ...           2 months ago
  • 0.0.6                                ...           2 months ago
  • 0.0.5                                ...           3 months ago
  • 0.0.4                                ...           3 months ago
  • 0.0.3                                ...           3 months ago
  • 0.0.2                                ...           3 months ago
  • 0.0.1                                ...           3 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 11
Dependencies (1)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |