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

pinia-persist-own

v0.1.1

Published

pinia 持久化插件, 可加密

Downloads

15

Readme

使用

安装

# npm
npm i pinia-persist-own
# pnpm
pnpm add pinia-persist-own

使用

import { persist, createPersist } from 'pinia-persist-own'
import { createPinia } from 'pinia'

const pinia = createPinia()

// 这里传入的是公共参数,每个 store 均共享此参数
const createPersist = persist(/* 可进行传递通用参数 */)

/**
 * 如果不想进行统一设置参数的话,可以直接使用导出的 'createPersist' 
 * 每个 store 均可以进行单独进行配置,单独的配置要优先于公用配置
 * 
 */

// 添加持久化
pinia.use(createPersist)

app.use(pinia)

通用参数

  • 类型: Object

    options = { 
      	// 使用何种方式进行持久化, 默认: sessionStorage
      	storage: window.sessionStorage
      	// 持久化时,是否启用加密,需自行加密, 默认: false
      	// 当 useCrypt 为 true 时,加密解密方法必传
      	useCrypt: false,
      	// 加密数据方法
      	encrypt: (data /* 待加密数据 */) => {
      		// 加密实现
      	},
      	decrypt: (secretData) => {
      		// 解密实现
      	}
      }

私有参数

import { defineStore } from 'pinia' 

interface PersistProps{
	// 持久化名称
	name?: string;
	// 需要进行单独持久化的 keys => state 中的 key 集合
	keys?: string[];
	// 持久化方式,localStorage 和 sessionStorage 
	// 或者自行实现,自行实现 Storage 时,注意要实现的方法
	storage?: Storage;
	// 是否使用加密进行存储
	useCrypt?: false;
	// 加密方法
	encrypt?: (data: string) => string;
	// 解密方法
	decrypt?: (secretData: string) => string;
}

const useStore = defineStore('default-store', {
	// 是否启用持久化,传入 true/[] 均可,表示使用公用参数进行持久化
	persist: boolean | PersistProps[]
	state,
	getters,
	actions
})

License

MIT License © 2022 Owner