1.1.1 • Public • Published

    Browser Storage Class

    NPM js-semistandard-style

    npm version Gitlab Pipeline Gitlab Coverage NPM download/month NPM download total
    A Browser Storage Class for NodeJS or Browser

    There are many library to handle local or session storage for browser out there. But many of them is too bloated for browser. Actually we just need a simple wrapper class, so your website still lightweight and running fast.

    Minimum Requirement

    • Tested with NodeJS v10.
    • All browsers with support ES5.

    Install using NPM

    $ npm install browser-storage-class

    Or simply use in Browser with CDN

    <!-- Always get the latest version -->
    <!-- Not recommended for production sites! -->
    <script src=""></script>
    <!-- Get minor updates and patch fixes within a major version -->
    <script src=""></script>
    <!-- Get patch fixes within a minor version -->
    <script src=""></script>
    <!-- Get a specific version -->
    <!-- Recommended for production sites! -->
    <script src=""></script>


    Local or Session Storage

    const BrowserStorageClass = require('browser-storage-class'); // in browser doesn't need this line
    // Example
    // Use LocalStorage
    var storage = new BrowserStorageClass(localStorage);
    // Use SessionStorage
    var storage = new BrowserStorageClass(sessionStorage);
    // If you want asynchronous
    // Note:
    // - All methods will return as promise.
    var storage = new BrowserStorageClass(localStorage, true);

    Save or add new value

    storage.set('yourkeyname1', 'Saving value as string');
    storage.set('yourkeyname2', ['saving', 'value', 'as', 'array']);
    storage.set('yourkeyname3', {name: 'budi', address: 'jakarta', info:'saving value as object'});


    • You are able to save tipe data value as string, array, and object.
    • You are able to use set to update the value.
      Because Key name is primary, it will automatically replace old value.

    Get value from key


    Check value is exist or not

    if(storage.has('yourkeyname1')) {
    } else {
        console.log('Not Found!');

    Remove single data


    Clear all data


    List all saved data



    • BrowserStorageClass(_typeStorage[, _promisify])
      _typeStorage {WindowLocalStorage} : localStorage or sessionStorage.
      _promisify {boolean} : If set to true, all methods will return as promise. Optional, default is false.

    • has(key)
      key {string} : Key name for your data value.
      returns {boolean}

    • set(key, value)
      key {string} : Key name for your data value.
      value {mixed} : Value can be string / array / object.

    • get(key)
      key {string} : Key name for your data value.
      returns {mixed} : Value can be string / array / object.

    • remove(key)
      key {string} : Key name for your data value.

    • clear()
      This will clear all data storage.

    • list()
      returns {array}

    This will show all saved data in storage.

    Unit Test

    If you want to playing around with test

    npm test


    npm i browser-storage-class

    DownloadsWeekly Downloads






    Unpacked Size

    23.7 kB

    Total Files


    Last publish


    • aalfiann