Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bnfe/localstorage-slim

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bnfe/localstorage-slim - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

dist/index.esm.js

@@ -1,1 +0,1 @@

const e="WEAPP",t="WEB",n="SWAN",r="ALIPAY",o="TT",c="QQ",l="JD";let a=null;const s=a||("undefined"!=typeof jd&&jd.getSystemInfo?(a=l,l):"undefined"!=typeof qq&&qq.getSystemInfo?(a=c,c):"undefined"!=typeof tt&&tt.getSystemInfo?(a=o,o):"undefined"!=typeof wx&&wx.getSystemInfo?(a=e,e):"undefined"!=typeof swan&&swan.getSystemInfo?(a=n,n):"undefined"!=typeof my&&my.getSystemInfo?(a=r,r):"undefined"!=typeof window?(a=t,t):"Unknown environment");let y;"WEB"===s&&(y={getItem:e=>{const t=window.localStorage.getItem(e);try{return JSON.parse(t||"")}catch(e){return t}},setItem:(e,t)=>window.localStorage.setItem(e,JSON.stringify(t)),removeItem:e=>window.localStorage.removeItem(e),clear:()=>window.localStorage.clear(),keys:()=>Object.keys(window.localStorage)||[],length:Object.keys(window.localStorage).length}),"WEAPP"===s&&(y={getItem:wx.getStorageSync,setItem:wx.setStorageSync,removeItem:wx.removeStorageSync,clear:wx.clearStorageSync,keys:()=>wx.getStorageInfoSync().keys,length:wx.getStorageInfoSync().keys.length});var i=y;const g=(...e)=>{},f=e=>null!==e&&"Object"===e.constructor.name;let m;const d=()=>{if(void 0!==m)return m;m=!0;try{i||(m=!1)}catch(e){m=!1}return w(),m},u=String.fromCharCode(0),S=(e,t,n=!0)=>n?[...JSON.stringify(e)].map((e=>String.fromCharCode(e.charCodeAt(0)+t))).join(""):JSON.parse([...e].map((e=>String.fromCharCode(e.charCodeAt(0)-t))).join("")),p={ttl:null,encrypt:!1,encrypter:S,decrypter:(e,t)=>S(e,t,!1),secret:75},w=(e=!1)=>{if(!d())return!1;i.keys().forEach((t=>{try{const n=i.getItem(t);if(!n)return;f(n)&&u in n&&(Date.now()>n.ttl||e)&&i.removeItem(t)}catch(e){return}}))};var I={config:p,set:(e,t,n={})=>{if(!d())return!1;const r=Object.assign(Object.assign(Object.assign({},p),n),{encrypt:!1!==n.encrypt&&(n.encrypt||p.encrypt),ttl:null===n.ttl?null:n.ttl||p.ttl});try{const n=r.ttl&&!isNaN(r.ttl)&&r.ttl>0;let o=n?{[u]:t,ttl:Date.now()+1e3*r.ttl}:t;r.encrypt&&(n?o[u]=(r.encrypter||g)(o[u],r.secret):o=(r.encrypter||g)(o,r.secret)),i.setItem(e,o)}catch(e){return!1}},get:(e,t={})=>{if(!d())return null;let n=i.getItem(e);if(!n)return null;const r=Object.assign(Object.assign(Object.assign({},p),t),{encrypt:!1!==t.encrypt&&(t.encrypt||p.encrypt),ttl:null===t.ttl?null:t.ttl||p.ttl}),o=f(n)&&u in n;if(r.decrypt||r.encrypt)try{o?n[u]=(r.decrypter||g)(n[u],r.secret):n=(r.decrypter||g)(n,r.secret)}catch(e){}return o?Date.now()>n.ttl?(i.removeItem(e),null):n[u]:n},remove:e=>{if(!d())return!1;i.removeItem(e)},clear:()=>{if(!d())return!1;i.clear()},flush:w};export{I as default};
const e="WEAPP",t="WEB",n="SWAN",r="ALIPAY",o="TT",c="QQ",l="JD";let a=null;const s=a||("undefined"!=typeof jd&&jd.getSystemInfo?(a=l,l):"undefined"!=typeof qq&&qq.getSystemInfo?(a=c,c):"undefined"!=typeof tt&&tt.getSystemInfo?(a=o,o):"undefined"!=typeof wx&&wx.getSystemInfo?(a=e,e):"undefined"!=typeof swan&&swan.getSystemInfo?(a=n,n):"undefined"!=typeof my&&my.getSystemInfo?(a=r,r):"undefined"!=typeof window?(a=t,t):"Unknown environment");let y;"WEB"===s&&(y={getItem:e=>{const t=window.localStorage.getItem(e);try{return JSON.parse(t||"")}catch(e){return t}},setItem:(e,t)=>window.localStorage.setItem(e,JSON.stringify(t)),removeItem:e=>window.localStorage.removeItem(e),clear:()=>window.localStorage.clear(),keys:()=>Object.keys(window.localStorage)||[],length:Object.keys(window.localStorage).length}),"WEAPP"===s&&(y={getItem:wx.getStorageSync,setItem:wx.setStorageSync,removeItem:wx.removeStorageSync,clear:wx.clearStorageSync,keys:()=>wx.getStorageInfoSync().keys,length:wx.getStorageInfoSync().keys.length});var i=y;const g=(...e)=>{},f=e=>null!==e&&"Object"===e.constructor.name;let m;const d=()=>{if(void 0!==m)return m;m=!0;try{i||(m=!1)}catch(e){m=!1}return w(),m},u=String.fromCharCode(0),S=(e,t,n=!0)=>n?[...JSON.stringify(e)].map((e=>String.fromCharCode(e.charCodeAt(0)+t))).join(""):JSON.parse([...e].map((e=>String.fromCharCode(e.charCodeAt(0)-t))).join("")),p={ttl:null,encrypt:!1,encrypter:S,decrypter:(e,t)=>S(e,t,!1),secret:75},w=(e=!1)=>{if(!d())return!1;i.keys().forEach((t=>{try{const n=i.getItem(t);if(!n)return;f(n)&&u in n&&(Date.now()>n.ttl||e)&&i.removeItem(t)}catch(e){return}}))},I={config:p,set:(e,t,n={})=>{if(!d())return!1;const r=Object.assign(Object.assign(Object.assign({},p),n),{encrypt:!1!==n.encrypt&&(n.encrypt||p.encrypt),ttl:null===n.ttl?null:n.ttl||p.ttl});try{const n=r.ttl&&!isNaN(r.ttl)&&r.ttl>0;let o=n?{[u]:t,ttl:Date.now()+1e3*r.ttl}:t;r.encrypt&&(n?o[u]=(r.encrypter||g)(o[u],r.secret):o=(r.encrypter||g)(o,r.secret)),i.setItem(e,o)}catch(e){return!1}},get:(e,t={})=>{if(!d())return null;let n=i.getItem(e);if(!n)return null;const r=Object.assign(Object.assign(Object.assign({},p),t),{encrypt:!1!==t.encrypt&&(t.encrypt||p.encrypt),ttl:null===t.ttl?null:t.ttl||p.ttl}),o=f(n)&&u in n;if(r.decrypt||r.encrypt)try{o?n[u]=(r.decrypter||g)(n[u],r.secret):n=(r.decrypter||g)(n,r.secret)}catch(e){}return o?Date.now()>n.ttl?(i.removeItem(e),null):n[u]:n},remove:e=>{if(!d())return!1;i.removeItem(e)},clear:()=>{if(!d())return!1;i.clear()},flush:w};export{I as default};

