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

@bnfe/localstorage-slim

Package Overview
Dependencies
Maintainers
4
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.0 to 1.0.1

2

dist/index.esm.js

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

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

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).ls=t()}(this,(function(){"use strict";const e={WEAPP:"WEAPP",WEB:"WEB",RN:"RN",SWAN:"SWAN",ALIPAY:"ALIPAY",TT:"TT",QQ:"QQ",JD:"JD"};let t=null;const n=t||("undefined"!=typeof jd&&jd.getSystemInfo?(t=e.JD,e.JD):"undefined"!=typeof qq&&qq.getSystemInfo?(t=e.QQ,e.QQ):"undefined"!=typeof tt&&tt.getSystemInfo?(t=e.TT,e.TT):"undefined"!=typeof wx&&wx.getSystemInfo?(t=e.WEAPP,e.WEAPP):"undefined"!=typeof swan&&swan.getSystemInfo?(t=e.SWAN,e.SWAN):"undefined"!=typeof my&&my.getSystemInfo?(t=e.ALIPAY,e.ALIPAY):"undefined"!=typeof window?(t=e.WEB,e.WEB):"Unknown environment");let r;"WEB"===n&&(r={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"===n&&(r={getItem:wx.getStorageSync,setItem:wx.setStorageSync,removeItem:wx.removeStorageSync,clear:wx.clearStorageSync,keys:()=>wx.getStorageInfoSync().keys,length:wx.getStorageInfoSync().keys.length});var o=r;const c=(...e)=>{},l=e=>null!==e&&"Object"===e.constructor.name;let s;const y=()=>{if(void 0!==s)return s;s=!0;try{o||(s=!1)}catch(e){s=!1}return g(),s},a=String.fromCharCode(0),i=(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("")),f={ttl:null,encrypt:!1,encrypter:i,decrypter:(e,t)=>i(e,t,!1),secret:75},g=(e=!1)=>{if(!y())return!1;o.keys().forEach((t=>{try{const n=o.getItem(t);if(!n)return;l(n)&&a in n&&(Date.now()>n.ttl||e)&&o.removeItem(t)}catch(e){return}}))};return{config:f,set:(e,t,n={})=>{if(!y())return!1;const r=Object.assign(Object.assign(Object.assign({},f),n),{encrypt:!1!==n.encrypt&&(n.encrypt||f.encrypt),ttl:null===n.ttl?null:n.ttl||f.ttl});try{const n=r.ttl&&!isNaN(r.ttl)&&r.ttl>0;let l=n?{[a]:t,ttl:Date.now()+1e3*r.ttl}:t;r.encrypt&&(n?l[a]=(r.encrypter||c)(l[a],r.secret):l=(r.encrypter||c)(l,r.secret)),o.setItem(e,l)}catch(e){return!1}},get:(e,t={})=>{if(!y())return null;let n=o.getItem(e);if(!n)return null;const r=Object.assign(Object.assign(Object.assign({},f),t),{encrypt:!1!==t.encrypt&&(t.encrypt||f.encrypt),ttl:null===t.ttl?null:t.ttl||f.ttl}),s=l(n)&&a in n;if(r.decrypt||r.encrypt)try{s?n[a]=(r.decrypter||c)(n[a],r.secret):n=(r.decrypter||c)(n,r.secret)}catch(e){}return s?Date.now()>n.ttl?(o.removeItem(e),null):n[a]:n},remove:e=>{if(!y())return!1;o.removeItem(e)},clear:()=>{if(!y())return!1;o.clear()},flush:g}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).ls=t()}(this,(function(){"use strict";const e="WEAPP",t="WEB",n="SWAN",r="ALIPAY",o="TT",c="QQ",l="JD";let s=null;const y=s||("undefined"!=typeof jd&&jd.getSystemInfo?(s=l,l):"undefined"!=typeof qq&&qq.getSystemInfo?(s=c,c):"undefined"!=typeof tt&&tt.getSystemInfo?(s=o,o):"undefined"!=typeof wx&&wx.getSystemInfo?(s=e,e):"undefined"!=typeof swan&&swan.getSystemInfo?(s=n,n):"undefined"!=typeof my&&my.getSystemInfo?(s=r,r):"undefined"!=typeof window?(s=t,t):"Unknown environment");let a;"WEB"===y&&(a={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"===y&&(a={getItem:wx.getStorageSync,setItem:wx.setStorageSync,removeItem:wx.removeStorageSync,clear:wx.clearStorageSync,keys:()=>wx.getStorageInfoSync().keys,length:wx.getStorageInfoSync().keys.length});var i=a;const f=(...e)=>{},g=e=>null!==e&&"Object"===e.constructor.name;let d;const u=()=>{if(void 0!==d)return d;d=!0;try{i||(d=!1)}catch(e){d=!1}return w(),d},m=String.fromCharCode(0),p=(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("")),S={ttl:null,encrypt:!1,encrypter:p,decrypter:(e,t)=>p(e,t,!1),secret:75},w=(e=!1)=>{if(!u())return!1;i.keys().forEach((t=>{try{const n=i.getItem(t);if(!n)return;g(n)&&m in n&&(Date.now()>n.ttl||e)&&i.removeItem(t)}catch(e){return}}))};return{config:S,set:(e,t,n={})=>{if(!u())return!1;const r=Object.assign(Object.assign(Object.assign({},S),n),{encrypt:!1!==n.encrypt&&(n.encrypt||S.encrypt),ttl:null===n.ttl?null:n.ttl||S.ttl});try{const n=r.ttl&&!isNaN(r.ttl)&&r.ttl>0;let o=n?{[m]:t,ttl:Date.now()+1e3*r.ttl}:t;r.encrypt&&(n?o[m]=(r.encrypter||f)(o[m],r.secret):o=(r.encrypter||f)(o,r.secret)),i.setItem(e,o)}catch(e){return!1}},get:(e,t={})=>{if(!u())return null;let n=i.getItem(e);if(!n)return null;const r=Object.assign(Object.assign(Object.assign({},S),t),{encrypt:!1!==t.encrypt&&(t.encrypt||S.encrypt),ttl:null===t.ttl?null:t.ttl||S.ttl}),o=g(n)&&m in n;if(r.decrypt||r.encrypt)try{o?n[m]=(r.decrypter||f)(n[m],r.secret):n=(r.decrypter||f)(n,r.secret)}catch(e){}return o?Date.now()>n.ttl?(i.removeItem(e),null):n[m]:n},remove:e=>{if(!u())return!1;i.removeItem(e)},clear:()=>{if(!u())return!1;i.clear()},flush:w}}));

@@ -5,3 +5,3 @@ {

"description": "轻量级, 只有3KB的本地存储工具,可选支持ttl和加密,支持小程序和web",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/bnfe/localstorage-slim",

@@ -27,4 +27,3 @@ "scripts": {

"types": "dist/ls.d.ts",
"browser": "dist/index.umd.js",
"main": "dist/index.esm.js",
"main": "dist/index.umd.js",
"repository": {

@@ -31,0 +30,0 @@ "type": "git",

@@ -1,7 +0,5 @@

# localstorage-slim
## localstorage-slim
### 本项目 Fork [niketpathak/localstorage-slim](https://github.com/digitalfortress-tech/localstorage-slim), 添加支持小程序
---
一个超轻量级的库, 只有 3 KB 的本地存储工具,可选支持**ttl**和**加密**,支持**小程序**和**web**

@@ -13,4 +11,2 @@

---
### 安装

@@ -20,9 +16,9 @@

# Npm
$ npm install --save @banu/localstorage-slim
$ npm install --save @bnfe/localstorage-slim
# Yarn
$ yarn add @banu/localstorage-slim
$ yarn add @bnfe/localstorage-slim
# pnpm
$ pnpm add @banu/localstorage-slim
$ pnpm add @bnfe/localstorage-slim
```

@@ -34,6 +30,6 @@

// using ES6 modules
import ls from '@banu/localstorage-slim';
import ls from '@bnfe/localstorage-slim';
// using CommonJS modules
const ls = require('@banu/localstorage-slim');
const ls = require('@bnfe/localstorage-slim');
```

@@ -68,4 +64,2 @@

---
### 配置

@@ -84,4 +78,2 @@

---
### Encryption/Decryption

@@ -130,4 +122,2 @@

---
### API

@@ -143,4 +133,2 @@

---
#### 1.`ls.set(key, value, config = {})`

@@ -147,0 +135,0 @@

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