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

l-store

v0.1.0

Published

A js libray for web storage, default support for localStorage and sessionStorage.

Downloads

4

Readme

l-store

对Web Storage(localStorage,sessionStorage)方法进行了封装和扩展, 支持设置过期时间, 主要特点是支持根据“路径”进行设值和取值操作。例如:"a.b[2].c"

Useage

npm install l-store -S

const Store = require("l-store");
// 或者直接引入  ./dist/lStore.js

options的字段说明

|字段|类型|默认值|说明| |-----|-----|-----|-----| |Storage|String|"localStorage"|可选("sessionStorage")| |exp|Number|31536000(100年)|过期时间(时间单位:秒)| |serialize|Function|默认执行JSON.stringify|存储到Storage时会执行serialize,可用于加密数据| |deserialize|Function|默认执行JSON.parse|从Storage取出来会执行deserialize,可用于解密数据|

Web Storage存储时的数据格式如下

{
    __start__:存储时的时间蹉,
    __data__ : 存储的数据(String类型),
    __end__: 数据有效的截止时间蹉
}

代码示例

const lStore = require("l-store");
var store = new lStore(/*options*/);   //实例化,采用默认配置

// set("路径",值,/*可选配置,只能设置exp*/)
store.set("db.userinfo.list[2].name","julyL");   
store.set("db.userinfo.id","10");
// 如果无法根据“路径”获取到值,则会根据“路径”生成相应的对象或者数组。
// 生成原理:“路径”中以.或者[]分隔的会被解析为属性,[]中有数字则会解析成数组。
// 上面的代码执行后,localStorage的结构如下:  localStorage中存储的键为“路径”解析后的第一个属性,这里是db
// => {
//     db: "{
//         "__start__":'Fri, 05 Jan 2018 05:37:12 GMT',
//         "__end__":'Fri, 05 Jan 2118 05:37:12 GMT',
//         "__data__":{
//             "db":{
//                 "userinfo":{
//                     "list":[null,null,{"name":"julyL"}]}    // 注意: list[2]会解析成长度为3的数组,由于我们只设置了第3个值,其余未设置的空值会用null进行填充
//                 },
//                 "id":"10"
//             }
//         }"
// }


store.get("db.userinfo.list.[2].name");  //=> "julyL"

store.set("a.b","1",{ exp :60 })   // 设置60s的过期之间

store.get("a")   //=>"1"  如果60s之后再进行store.get("userinfo")则会删除这条数据并且返回undefined

// 从localStoarge中删除指定的键
store.remove("a")  

// 清除所有过期数据
store.clearAllExpires()