@@ -11,10 +11,10 @@ type Encrypter = (...args: unknown[]) => string;

}
declare const _default: {
declare const ls: {
config: LocalStorageConfig;
set: <T = unknown>(key: string, value: T, localConfig?: LocalStorageConfig) => boolean | void;
set: <T = unknown>(key: string, value: T, localConfig?: LocalStorageConfig) => void | boolean;
get: <T_1 = unknown>(key: string, localConfig?: LocalStorageConfig) => T_1 | null;
remove: (key: string) => false | undefined;
clear: () => false | undefined;
remove: (key: string) => undefined | false;
clear: () => undefined | false;
flush: (force?: boolean) => false | void;
};
export default _default;
export default ls;

@@ -5,12 +5,4 @@ {

"description": "轻量级, 只有3KB的本地存储工具,可选支持ttl和加密,支持小程序和web",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://github.com/bnfe/localstorage-slim",
"scripts": {
"build": "rollup -c",
"dev": "NODE_ENV=development rollup -c --watch",
"prod": "NODE_ENV=production rollup -c",
"tag": "npm version minor --no-git-tag-version && npm run prod && PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git commit -am \"$PACKAGE_VERSION release\" && git tag v$PACKAGE_VERSION",
"test": "jest --verbose",
"lint": "eslint ./src --ext .ts --fix"
},
"jest": {

@@ -57,3 +49,11 @@ "transform": {

"typescript": "^4.0.3"
},
"scripts": {
"build": "rollup -c",
"dev": "NODE_ENV=development rollup -c --watch",
"prod": "NODE_ENV=production rollup -c",
"tag": "npm version minor --no-git-tag-version && npm run prod && PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git commit -am \"$PACKAGE_VERSION release\" && git tag v$PACKAGE_VERSION",
"test": "jest --verbose",
"lint": "eslint ./src --ext .ts --fix"
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc