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

js-storages

v1.1.0

Published

html5、localStorage、sessionStorage...

Downloads

8

Readme

js-storages

node version Build Status js-storages npm version js-storages weekly download

js-storages是一个封装了localStoragesessionStorageCookie对象的方法的JavaScript库。使用js-storages你可以简单、方便的对本地存储进行操作。

安装

npm install js-storages --save-dev
yarn add js-storages

使用

import storages from 'js-storages'

storages.JSLocalStorage.set('key', 'value')
storages.JSLocalStorage.get('key')

storages.JSSessionStorage.set('key', 'value')
storages.JSSessionStorage.get('key')

storages.JSCookie.set('key', 'value', {
 " : 1000*60*60*24*30,
 " path: '/',
 " domain: 'www.baidu.com',
 " secure: true
})
storages.JSCookie.get('key')

你也可以导入指定指定模块后再进行操作

import { JSLocalStorage, JSSessionStorage, JSCookie } from 'js-storages'

具体方法

localStoragesessionStorage

HTML5提供的localStoragesessionStorage对象的API十分类似,只是在对值保存的生命周期上有所不同:网址链接,所以对localStoragesessionStorage封装的API是相同的。

1、set

Storage中存储指定的值

语法:

JSLocalStorage.set(key, value[, time[, callback]])

参数:

key (必须,string

所存储值的键

value (必须,string | object | any[] | number

存储的值

time(可选,number

存储值的过期时间,单位毫秒

callback(可选,Function

执行成功的回调函数

2、get

获取Storage中指定的值。

语法

JSLocalStorage.get(key[, callback])

参数

key (必须,string

根据keyStorage中获取对应的值。

callback(可选,Function

执行成功的回调函数

3、remove

删除Storage中指定的值。

语法

JSLocalStorage.remove(key)

参数

key (必须,string

根据key值从Storage中删除指定的值。

4、removeAll

删除Storage中所有的值。

语法

JSLocalStorage.removeAll()

5、has

判断Storage中是否含有某个值。

语法

JSLocalStorage.has(key)

参数

key (必须,string

根据key值判断Storage中存在某个键

6、keys

获取Storage中所有的键。

语法

JSLocalStorage.keys()

cookie

1、set

语法:

JSCookie.set('test', 'value', {
  path: '/',
  expries: 1000 * 60
})

参数:

key [string]

必填字段,不能是:pathexpiresdomain等字段。

value [any]

必填字段,存储的值

args [object]

可选字段,额外的配置信息,包括pathexpiresdomainsecure

"expires": "cookie过期时间",
"path": "cookie存储的路径",
"domain": "cookie存储的域名",
"secure": "cookie只通过https协议传输"

2、get

获取某个cookie的value。

语法:

JSCookie.get('key')

参数:

key [string]

必填字段。

3、has

判断是否存储有某个cookie。

语法:

JSCookie.has('key')

参数:

key [string]

必填字段

4、remove

清除某个cookie

语法:

JSCookie.remove('key')

参数:

key [string]

必填字段

5、removeAll

清除所有cookie

语法:

JSCookie.removeAll()

6、keys

获取所有cookie的key,并以数组的形式返回。

语法:

JSCookie.keys()