New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

storage-manager-ts

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storage-manager-ts

A storage manager that supports storage managing with local and Redis storages

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by116.67%
Maintainers
1
Weekly downloads
 
Created
Source

storage-manager-ts

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

Local Storage

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.delete('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

Keywords

FAQs

Package last updated on 20 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc