@itshkins/dom-utils
TypeScript icon, indicating that this package has built-in type declarations

1.1.20 • Public • Published

DOM utils

This package provides a set of DOM utilities.

  • One of them is a local state manager that simplifies the usage of Storage API:
const KEY = `my-key`
const storage = localStorage // or sessionStorage

const state = JSON.parse(storage.getItem(KEY))
storage.setItem(KEY, JSON.stringify({value: []}))

Installation

npm i @itshkins/dom-utils@latest

Usage

Node

import {newLocalState} from '@itshkins/dom-utils'

const DEFAULT_STATE = Object.freeze({})

const localState = newLocalState(`my-key`)
console.log(localState.getState(DEFAULT_STATE)) // {}
console.log(localState.setState({value: []})) // true
console.log(localState.getState(DEFAULT_STATE)) // {value: Array(0)}

Browser

<script src="./node_modules/@itshkins/dom-utils/dist/dom-utils.js"></script>

<script>
  const DEFAULT_STATE = Object.freeze({})

  const localState = domUtils.newLocalState(`my-key`)
  console.log(localState.getState(DEFAULT_STATE)) // {}
  console.log(localState.setState({value: []})) // true
  console.log(localState.getState(DEFAULT_STATE)) // {value: Array(0)}
</script>

/@itshkins/dom-utils/

    Package Sidebar

    Install

    npm i @itshkins/dom-utils

    Weekly Downloads

    2

    Version

    1.1.20

    License

    MIT

    Unpacked Size

    27.9 kB

    Total Files

    9

    Last publish

    Collaborators

    • itshkins