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 🙏

© 2025 – Pkg Stats / Ryan Hefner

easy-storage-manager

v1.0.3

Published

为storage提供一种集中化管理的方法、统一的API, 以及方便的扩展。

Readme

Easy storage manager

为storage提供一种集中化管理的方法、统一的API, 以及方便的扩展。

Feature

示例:

import generateStorageApi from 'easy-storage-manager';
const enterCount = generateStorageApi({
    engine: window.localStorage,
    space: 'myAppName',
    key: 'ENTER_COUNT',
    validate: 'number',
    defaultMaxAge: 24 * 60 * 60 * 1000, // MILLISECONDS_EACH_DAY
});
enterCount.set(1);

// extend a method inc for enterCount
enterCount.inc = function inc() {
  const count = this.get() || 0;
  this.set(count + 1);
};
enterCount.inc();
enterCount.inc();

small API

只有两个

generateStorageApi // => get set 
generateArrayStorageApi // => get set push pop update

different storage extend

  1. window.sessionStorage
  2. window.localStorage
engine: window.localStorage, // window.sessionStorage

validate

数据验证 more rules

如果项目已经引入prop-types, 可以选择prop-types的验证方式

const config = {
    validate: (data) => PropTypes.checkPropTypes({ 
            data: PropTypes.string, // validate
        },
        { data },
        'prop',
        'validate in storage'
    ),
    ...
}

space

避免键名冲突

defaultMaxAge

设置数据过期时间

const s = generateStorageApi({
  defaultMaxAge: 1000, // 1000 毫秒,默认为不过期
  ...
});

// 为某条数据单独设置过期时间
s.set('', 2000); // 2000 毫秒

Array Data

在本地需要存储搜索的历史纪录,涉及 get set push update 等操作.

// index.js
import { generateArrayStorageApi } from 'easy-storage-manager';

const Keys = {
    HISTORY_RECORD: 'HISTORY_RECORD',
}

const historyRecordStorage = generateArrayStorageApi({
    engine: window.localStorage,
    key: Keys.HISTORY_RECORD,
    validate: [{
        type: 'string',
        text: 'string',
    }]
    uniqueField: 'text',
});

const search = {
 type: 'keywords',
 text: '回龙观',
};

historyRecordStorage.set([ search ]);
const searches = historyRecordStorage.get();

// more API
historyRecordStorage.push({ type: 'keywords', text: '中关村' });

More

Why not prop-types, but data-validate

因为一开始只想简单的验证存入storage的数据, 但是通过不断的给validate添加功能, 我发现我要的就是一个prop-types >_<

Test

npm install mocha -g
npm run test  # or mocha

Publish

npm version [higher version]
npm publish