npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bt-storage

v0.1.0

Published

<h1 align="center">Welcome to better-storage 👋</h1> <p> <a href="https://www.npmjs.com/package/bt-storage" target="_blank"> <img alt="Version" src="https://img.shields.io/npm/v/bt-storage.svg"> </a> <a href="#" target="_blank"> <img alt="Li

Downloads

1

Readme

安装

npm install bt-storage

示例

import BetterStorage from "bt-storage";

const stg = new BetterStorage({
  storage: localStorage,         // localStorage or sessionStorage
  prefix: 'BIU',
  expires: 0,
  secret: false,
  AES: {
    secret: '30D17839695CB24C',    // AES secret key
    iv: '8BCAB84D2148034C'         // AES IV
  },
})

stg.set('test', 'some value', {
  expires: 1000, // 1秒后过期
  secret: true,  // 加密存储
})

参数说明

instanceConfig:

| 属性 | 说明 | 类型 | 是否必填 | 默认值 | | -------- | ----- | ---- | ---- | ---- | | storage | storage类型,为localStorage或sessionStorage | Storage | 是 | -- | | prefix | 存储的key的前缀| string | 是 | -- | | expires | 存储持续时间,为0则不过期 | number | 否 | 0 | | secret | 存储时是否加密 | boolean | 否 | false | | AES.secret | 加密存储时的AES secret key,为8n位的16进制字符 | string | 否 | 30D17839695CB24C | | AES.iv | 加密存储时的AES IV,为8n位的16进制字符 | string | 否 | 8BCAB84D2148034C |

setConfig:

| 属性 | 说明 | 类型 | 是否必填 | 默认值 | | -------- | ----- | ---- | ---- | ---- | | expires | 存储持续时间,为0则不过期 | number | 否 | 取自instance config | | secret | 存储时是否加密 | boolean | 否 | 取自instance config |

storageValue:

| 属性 | 说明 | 类型 | | -------- | ----- | ---- | | expires | 过期的时间戳 | number | | secret | 是否被加密 | boolean | | value | 被存储的数据 | any | | signature | 签名,用于读取时校验数据是否被更改 | string |

API

创建实例

constructor(options: instanceConfig): storageInstance

const stg = new BetterStorage({
  storage: localStorage,
  prefix: 'BIU',
  expires: 0,
  secret: false,
  AES: {
    secret: '01234567',
    iv: '0123456789abcdef'
  },
})

set(key: string, value: any, config: setConfig): void

向storage中存数据

stg.set('hello', 'world')

/* 存储结果
'@BIU/hello'
{
  "secret":false,
  "value":"world",
  "expires":0,
  "signature":"8E162389DE1AB8B27CB8D41C17AC94AD08721FC7"
}
*/

stg.set('hello', 'world', {
  secret: true,
  expires: 2000,
})

/* 存储结果
'@BIU/hello'
{
  "secret":true,
  "value":"e1FcAN/aPkJR/dCAWIl10Q==",
  "expires":1573025822648,
  "signature":"1A867EFC666516B7B0E7CC4552EFA969106A907F"
}
*/

get(key: string): any

从storage中取数据,未取到时返回null

const result = stg.get('hello') // "world"

remove(key: string): void

从storage中移除相应数据

stg.remove('hello')

stg.get('hello') // null

clear(): void

移除所有由该实例存入的数据

localStorage.setItem('hi', 'hi from origin');
stg.set('hi', 'hi from stg');
stg.set('hello', 'hello from stg');

localStorage.getItem('hi') // "hi from origin"
stg.get('hi') // "hi from stg"
stg.get('hello') // "hello from stg"

stg.clear();
localStorage.getItem('hi') // "hi from origin"
stg.get('hi') // null
stg.get('hello') // null

readable(): void

允许调用Api get

unreadable(): void

禁止调用Api get

stg.get('hello') // "world"

stg.unreadable()
stg.get('hello') // Error: this storage is unreadable for now!

keys: string[]

stg.set('a', 1)
stg.set('b', 1)
stg.set('c', 1)

console.log(stg.keys) // ["a", "b", "c"]

length: number

stg.set('a', 1)
stg.set('b', 1)
stg.set('c', 1)

console.log(stg.length) // 3

Author

👤 render