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

easy-async-storage

v1.0.20

Published

easy-async-storage

Readme

easy-async-storage easy-async-storage Stars

1.简介

最初目的

在项目开发中,有少数情况会有在存入Storage的同时获取该storage的逻辑,如果存入数据的函数为异步函数(比如请求了一个用户信息的接口,特别是在登录后),这样的逻辑就会导致原生的getItem函数获取不到,easy-async-storage库将getItem变为异步函数,返回一个Promise对象,让你可以像调用一个网络请求一样去调用storage

目前已有功能

  • 使用面向对象思想对存储方式进行二次封装,让 Storage 操作能够更加简便快捷,不需要考虑某条数据存在于localStorage还是sessionStorage

TODO

  • 加密存取

2.Install

npm install easy-async-storage

3.Use

eStorage()的暴露方式类似Vue Composition API

const { keep, set, get, asyncGet, check } = eStorage();

const est = eStorage();

3.1 Get Storage

获取存储数据,调用对象的get方法,返回类型为Promise

est.get(key:string):Promise<any>;
est.get(key:string).then(res=>{
  // res即为获取到的value
}).catch(err=>{
  // 未获取到的操作
})

3.2 Async Get Storage

est.asyncGet(key:string,timeout?:number)

调用异步获取方法,参数如下

  1. key:string Storage 的 key,必传
  2. timeout:number 超时时间,若在超时时间到达后仍旧没有获取到值,则在reject中返回undefined,非必需,默认 1000(ms)

3.3 Set Storage

与原生存储方式相似,但是value参数强制使用string,存在类型检查,若不符合则抛出异常。

set()返回一个EStorage对象,支持链式调用

est.set(key: string, value: string);

3.4 Set Local Storage

easy-async-storage在使用set()方法时,底层默认操作对象为sessionStorage,如有对localStorage进行存储的需求,则可以使用keep()方法

keep()返回一个EStorage对象,支持链式调用

est.keep().set(key: string, value: string);

注意:您在进行getasyncGetcheck操作时,并不一定需要调用keep()

3.5 Check

查找当前存储中是否存在某一字段

使用:

est.check(key: string).then(res=>{
  // 存储存在的操作
}).catch(()=>{
  // 存储不存在的操作
});

返回的数据类型:

Promise<CheckResult>

interface CheckResult {
  status: boolean;
  target?: EStorage;
}
  • status:boolean 存在 true 不存在 false
  • target?:EStorage 存在返回一个EStorage对象,支持链式调用;不存在则没有该字段。