JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q35522F
  • License ISC

Web storage with type

Package Exports

  • type-storage-utils
  • type-storage-utils/dist/type-storage-utils.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 (type-storage-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

带类型的本地存储

支持string | number | boolean | null | undefined | array | object

下载

npm

npm i type-storage-utils

src

<script src="../dist/type-storage-utils.js"></script>

使用

// npm
import { localStorage, sessionStorage } from 'type-storage-utils'

// src
// const { localStorage, sessionStorage } = typeStorage

localStorage.setItem('string', 'I am a string.')
localStorage.setItem('object', { foo: 'foo' })

localStorage.getItem('string') // I am string
typeof localStorage.getItem('string') //  string

localStorage.getItem('object') // {foo: 'foo'}
Object.prototype.toString.call(localStorage.getItem('object')) // '[object Object]'

API

import { localStorage, sessionStorage } from 'type-storage-utils'
// const { localStorage, sessionStorage } = typeStorage

// 设置
localStorage.setItem(key, value)

// 获取
localStorage.getItem(key)

// 移除
localStorage.removeItem(key)

// 清空
localStorage.clear()

// 容量
localStorage.capacity() // 0.000045%