JSPM

mok-localstorage

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q27784F
  • License ISC

localStorage api's

Package Exports

  • mok-localstorage
  • mok-localstorage/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mok-localstorage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mok-localstorage

Ease use of Local Storage in JavaScript and it's libraries

Table of Contents

Features

  • Get Data Item From Local Storage
  • Set Data Item in Local Storage
  • Remove Data Item in Local Storage

Installing

npm i mok-localstorage

Example

Get Data

key will be string

 import {getLocalStorageItem} from 'mok-localstorage';

 const data = getLocalStorageItem(key)

Set Data

key will be string

data will be string or object type

import {setLocalStorageItem} from 'mok-localstorage';

 const data = setLocalStorageItem(key,data)

Remove Data

key will be string

import {removeLocalStorage} from 'mok-localstorage';

 const data = removeLocalStorage(key)

React Example

import {
  getLocalStorageItem,
  removeLocalStorage,
  setLocalStorageItem,
} from "mok-localstorage";

function App() {
    // persist is JSON object
  const persist = getLocalStorageItem("persist");

  // Get Data
  const token = getLocalStorageItem("token");
  const user = {
    userid: "8045dd77-f0aa-4245-b695-2575536c1b9d",
    username: "new user",
    useremail: "newuser@gmail.com",
  };

const access-token ="8045dd77-f0aa-4245-b695-2575536c1b9d"
  // Set Data
  setLocalStorageItem("user", user);
  setLocalStorageItem("access-token", access-token);


  // Remove Data
  removeLocalStorage("newdata");

  return (
    <h1>
      {token}
      {JSON.stringify(persist)}
    </h1>
  );
}

export default App;