Noiseless Peaceful Morning

    @yzfe/storage
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0-alpha.0 • Public • Published

    本地存储操作类

    用法

    import Storage from '@yzfe/storage'
    
    let storage = new Storage()
    // 设置 item
    storage.set('key', { name: 'Allenice' })
    
    // 获取 item
    storage.get('key', { name: '这是默认值' })
    
    // 删除 item
    storage.remove('key')
    
    // 全部清除
    storage.clear()
    
    // 作用域,也就是添加 key 前缀
    let storage2 = new Storage('myapp:')
    storage2.set('key', 1) // 相当于 localStorage.setItem('myapp:key', 1)
    
    // 使用 sessionStorage
    let session = new Storange('myapp:', 'session')

    API

    set(key: string, val: any): void

    设置 item

    get(key: string, defaultVal: T | null = null): T | null

    获取 item

    remove(key: string): void

    删除 Item

    clear(): void

    全部清除

    getFullKey(key: string = ''): string

    获取包含作用域前缀的 Key

    keys(): string[]

    返回作用域所有的 Key

    Keywords

    none

    Install

    npm i @yzfe/storage

    DownloadsWeekly Downloads

    15

    Version

    2.0.0-alpha.0

    License

    MIT

    Unpacked Size

    5.05 kB

    Total Files

    4

    Last publish

    Collaborators

    • allenice
    • allenmo
    • vfasky