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

store-gem.js

v2.0.7

Published

最全webStorage封装库-支持cookie解决方案

Readme

#store-gem.js

本地存储localstorage/sessionstorage的封装,cookie完美解决方案.

安装

npm

$ npm install store-gem.js --save

导入

import store from 'store-gem.js';		// ES6 导入
var store = require('store-gem.js');	// CommonJS规范导入

本地存储APIs

var myStore = new store()			//可选参数:sessionStorage和localStorage 默认localStorageq
myStore.set(key, data,timeouts);	//单个存储字符串数据 timeouts 为过期时间
myStore.set({key: data, key2: data2},timeouts);	//批量存储多个字符串数据
myStore.get(key);               	//获取key的字符串数据
myStore.get();                  	//获取所有key/data
myStore.get(key1,key2,key3);    	//获取对应{key: data, key2: data2,key3:data3}对象
myStore.has(key)					//判断key是否存在
myStore.keys()						//返回所有key的数组
myStore.remove(key)					//删除key/data
myStore.remove(key1,key2)			//删除key1/data1,key2/data2
myStore.clear()						//清空所有key/data
myStore.clearExpires()				//删除缓存中所有超时值
myStore.setTimeout(key,timeouts)	//根据key为已存在的(未超时的)缓存值以当前时间为基准设置新的超时时间。
myStore.add(key, data, timeouts)	//根据key做插入操作,如果key对应的值不存在或者已超时则插入该值,反之什么都不做。
myStore.replace(key,data,timeouts)	//根据key做插入操作,如果key对应的值存在并且未超时则插入该值,反之什么都不做
myStore.each(callback);         	//循环遍历,返回false结束遍历
myStore.length()					//返回缓存中key的数量

###Constructor 实例化store

var myStore = new store('localStorage'// [可选] 'localStorage', 'sessionStorage', 默认 'localStorage')

set

向缓存中插入一条或多条数据

插入单条myStore.set(key, data,timeouts); //key [必填]必须要为String类型 data [必填] 支持所有类型 //timeouts [选填] 支持Number和Date类型 Number类型单位为秒数 //默认为 new Date('Fri Dec 31 9999 00:00:00 GMT+0800')
插入多条myStore.set({key: data, key2: data2},timeouts);//过期时间相同

myStore.set('a0','name1',200)   					//a0 ⇒  name1 过期时间200秒后
myStore.set('a1','name2')     						//a1 ⇒  name2 过期时间无限大
myStore.set({'a4':'string',a5:['array1',2]},50);
//存储两条字符串数据
//	a4⇒'string' 过期时间50秒后
//  a5⇒['array1',2]过期时间50秒后

get

获取key的字符串数据

myStore.get()无参数为获取全部key/data 返回Object对象 myStore.get(key)返回对应data myStore.get(key1,key2)返回Object {key1: data1, key2: data2}

console.log(myStore.get());    		//⇒Object {a0: 'name1', a1: 'name2', a4: 'string', a5: ['array1',2]}
console.log(myStore.get('a0'));    	//⇒name1
console.log(myStore.get('a0','a3'));//⇒Object {a0: 'name1', a3: 3}

clear

清空所有key/data
myStore.clear()

myStore.clear()

remove

删除key包括key的字符串数据 myStore.remove(key) myStore.remove(key1,key2)

myStore.remove("a0"); //删除a0
myStore.remove("a1","a2"); //删除a1,a2

keys

返回所有key的数组
myStore.keys()

myStore.keys() //⇒["a3", "a4", "a5"]

search

搜索所有key中包含string的key/data 返回object对象

搜索方法 myStore.search(string)

myStore.search('key') //⇒ {"key":"keytest","key1":{"a":1},"keyaev":"fff"}

has

判断是否存在返回true/false
myStore.has(key)

myStore.has("a3"); //⇒true

each

循环遍历,返回false结束遍历

myStore.each(function(key,data){
    console.log(key,data)
    if (key== 3) return false
})

clearExpires

删除缓存中所有通过WebStorageCache存储的超时值

myStore.clearExpires();

###setTimeout 根据key为已存在的(未超时的)缓存值以当前时间为基准设置新的超时时间。设置成功返回true失败返回false。

myStore.setTimeout(key,timeouts);

myStore.setTimeout("a0",500)//设置过期时间为500秒后

###add 根据key做插入操作,如果key对应的值不存在或者已超时则插入该值,反之什么都不做。插入成功返回true失败返回false。

myStore.add();

###replace 根据key做替换操作,如果key对应的值存在并且未超时则替换该值,反之什么都不做。替换成功返回true失败返回false。

myStore.replace();

链式书写

myStore.remove('a0','a2').clear().set('a0','name1',200).set('a1','name2').get('a1')

兼容

来源:sessionStorage localStorage

| 特性 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit)| iPhone(IOS) | Android | Opera Mobile | Window Phone | | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | |localStorage|4+|3.5+| 8+ |10.50+|4+| 3.2+ | 2.1+ | 11+ | 8+ | |sessionStorage|5+|2+| 8+ |10.50+|4+| 3.2+ | 2.1+ | 11+ | 8+ |

本地存储大小

JSON.stringify(localStorage).length 当前占用多大容量

检测localstore容量上限