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

storage.js_chping

v1.0.2

Published

本地储存Storage的封装,提供简单API

Downloads

5

Readme

Storage.js

GitHub issues GitHub forks GitHub stars

本地存储Storage的封装,提供方便的API

下载

NPM

$ npm install storejs

Git

  • Fork到你的Git仓库,然后检出到你本地即可。

ZIP

使用

<script type="text/javascript" src="scripts/Storage.js"></script>
<script>
	storage('session','test','123');
</script>

or

	var storage = require('Storage.js');
	storage.getOrSetStorage('session','test','123');

本地存储APIs

storage(type,key,value)

	/**
	 * 添加、修改、获取指定的Storage中的数据
	 * @param type[String](session/local)  指定要存储的Storage类型
	 * @param key[String]                  待添加、修改、获取的Storage的key值
	 * @param value[all Type]              待添加、修改的Storage的value值,缺省时为获取数据
	 * @return [Boolean/value]             type类型错误、添加、修改返回Boolean,获取返回value值或null
	 **/
	storage(type,key,value)

	eg:
		storage('session','test','123');

说明

  1. type:指定Stroage的类型为sessionStorage/localStorage时出入“session”/"local",其他输入返回false。
  2. key:只能为String类型,其他输入返回false。
  3. value:传入null或undefined的时,返回null。

storage(type).length

	 /**
	 * 获取Storage中数据的容量
	 * @param type[String](session/local)  指定要获取容量的Storage类型
	 * @return [Number]                    返回容量大小
	 * */
	 storage(type).length
	eg:
		storage('session').length;

storage.remove(type,key)

	 /**
	 * 删除一个或清空Storage中的数据
	 * @param type[String](session/local)  指定要删除或者清空的Storage类型
	 * @param key[String]                  待删除的Storage的key值,缺省时为清空所有Storage
	 * @return [Boolean]
	 * */
	 storage.remove(type,key)
	eg:
		storage.remove('session','test');

说明

删除不会有任何提示,删除时请注意,或者你可以在原方法中添加你需要的返回信息。

storage.set(type,obj)

	 /**
	 * 添加多条数据到Storage
	 * @param type[String](session/local)  指定要添加的Storage类型
	 * @param obj[JSON格式]                待添加的JSON格式数据
	 * @return [Boolean]
	 * */
	 storage.set(type,obj)
	eg:
		storage.set('session',{"a",123,"b":true});

说明

  • obj必须为json格式的数据,如果仅想添加一条数据建议使用storage()方法。

storage.get(type,obj)

	 /**
	 * 获取多条数据
	 * @param type[String](session/local)  指定要获取的Storage类型
	 * @param obj[Array]                   待获取的数据名称数组
	 * @return [Object]                    返回JSON格式数组或者null
	 * */
	 storage.get(type,obj)
	eg:
		storage.get('session',["a","b"]);

说明

  • obj数组每一项必须为String类型的key。
  • obj也可以为String类型,表示获取单个Storage数据,功能同storage(type,key);

storage.has(type,key)

	 /**
	 * 判断指定Storage有无指定值
	 * @param type[String](session/local)  指定要获取的Storage类型
	 * @param key[String]                  待判断数据的key
	 * @return [Boolean]                    
	 * */
	 storage.has(type,obj)
	eg:
		storage.has('session','a');