Socket
Socket
Sign inDemoInstall

storage-manager

Package Overview
Dependencies
3
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.9 to 1.1.0

0

.eslintrc.json

@@ -0,0 +0,0 @@ {

7

lib/StorageHelper.js

@@ -19,3 +19,3 @@ 'use strict';

set: function set(storageType, key, value, options, innerSet) {
if (!key || !value) {
if (key === undefined || key === null || value === undefined || value === null) {
throw new Error("StorageManager -> Can't set without a key or value");

@@ -27,3 +27,3 @@ }

window[storageType + 'Storage'].setItem(this.getTTLKey(storageType, key), (0, _stringify2.default)({ calculatedTTL: this.getCalculatedTTL(storageType, options), ttlOptions: options }));
return window[storageType + 'Storage'].setItem(key, (0, _stringify2.default)(value));
return window[storageType + 'Storage'].setItem(this.getTTLKey(storageType, key) + '__VALUE', (0, _stringify2.default)(value));
},

@@ -39,2 +39,3 @@ get: function get(storageType, key, innerGet) {

this.handleTTL(storageType, key);
key = this.getTTLKey(storageType, key) + '__VALUE';
}

@@ -49,3 +50,3 @@ var result = window[storageType + 'Storage'].getItem(key);

window[storageType + 'Storage'].removeItem(this.getTTLKey(storageType, key));
return window[storageType + 'Storage'].removeItem(key);
return window[storageType + 'Storage'].removeItem(this.getTTLKey(storageType, key) + '__VALUE');
},

@@ -52,0 +53,0 @@ clearAll: function clearAll(storageType) {

{
"name": "storage-manager",
"description": "Storage Manager module that help you manage your local and session storage",
"version": "1.0.9",
"version": "1.1.0",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "lib/index.js",

# storage-manager
Storage Manager module that help you manage your local and session storage
* Support TTL functionality
* Support TTL functionality ```{ minutes: 2 }```
* Support multiple values like ```{ minutes: 3, seconds: 30 }```

@@ -8,11 +9,49 @@ ## Installing

## Example usage
## Some examples
```js
/**
* Supported TTL values: { milliseconds, seconds, minutes, hours, days }
* You can use multiple values like { minutes: 3, seconds: 30 }
* SessionStorage works the same implementation as LocalStorage
* */
```
```js
import { LocalStorage } from 'storage-manager';
LocalStorage.set('some-key', 'some-value', { minutes: 2 })
LocalStorage.get('some-key') // it will refresh the TTL of this key to it's default value (2 minutes in that case)
const options = { minutes: 2 }
LocalStorage.set('forever-key', 'some-value') // it will save the key forever untill you will remove it manually
// this will update the ttl everytime you'll get the key
LocalStorage.set('some-key', 'some-value', options)
// it will refresh the TTL of this key to it's default value (2 minutes in that case)
LocalStorage.get('some-key')
```
```js
import { LocalStorage } from 'storage-manager';
// it will save the key forever untill you will remove it manually
LocalStorage.set('forever-key', 'some-value')
LocalStorage.remove('forever-key')
```
```js
import { LocalStorage } from 'storage-manager';
// refreshTTL is true by default.
// refreshTTL means that everytime you'll get this key, it will refresh his TTL to what it was before
const options = { minutes: 4, seconds: 30, refreshTTL: false }
LocalStorage.set('some-key', 'some-value', options)
// this will not update the ttl everytime you'll get the key
LocalStorage.get('some-key')
// it will NOT refresh the TTL of this key, this key will stay 4 minutes and 30 seconds
```
```js
import { LocalStorage } from 'storage-manager';
LocalStorage.clearAll() // clear all storage
```
const StorageHelper = {
set(storageType, key, value, options, innerSet) {
if (!key || !value) { throw new Error("StorageManager -> Can't set without a key or value") }
if (key === undefined || key === null || value === undefined || value === null) {
throw new Error("StorageManager -> Can't set without a key or value")
}
options = options || {}

@@ -8,3 +10,3 @@ innerSet = innerSet || false

window[`${storageType}Storage`].setItem(this.getTTLKey(storageType, key), JSON.stringify({ calculatedTTL: this.getCalculatedTTL(storageType, options), ttlOptions: options }))
return window[`${storageType}Storage`].setItem(key, JSON.stringify(value))
return window[`${storageType}Storage`].setItem(`${this.getTTLKey(storageType, key)}__VALUE`, JSON.stringify(value))
},

@@ -16,2 +18,3 @@ get(storageType, key, innerGet) {

this.handleTTL(storageType, key)
key = `${this.getTTLKey(storageType, key)}__VALUE`
}

@@ -26,3 +29,3 @@ let result = window[`${storageType}Storage`].getItem(key)

window[`${storageType}Storage`].removeItem(this.getTTLKey(storageType, key))
return window[`${storageType}Storage`].removeItem(key)
return window[`${storageType}Storage`].removeItem(`${this.getTTLKey(storageType, key)}__VALUE`)
},

@@ -88,2 +91,2 @@ clearAll(storageType) {

export default StorageHelper
export default StorageHelper

@@ -0,0 +0,0 @@ import test from 'ava'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc