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
API
const { localStorage, sessionStorage } = typeStorage
// 设置
localStorage.setItem(key, value)
// 获取
localStorage.getItem(key)
// 移除
localStorage.removeItem(key)
// 清空
localStorage.clear()
// 容量
localStorage.capacity() // 0.000045%
npm下载
npm i type-storage-utils
使用
import { localStorage, sessionStorage } from 'type-storage-utils'
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]'
src下载
<script src="../dist/type-storage-utils.js"></script>
使用
const { localStorage, sessionStorage } = typeStorage
// ...