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

locstore

v1.2.3

Published

>`Locstore`是一个轻量级的`JavaScript`库,提供了简洁而强大的本地存储管理功能。通过`Locstore`,开发者可以轻松地存储、检索和管理数据在用户的浏览器中,无论是长期存储还是短期会话存储。`Locstore`提供了一组丰富的API,允许您以简单的方式操作数据,包括设置、获取、删除等操作。它还提供了数据加密功能,以确保数据的安全性和高效存储。`Locstore`是一个高效、可靠、易于使用的本地存储解决方案,可以帮助您更好地管理和利用数据,提升用户体验和应用程序性能。 >`Locst

Downloads

7

Readme

locstore

Locstore是一个轻量级的JavaScript库,提供了简洁而强大的本地存储管理功能。通过Locstore,开发者可以轻松地存储、检索和管理数据在用户的浏览器中,无论是长期存储还是短期会话存储。Locstore提供了一组丰富的API,允许您以简单的方式操作数据,包括设置、获取、删除等操作。它还提供了数据加密功能,以确保数据的安全性和高效存储。Locstore是一个高效、可靠、易于使用的本地存储解决方案,可以帮助您更好地管理和利用数据,提升用户体验和应用程序性能。 Locstore集成了TypeScript,让您使用起来更是得心应手。 无论您是构建Web应用程序还是构建离线应用程序,Locstore都是您不可或缺的存储管理工具。


安装

npm install locstore --save
yarn add locstore --save
pnpm add locstore --save

导入

import _cache from 'locstore'

项目中使用

  1. 存储及获取
// js版本存储 默认为localstorage
_cache.set("name", "张三");

// js版本获取
const name = _cache.get("name");

// ts版本存储同上
// ts版本获取
const name = _cache.get<string>("name");
  1. 指定存储获取缓存类型
// 0. 安装
import _cache, { StoreType } from "locstore"

// 1. sessionstorage
_cache.set("name", "张三", { storage: StoreType.SEEEIONSTORAGE });
_cache.get("name", { storage: StoreType.SEEEIONSTORAGE })

// 2. localstorage
_cache.set("name", "张三", { storage: StoreType.LOCALSTORAGE});
_cache.get("name", { storage: StoreType.LOCALSTORAGE })

// 3. cookie
_cache.set("name", "张三", { storage: StoreType.COOKIE });
_cache.get("name", { storage: StoreType.COOKIE })
  1. 存储设置过期时间

过期时间根据dayjs时间转换,locstore中已经内置,项目中可以不安装, TimeSpan类为内置的,该类提供了一下几个方法 TimeSpan.Now(): Dayjs or TimeSpan.Today(): Dayjs // 获取当天时间 TimeSpan.Ticks(): number// 获取当前时间的时间戳 TimeSpan.FromDays(num: number): Dayjs 获取指定天数的后的日期 TimeSpan.FromHours(num: number): Dayjs 获取指定小时数的后的日期 TimeSpan.FromMinutes(num: number): Dayjs 获取指定分钟数的后的日期 TimeSpan.FromMilliseconds(num: number): Dayjs 获取指定毫秒数的后的日期 TimeSpan.FromSeconds(num: number): Dayjs 获取指定秒数的后的日期

// 0. 安装
import _cache, { TimeSpan } from "locstore";

// 1. 使用,
_cache.set("name", "张三", { expires: TimeSpan.FromDays(2) }); // 表示该缓存两天后过期
  1. 缓存加密

注意,加密后获取时需要解密

// 0. 安装
import _cache from "locstore";

// 1. 使用
_cache.set("name", "张三", { encrypt: true });

// 2. 获取
_cache.get("name", { decrypt: true });
  1. 案例
// 0. 安装
import _cache, { TimeSpan, StoreType } from "locstore";

// 1.从sessionStore加密存储一个对象并获取,过期时间为两天
const student = {
	name: "张三",
	age: 18,
	gender: "男"
}
_cache.set("student", student, { storage: StoreType.SESSIONSTORAGE, expires: TimeSpan.FromDays(2), encrypt: true  })
_cache.get("student", { decrypt: true })

// ts中获取对象格式
type StudentType = {
	name: string;
	age: number;
	gender: string;
}
_cache.get<StudentType>("student", { decrypt: true });

locstore为平时用ts编写代码时秉着能懒则懒,一劳永逸的心态而写。如果你也和我一样懒......🤣。对不起,实在是吹不下去了~~~~~