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

storagetify

v1.0.0

Published

Make the APIs of LocalStorage and SessionStorage easier

Downloads

9

Readme

storagetify

一个简单轻量级的对LocalStorage和SessionStorage的AP简单包装js插件(支持过期时间设置等)

特性:

使用

通过npm安装

$ npm install storagetify -D
import Storagetify from 'storagetify';

//实例化,以及默认参数
const storage = new Storagetify({
  type: 'local', //默认驱动是 localStorage
  expire: 0,//单位是秒
  prefix: '',//key的前缀
  serialize: JSON.stringify,//序列化
  deserialize: JSON.parse,//反序列化
})

storage.set('key', 'value', 3600)

或者使用cdn

<script src="https://unpkg.com/storagetify@latest/dist/storagetify.min.js"></script>
<!-- 或者 -->
<!-- <script src="https://cdn.jsdelivr.net/npm/storagetify@latest/dist/storagetify.min.js"></script> -->
<script type="text/javascript">
  const storage = new Storagetify({})
  storage.set('key', 'value', 3600)
</script>

API

设置缓存

//数组
storage.set('name', [1, 2, 4])
//数值
storage.set('name', 1)
//对象
storage.set('name', {name:'value1',name2:'value2'})
// 缓存在3600秒之后过期
storage.set('name', 'hello php!',3600)

缓存自增

针对数值类型的缓存数据,可以使用自增操作,例如:

storage.set('name', 1)
//name自增(步进值为1)
storage.inc('name')
//name自增(步进值为3)
storage.inc('name',3)

只能对数字类型数据进行自增和自减操作

缓存自减


//name自减(步进值为1)
storage.dec('name')
//name自减(步进值为3)
storage.dec('name',3)

获取缓存

storage.get('name')

如果name值不存在,则默认返回 null 支持指定默认值,例如

storage.get('name','')

表示如果name值不存在,则返回空字符串

追加缓存数据

如果缓存数据是一个数组,可以通过push方法追加一个数据

storage.set('name', [1,2,3]);
storage.push('name', 4);
storage.get('name'); // [1,2,3,4]

删除缓存

storage.delete('name')

获取并删除缓存

storage.pull('name')

如果name值不存在,则返回null

清空缓存

storage.clear()

该方法谨慎使用,它会一口气清除所有的缓存

不存在则写入缓存数据后返回

storage.remember('start_time', Date.now())

如果start_time缓存数据不存在,则会设置缓存数据为当前时间。

第二个参数可以使用函数

storage.remember('start_time',function(){
    return time()+1;
})

remember方法的第三个参数可以设置缓存的有效期

缓存标签

支持给缓存数据打标签,例如:

 storage.tag('tag').set('name1', 'value1')


// 清除tag标签的缓存数据
 storage.tag('tag').clear()

缓存标签不会改变缓存的读取操作,所以获取方式依然是:

storage.get('name1')

并支持同时指定多个缓存标签操作

storage.tag(['tag1', 'tag2']).set('name1', 'value1')

// 清除多个标签的缓存数据
storage.tag(['tag1', 'tag2']).clear()

可以追加某个缓存标识到标签

storage.tag('tag').append('name3')

获取标签的缓存标识列表

storage.getTagItems('tag')

切换缓存类型

// 默认使用localStorage缓存(初始化时指定的type类型)
storage.set('name','value',3600);
storage.get('name');

//切换到sessionStorage
storage.store('session').set('name','value',3600);
storage.store('session').get('name')

变更日志

每个版本的详细更改记录在CHANGELOG.md中.

贡献

在提出拉取请求之前,请务必阅读贡献指南

License

MIT

Copyright (c) 2024-present, ajiho