@owneul/kocal-storage

localStorage Handler library

Usage no npm install needed!

<script type="module">
  import owneulKocalStorage from 'https://cdn.skypack.dev/@owneul/kocal-storage';
</script>

README

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

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

License

MIT