1.1.20 • Published 2 years ago

@itshkins/dom-utils v1.1.20

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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>
1.1.20

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago