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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@equalto/js-storage

v1.1.0

Published

js storage

Readme

js-storage

基于H5的localStorage/sessionStorage包装的一个缓存。实现了这些功能:

  • 基础功能 SimpleStorage
    • 单个操作 set/get/remove
    • 批量操作 keys/clear
  • 服务注册功能 RegisteredStorage
    • register/deregister/getPromise
    • registeredKeys()

不同的Storage之间通过不同的zone来相互隔离。

使用说明

SimpleStorage

普通的Map操作

import JsStorage from '@equalto/js-storage'
const storage = new JsStorage('simple')

const key = 'k1', value = 'v1'
storage.set(key, value)
storage.get(key) == value   // true 

storage.set(key, value, {
  expireAfter: 100   // 缓存有效期100毫秒 
})
storage.get(key) == value  // true
setTimeout(() => storage.get(key) == value, 200)  // false,缓存200毫秒超时了

RegisteredStorage

数据的使用者不应该关心数据的获取方式和缓存策略。 我们应该把数据做成服务,对于调用者来说是傻瓜式的。

因此有了数据服务注册的概念

范例 —— 注册数据服务

sys-data.ts

import JsStorage from '@equalto/js-storage'
import fetch from "node-fetch"   // 非web环境,使用 node-fetch@2 来模拟fetch函数 

const storage = new JsStorage('sys-data')

storage.register(
  'countries', 
  () => fetch(`https://restcountries.com/v3.1/all?fields=name`)
      .then(resp => resp.json()),
  { expireAfter: 3600 * 1000 * 24 * 365 }
)

export default storage

调用代码 using-sys-data.ts

import SysData from './sys-data'

SysData.get2('countries')  // 返回一个Promise

范例 —— 做一个特定的数据服务

或者做一个更加干净的数据服务: countries.ts

import JsStorage from '@equalto/js-storage'
import fetch from "node-fetch"   // 非web环境,使用 node-fetch@2 来模拟fetch函数 

const storage = new JsStorage('sys-countries')

const getCountries = storage.register(
  'countries', 
  () => fetch(`https://restcountries.com/v3.1/all?fields=name`)
      .then(resp => resp.json()),
  { expireAfter: 3600 * 1000 * 24 * 365 }
)

export default getCountries

使用服务的范例代码:using-countries.ts

import getCountries from './countries'

getCountries()  // 返回一个promise

安装

npm install @equalto/js-storage

API 参考

JsStorage 构造函数

new JsStorage(zone?: string, engine?: Storage)

SetOpts

interface SetOpts {
  expireAt?: number      // 指定时间戳过期
  expireAfter?: number   // 毫秒数后过期
  expireFn?: () => SetOpts // 动态过期函数
}

RegisterOpts

interface RegisterOpts extends SetOpts {
  initNow?: boolean      // 注册后立即执行
}

许可证

MIT