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

hd-localstorage

v1.2.0

Published

支持设置访问频率的本地存储

Downloads

4

Readme

localStorage带有使用频率限制的本地存储

1、存储的数据,带有获取次数记录。常用语运营位展示 n天n次 的业务需求。
2、存储格式支持对象,数组,字符串,number等类型
3、只针对业务中经常使用的场景,代码简单,代码量少

使用过程

npm install --save hd-localstorage 或 yarn add hd-localstorage

import Frequency from "hd-localstorage" ;

使用方法介绍

提供了2种常用的方法:get() ,set(). new Frequency(options)  ---  options配置实例默认值,选填参数 day:2  ---  配置数据过期时间,单位,天。默认无限大 frequency: 3  ---  配置数据最大请求次数,单位,次。默认无限大

let frequency = new Frequency({
      day: 2,           // 设置默认几天几次,如果不设置,则默认无数天,无数次
      frequency: 3
})

1、set()存入操作

方法:set(name, value, params) 参数1:name => 存储的key值 参数2:value => 存储的value值,默认取name值 参数3: options{ day: 几天, frequency: 几次 } => day: 单位,天,支持浮点数 frequency: 单位,次,不支持浮点数 nowFrequency: 单位,次,不支持浮点数。当前获取次数,不填,默认为0

frequency.set('name') 
frequency.set('name', '张三') 
frequency.set('name', '张三',{ day: 1, frequency: 1, nowFrequency: 1 }) //设置一天内只允许获取一次, 并且当前获取次数为1

2、对get()的获取操作

方法:get(name) 参数1:name => 存储的key值

frequency.get("name") ;

返回值:object || null 注:如果没有存储过,或者存储过期,则返回 null,存储值存在并且在有效期范围内,则返回对象

{
      value: "张三" ,   // 存储的value值
      isSafety: true ,  // 当前获取次数是否在安全值范围内
      nowNumber: 1, // 当前获取次数值
      maxNumber: 3, // 设置的获取次数限制
}