New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

hd-localstorage

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hd-localstorage

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

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

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, // 设置的获取次数限制
}

Keywords

localStorage

FAQs

Package last updated on 16 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts