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
API
setItem
/**
* 设置本地存储
*
* @param {string} key - 键名
* @param {*} value - 键值
*/
localStorage.setItem('foo', { bar: 'bar' })
getItem
/**
* 获取本地存储
*
* @param {string} key - 键名
* @returns {*} 键值
*/
const value = localStorage.getItem('foo') // output: { bar: 'bar' }
Object.prototype.toString.call(value) // output: [object Object]
removeItem
/**
* 清除指定键名的本地存储
*
* @param {string} key - 键名
*/
localStorage.removeItem('foo')
clear
/** 清除所有的本地存储 */
localStorage.clear()
used
/**
* 查询已使用的存储容量
*
* @returns {string} 返回已使用的存储容量
*/
localStorage.used() // 0.000045%