@lytjs/plugin-storage 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +44 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var b=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var F=(n,t)=>{for(var o in t)b(n,o,{get:t[o],enumerable:!0})},R=(n,t,o,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let g of N(t))!_.call(n,g)&&g!==o&&b(n,g,{get:()=>t[g],enumerable:!(l=J(t,g))||l.enumerable});return n};var j=n=>R(b({},"__esModule",{value:!0}),n);var B={};F(B,{createStorage:()=>A});module.exports=j(B);function w(n,t){return`${t}${n}`}function q(n,t){return n.startsWith(t)?n.slice(t.length):n}function x(n,t){let o=null;return function(...l){o&&clearTimeout(o),o=setTimeout(()=>n.apply(this,l),t)}}function A(n={}){let{prefix:t="lyt_",storage:o=typeof localStorage!="undefined"?localStorage:{},expire:l,debug:g=!1,serialize:P=JSON.stringify,deserialize:O=JSON.parse}=n,u=(...r)=>{};function c(r,e,i){try{let s={value:e,timestamp:Date.now()},a=i!=null?i:l;a&&(s.expire=Date.now()+a);let y=w(r,t);o.setItem(y,P(s)),u(`set ${r}`,e)}catch(s){}}function m(r,e){try{let i=w(r,t),s=o.getItem(i);if(!s)return e!=null?e:null;let a=O(s);return a.expire&&Date.now()>a.expire?(u(`${r} expired, removing`),h(r),e!=null?e:null):(u(`get ${r}`,a.value),a.value)}catch(i){return e!=null?e:null}}function h(r){try{let e=w(r,t);o.removeItem(e),u(`removed ${r}`)}catch(e){}}function $(){try{let r=T();for(let e of r)h(e);u("cleared all")}catch(r){}}function I(r){return m(r)!==null}function T(){try{let r=[];for(let e=0;e<o.length;e++){let i=o.key(e);i&&i.startsWith(t)&&r.push(q(i,t))}return r}catch(r){return[]}}function z(){return T().length}function W(r,e,i={}){let{immediate:s=!0,deep:a=!0,debounce:y=100}=i;if(typeof r.$watch=="function")return r.$watch(e,y>0?x(p=>{c(e,p)},y):p=>{c(e,p)},{immediate:s,deep:a});if(typeof globalThis.watch=="function"){let f=globalThis.watch;return f(()=>r[e],y>0?x(S=>{c(e,S)},y):S=>{c(e,S)},{immediate:s,deep:a})}let d=r[e],D=setInterval(()=>{let f=r[e];f!==d&&(d=f,c(e,f))},200);return s&&c(e,d),()=>clearInterval(D)}function K(r,e,i){let s=m(e,i);return s!==null&&(r[e]=s,u(`restored ${e}`,s)),r[e]}let v={install(r,e){r.config=r.config||{},r.config.globalProperties=r.config.globalProperties||{},r.config.globalProperties.$storage=v,typeof r.provide=="function"&&r.provide("storage",v)},set:c,get:m,remove:h,clear:$,has:I,keys:T,size:z,watch:W,restore:K,get storage(){return o}};return v}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function S(a,o){return`${o}${a}`}function D(a,o){return a.startsWith(o)?a.slice(o.length):a}function b(a,o){let i=null;return function(...f){i&&clearTimeout(i),i=setTimeout(()=>a.apply(this,f),o)}}function J(a={}){let{prefix:o="lyt_",storage:i=typeof localStorage!="undefined"?localStorage:{},expire:f,debug:w=!1,serialize:x=JSON.stringify,deserialize:P=JSON.parse}=a,c=(...r)=>{};function g(r,e,t){try{let n={value:e,timestamp:Date.now()},s=t!=null?t:f;s&&(n.expire=Date.now()+s);let l=S(r,o);i.setItem(l,x(n)),c(`set ${r}`,e)}catch(n){}}function p(r,e){try{let t=S(r,o),n=i.getItem(t);if(!n)return e!=null?e:null;let s=P(n);return s.expire&&Date.now()>s.expire?(c(`${r} expired, removing`),m(r),e!=null?e:null):(c(`get ${r}`,s.value),s.value)}catch(t){return e!=null?e:null}}function m(r){try{let e=S(r,o);i.removeItem(e),c(`removed ${r}`)}catch(e){}}function O(){try{let r=h();for(let e of r)m(e);c("cleared all")}catch(r){}}function $(r){return p(r)!==null}function h(){try{let r=[];for(let e=0;e<i.length;e++){let t=i.key(e);t&&t.startsWith(o)&&r.push(D(t,o))}return r}catch(r){return[]}}function I(){return h().length}function z(r,e,t={}){let{immediate:n=!0,deep:s=!0,debounce:l=100}=t;if(typeof r.$watch=="function")return r.$watch(e,l>0?b(y=>{g(e,y)},l):y=>{g(e,y)},{immediate:n,deep:s});if(typeof globalThis.watch=="function"){let u=globalThis.watch;return u(()=>r[e],l>0?b(d=>{g(e,d)},l):d=>{g(e,d)},{immediate:n,deep:s})}let v=r[e],K=setInterval(()=>{let u=r[e];u!==v&&(v=u,g(e,u))},200);return n&&g(e,v),()=>clearInterval(K)}function W(r,e,t){let n=p(e,t);return n!==null&&(r[e]=n,c(`restored ${e}`,n)),r[e]}let T={install(r,e){r.config=r.config||{},r.config.globalProperties=r.config.globalProperties||{},r.config.globalProperties.$storage=T,typeof r.provide=="function"&&r.provide("storage",T)},set:g,get:p,remove:m,clear:O,has:$,keys:h,size:I,watch:z,restore:W,get storage(){return i}};return T}export{J as createStorage};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lytjs/plugin-storage",
|
|
3
|
+
"version": "4.0.5",
|
|
4
|
+
"description": "Lyt.js 本地存储持久化插件 - 自动保存响应式状态到 localStorage/sessionStorage",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"module": "./src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./src/index.ts",
|
|
10
|
+
"require": "./src/index.ts",
|
|
11
|
+
"default": "./src/index.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "lytjs",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://gitee.com/lytjs/lytjs"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://gitee.com/lytjs/lytjs",
|
|
25
|
+
"keywords": [
|
|
26
|
+
"lyt",
|
|
27
|
+
"lytjs",
|
|
28
|
+
"javascript",
|
|
29
|
+
"framework",
|
|
30
|
+
"frontend",
|
|
31
|
+
"vue-like",
|
|
32
|
+
"lightweight",
|
|
33
|
+
"zero-dependency",
|
|
34
|
+
"storage",
|
|
35
|
+
"localStorage",
|
|
36
|
+
"persistence"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|