Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
A function to manipulate browser storages, v2023.3.19 is ready on NPM
License
sametcelikbicak/storage-function
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A function to manipulate browser storages. Such as store a key value pair to session or local storage, getting key value pairs from local or session storage.You can check all available functions for more details.
- Installation
- Breaking Change
- Usage
- Local Storage functions
- Session Storage functions
- Storage functions
- Contribute
npm i storage-function
Before2.0.0 version each function should be import itself like below
import{toLocalStorage,toSessionStorage}from'storage-function';
or import them with an alias like below
import*asstorageFunctionfrom'storage-function';
With2.0.0 version its enough to just importstorageFunction then you can reach all helpful function under it like below.
import{storageFunction}from'storage-function';
Sample key and value definition for testing local storage functions.
constlocalStorageKey='local_storage_key';constlocalStorageValue={name:'object value',stringValue:'string value',booleanValue:true,numberValue:1234567890,dateValue:newDate(),};
import{storageFunction}from'storage-function';storageFunction.toLocalStorage(localStorageKey,localStorageValue);
import{storageFunction}from'storage-function';console.log(storageFunction.fromLocalStorage(localStorageKey));Result:{"name":"object value","stringValue":"string value","booleanValue":true,"numberValue":1234567890,"dateValue":"2021-08-22T15:57:05.147Z"}
import{storageFunction}from'storage-function';storageFunction.removeFromLocalStorage(localStorageKey);
import{storageFunction}from'storage-function';storageFunction.clearLocalStorage();// Remove all local storage keysconstexceptedKeys=['some_key','another_key'];storageFunction.clearLocalStorage(exceptedKeys);// Remove all local storage keys except exceptedKeys
import{storageFunction}from'storage-function';console.log(storageFunction.getKeysFromLocalStorage());Result:(2)["localKey2","localKey1"]0:"localKey2"1:"localKey1"
import{storageFunction}from'storage-function';console.log(storageFunction.getAllFromLocalStorage());Result:(2)[{…},{…}]0:{localKey2:"\"Local storage value 2\""}1:{localKey1:"\"Local storage value 1\""}
import{storageFunction}from'storage-function';storageFunction.toLocalStorage(localStorageKey,localStorageValue);console.log(storageFunction.getKeysCountFromLocalStorage());Result:1
Sample key and value definition for testing session storage functions.
constsessionStorageKey='session_storage_key';constsessionStorageValue={name:'object value',stringValue:'string value',booleanValue:true,numberValue:1234567890,dateValue:newDate(),};
import{storageFunction}from'storage-function';storageFunction.toSessionStorage(sessionStorageKey,sessionStorageValue);
import{storageFunction}from'storage-function';console.log(storageFunction.fromSessionStorage(sessionStorageKey));Result:{"name":"object value","stringValue":"string value","booleanValue":true,"numberValue":1234567890,"dateValue":"2021-08-22T15:58:28.646Z"}
import{storageFunction}from'storage-function';storageFunction.removeFromSessionStorage(sessionStorageKey);
import{storageFunction}from'storage-function';storageFunction.clearSessionStorage();// Remove all session storage keysconstexceptedKeys=['key_one','keyTwo'];storageFunction.clearSessionStorage(exceptedKeys);// Remove all session storage keys except exceptedKeys
import{storageFunction}from'storage-function';console.log(storageFunction.getKeysFromSessionStorage());Result:(2)["sessionKey2","sessionKey1"]0:"sessionKey2"1:"sessionKey1"
import{storageFunction}from'storage-function';console.log(storageFunction.getAllFromSessionStorage());Result:(2)[{…},{…}]0:{sessionKey2:"\"Session storage value 2\""}1:{sessionKey1:"\"Session storage value 1\""}
import{storageFunction}from'storage-function';storageFunction.toSessionStorage(sessionStorageKey,sessionStorageValue);console.log(storageFunction.getKeysCountFromSessionStorage());Result:1
They work with local and session storage.
import{storageFunction}from'storage-function';storageFunction.clearStorage();// Remove all storage keysconstexceptedKeys=['id_token','access_token'];storageFunction.clearStorage(exceptedKeys);// Remove all storage keys except exceptedKeys
import{storageFunction}from'storage-function';console.log(storageFunction.getKeys());Result:{localStorage:Array(2),sessionStorage:Array(2)}localStorage:(2)["localKey2","localKey1"]sessionStorage:(2)["sessionKey2","sessionKey1"]
import{storageFunction}from'storage-function';console.log(storageFunction.getAll());Result:{localStorage:Array(2),sessionStorage:Array(2)}localStorage:Array(2)0:{localKey2:"\"Local storage value 2\""}1:{localKey1:"\"Local storage value 1\""}sessionStorage:Array(2)0:{sessionKey2:"\"Session storage value 2\""}1:{sessionKey1:"\"Session storage value 1\""}
import{storageFunction}from'storage-function';storageFunction.toLocalStorage(localStorageKey,localStorageValue);storageFunction.toSessionStorage(sessionStorageKey,sessionStorageValue);console.log(storageFunction.getKeysCount());Result:{localStorage:1,sessionStorage:1}
You can read and follow ourCONTRIBUTING.md and report it usingGitHub Issues! for reporting bugs, suggesting enhancements, bugfixes, new features and extras are welcome.
Thanks goes to these wonderful people (emoji key):
Samet ÇELİKBIÇAK 🚇💻🐛📖💡🚧 |
This project follows theall-contributors specification. Contributions of any kind welcome!
About
A function to manipulate browser storages, v2023.3.19 is ready on NPM
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.