1.0.1 • Published 6 years ago

@owneul/kocal-storage v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

KocalStorage

KocalStorage is Utility Library for localStorage.

NPM Version

Install

npm i @owneul/kocal-storage

Usage

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

methodargumentsdescription
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: anythingit works only when storaged item is array(or not exists)
pullItem(key)key: stringit pull item by key, and remove from localStorage
removeItem(key)key: stringsame to localStorage.removeItem
clear()same to localStorage.clear
getItem(key)key: stringreturn item from storage by key
setItem(key, item)key: string item: object, array, string, null, undefinedonly JSON.stringifiable data can be stored

License

MIT