1.0.1 • Published 7 years ago
@owneul/kocal-storage v1.0.1
KocalStorage
KocalStorage is Utility Library for localStorage.
Install
npm i @owneul/kocal-storageUsage
KocalStorage.setItem('k-Array', ['red', 'orange', 'pink']);
console.log(KocalStorage.getItem('k-Array')); // ['red', 'orange', 'pink']
KocalStorage.let('k-NotCalled', function (__item) {
console.log('Hello, KocalStorage!'); // it will not appeared because 'k-NotCalled' not exists in localStorage.
});
KocalStorage.let('k-Called', function (__item) {
console.log('Hello, Forced KocalStorage!'); // it will appeared because 'k-Called' not exists in localStorage but forcedCallback is true.
}, true);API
| method | arguments | description |
|---|---|---|
| let(key, callback(item, key, isForcedCallback), isForcedCallback) | key: string / storage key callback: function / callback. basically, it called when item is not null and not undefined isForcedCallback: run callback function if item is null or undefined | |
| pushItem(key, item) | key: string item: anything | it works only when storaged item is array(or not exists) |
| pullItem(key) | key: string | it pull item by key, and remove from localStorage |
| removeItem(key) | key: string | same to localStorage.removeItem |
| clear() | same to localStorage.clear | |
| getItem(key) | key: string | return item from storage by key |
| setItem(key, item) | key: string item: object, array, string, null, undefined | only JSON.stringifiable data can be stored |