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

@qdk/localstore

v1.0.3-beta.1

Published

本地长期存储、本地会话期间存储,对原生方法的操作改进,创建了localStore、sessionStore组件库

Downloads

14

Readme

描述

localStorage 本地数据长期存储,不会因为浏览器关闭而清空数据。 sessionStorage 当前页面会话期间有效,当页面窗口关闭时,存储在sessionStorage的数据将被清空。

localStorage 、sessionStorage 键值对都是以字符串的形式存储,如果是其他类型将会自动转换为字符串类型的数据存储。

根据上面的特性,创建了localStore库,键可以是字符串,值可以是任何类型。支持方法有设置、读取、删除、清空、遍历键值对。

安装

npm install -S @qdk/localstore

引用

import { localStore, sesstionStore } from '@qdk/localstore';

例子

一、localStore 本地数据长期存储

例一、设置

localStore.setItem('array', [1, 2, 3, 4, 5, 6]);
localStore.setItem('object', { a: 'a', b: 'b', c: 'c' });
localStore.setItem('data', { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' });

例二、读取

localStore.getItem('array'); // [1, 2, 3, 4, 5, 6]
localStore.getItem('object'); // { a: 'a', b: 'b', c: 'c' }
localStore.getItem('data'); // { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' }

例三、删除

localStore.removeItem('array');
localStore.removeItem('object');
localStore.removeItem('data');

例四、清空

localStore.clear();

例五、遍历键

localStore.keys().forEach(item=> {
    console.log(item);
});

// 'array'
// 'object'
// 'data'

例六、遍历值

localStore.values().forEach(item=> {
    console.log(item);
});

// [1, 2, 3, 4, 5, 6]
// { a: 'a', b: 'b', c: 'c' }
// { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' }

例七、遍历键值对

localStore.entries().forEach(item=> {
    console.log(item);
});

// ['array', [1, 2, 3, 4, 5, 6]]
// ['object', { a: 'a', b: 'b', c: 'c' }]
// ['data', { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' }]

二、sesstionStore 页面会话期间有效

例一、设置

sesstionStore.setItem('array', [1, 2, 3, 4, 5, 6]);
sesstionStore.setItem('object', { a: 'a', b: 'b', c: 'c' });
sesstionStore.setItem('data', { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' });

例二、读取

sesstionStore.getItem('array'); // [1, 2, 3, 4, 5, 6]
sesstionStore.getItem('object'); // { a: 'a', b: 'b', c: 'c' }
sesstionStore.getItem('data'); // { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' }

例三、删除

sesstionStore.removeItem('array');
sesstionStore.removeItem('object');
sesstionStore.removeItem('data');

例四、清空

sesstionStore.clear();

例五、遍历键

sesstionStore.keys().forEach(item=> {
    console.log(item);
});

// 'array'
// 'object'
// 'data'

例六、遍历值

sesstionStore.values().forEach(item=> {
    console.log(item);
});

// [1, 2, 3, 4, 5, 6]
// { a: 'a', b: 'b', c: 'c' }
// { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' }

例七、遍历键值对

sesstionStore.entries().forEach(item=> {
    console.log(item);
});

// ['array', [1, 2, 3, 4, 5, 6]]
// ['object', { a: 'a', b: 'b', c: 'c' }]
// ['data', { list: [{a: 1}, {a: 2}, {a: 3}], version: '1.0.0' }]

微信号

联系作者:qianduanka

网站

https://www.qianduanka.com

前端咖公众号

公众号

前端咖小程序

公众号