memorio 2.7.4 → 2.8.0

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.
Files changed (4) hide show
  1. package/README.md +0 -4
  2. package/index.cjs +47 -29
  3. package/index.js +47 -27
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -6,10 +6,6 @@
6
6
  [![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=memorio&query=$.install.pretty&label=install%20size&style=flat-square)](https://packagephobia.now.sh/result?p=memorio)
7
7
  [![downloads](https://img.shields.io/npm/dm/memorio.svg)](https://npmjs.org/package/memorio)
8
8
 
9
- ![Snyk](https://img.shields.io/badge/Snyk-gray?logo=Snyk)
10
- [![Known Vulnerabilities](https://snyk.io/test/npm/memorio/badge.svg)](https://snyk.io/test/npm/memorio)
11
- [![Socket Badge](https://socket.dev/api/badge/npm/package/memorio)](https://socket.dev/npm/package/memorio)
12
-
13
9
  ![Node.js](https://img.shields.io/badge/Node.js-gray?logo=node.js)
14
10
  ![React](https://img.shields.io/badge/React-gray?logo=React)
15
11
  ![Javascript](https://img.shields.io/badge/Javascript-gray?logo=Javascript)
package/index.cjs CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  var e = Object.getOwnPropertyNames, t = (t, o) => function() {
4
2
  return t && (o = (0, t[e(t)[0]])(t = 0)), o;
5
3
  }, o = {}, r = t({
@@ -63,7 +61,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
63
61
  }
64
62
  };
65
63
  }
66
- }), m = {}, g = t({
64
+ }), m = {}, h = t({
67
65
  "functions/idb/tools/db.version.ts"() {
68
66
  idb.db.version = e => {
69
67
  let t = 0;
@@ -74,7 +72,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
74
72
  return t;
75
73
  };
76
74
  }
77
- }), h = {}, p = t({
75
+ }), g = {}, p = t({
78
76
  "functions/idb/tools/db.support.ts"() {
79
77
  idb.db.support = () => {
80
78
  const e = "indexedDB" in globalThis;
@@ -158,7 +156,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
158
156
  }, s.onerror = () => r(s.error);
159
157
  });
160
158
  }
161
- }), w = {}, _ = t({
159
+ }), w = {}, S = t({
162
160
  "functions/idb/crud/data.set.ts"() {
163
161
  idb.data.set = (e, t, o) => new Promise((r, s) => {
164
162
  const n = indexedDB.open(e);
@@ -176,7 +174,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
176
174
  };
177
175
  });
178
176
  }
179
- }), S = {}, k = t({
177
+ }), _ = {}, k = t({
180
178
  "functions/idb/crud/data.get.ts"() {
181
179
  idb.data.get = (e, t, o) => new Promise((r, s) => {
182
180
  const n = indexedDB.open(e);
@@ -206,7 +204,7 @@ function x() {
206
204
  return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
207
205
  }
208
206
 
209
- function N() {
207
+ function E() {
210
208
  try {
211
209
  if ("undefined" != typeof sessionStorage) {
212
210
  const e = "__memorio_test__";
@@ -216,7 +214,7 @@ function N() {
216
214
  return null;
217
215
  }
218
216
 
219
- function E() {
217
+ function N() {
220
218
  try {
221
219
  if ("undefined" != typeof localStorage) {
222
220
  const e = "__memorio_test__";
@@ -237,8 +235,8 @@ function D() {
237
235
  }(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
238
236
  return {
239
237
  platform: e,
240
- hasSessionStorage: null !== N(),
241
- hasLocalStorage: null !== E(),
238
+ hasSessionStorage: null !== E(),
239
+ hasLocalStorage: null !== N(),
242
240
  hasIndexedDB: I(),
243
241
  hasDispatchEvent: "function" == typeof globalThis.dispatchEvent,
244
242
  hasNavigator: "undefined" != typeof navigator,
@@ -312,7 +310,7 @@ Object.defineProperty(globalThis, "memorio", {
312
310
  }), Object.defineProperty(memorio, "version", {
313
311
  writable: !1,
314
312
  enumerable: !1,
315
- value: "2.7.4"
313
+ value: "2.8.0"
316
314
  });
317
315
 
318
316
  var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
@@ -583,10 +581,10 @@ Object.defineProperty(globalThis, "useObserver", {
583
581
  }
584
582
  }, Object.freeze(globalThis.useObserver);
585
583
 
586
- var R = E(), M = new Map, q = null !== R, W = `memorio_store_${globalThis.memorio?._sessionId || "default"}_`;
584
+ var R = N(), W = new Map, M = null !== R, q = "memorio_store_";
587
585
 
588
586
  function L(e) {
589
- return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? W + e : "" : "";
587
+ return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? q + e : "" : "";
590
588
  }
591
589
 
592
590
  Object.defineProperty(globalThis, "store", {
@@ -599,12 +597,12 @@ Object.defineProperty(globalThis, "store", {
599
597
  if (!e) return;
600
598
  const t = L(e);
601
599
  try {
602
- if (q) {
600
+ if (M) {
603
601
  const e = R.getItem(t);
604
602
  return e ? JSON.parse(e) : e;
605
603
  }
606
604
  {
607
- const e = M.get(t);
605
+ const e = W.get(t);
608
606
  return e ? JSON.parse(e) : e;
609
607
  }
610
608
  } catch (e) {}
@@ -616,7 +614,7 @@ Object.defineProperty(globalThis, "store", {
616
614
  if (!e) return;
617
615
  const o = L(e);
618
616
  try {
619
- q ? null == t ? R.setItem(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || R.setItem(o, JSON.stringify(t)) : null == t ? M.set(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || M.set(o, JSON.stringify(t));
617
+ M ? null == t ? R.setItem(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || R.setItem(o, JSON.stringify(t)) : null == t ? W.set(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || W.set(o, JSON.stringify(t));
620
618
  } catch (e) {}
621
619
  return null;
622
620
  }
@@ -626,9 +624,9 @@ Object.defineProperty(globalThis, "store", {
626
624
  if (!e) return;
627
625
  const t = L(e);
628
626
  try {
629
- if (q) {
627
+ if (M) {
630
628
  if (R.getItem(t)) return R.removeItem(t), !0;
631
- } else if (M.has(t)) return M.delete(t), !0;
629
+ } else if (W.has(t)) return W.delete(t), !0;
632
630
  } catch (e) {}
633
631
  return !1;
634
632
  }
@@ -637,7 +635,17 @@ Object.defineProperty(globalThis, "store", {
637
635
  value: e => (store.remove(e), !0)
638
636
  },
639
637
  removeAll: {
640
- value: () => (q ? R.clear() : M.clear(), !0)
638
+ value: () => {
639
+ if (M) {
640
+ const e = [];
641
+ for (let t = 0; t < R.length; t++) {
642
+ const o = R.key(t);
643
+ o?.startsWith(q) && e.push(o);
644
+ }
645
+ e.forEach(e => R.removeItem(e));
646
+ } else W.clear();
647
+ return !0;
648
+ }
641
649
  },
642
650
  clearAll: {
643
651
  value: () => (store.removeAll(), !0)
@@ -648,22 +656,22 @@ Object.defineProperty(globalThis, "store", {
648
656
  size: {
649
657
  value: () => {
650
658
  let e = 0;
651
- return q ? Object.keys(R).forEach(t => {
652
- if (t.startsWith(W)) {
659
+ return M ? Object.keys(R).forEach(t => {
660
+ if (t.startsWith(q)) {
653
661
  const o = R.getItem(t);
654
662
  o && (e += o.length);
655
663
  }
656
- }) : M.forEach(t => {
664
+ }) : W.forEach(t => {
657
665
  e += t.length;
658
666
  }), e;
659
667
  }
660
668
  },
661
669
  isPersistent: {
662
- get: () => q
670
+ get: () => M
663
671
  }
664
672
  }), Object.freeze(store);
665
673
 
666
- var U = N(), V = new Map, F = null !== U, K = `memorio_session_${globalThis.memorio?._sessionId || "default"}_`;
674
+ var U = E(), V = new Map, F = null !== U, K = "memorio_session_";
667
675
 
668
676
  function Z(e) {
669
677
  return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? K + e : "" : "";
@@ -714,7 +722,17 @@ Object.defineProperty(globalThis, "session", {
714
722
  value: e => (session.remove(e), !0)
715
723
  },
716
724
  removeAll: {
717
- value: () => (F ? U.clear() : V.clear(), !0)
725
+ value: () => {
726
+ if (F) {
727
+ const e = [];
728
+ for (let t = 0; t < U.length; t++) {
729
+ const o = U.key(t);
730
+ o?.startsWith(K) && e.push(o);
731
+ }
732
+ e.forEach(e => U.removeItem(e));
733
+ } else V.clear();
734
+ return !0;
735
+ }
718
736
  },
719
737
  clearAll: {
720
738
  value: () => (session.removeAll(), !0)
@@ -771,10 +789,10 @@ Object.defineProperty(globalThis, "cache", {
771
789
  }), await Promise.all([ Promise.resolve().then(() => (r(), o)), Promise.resolve().then(() => (n(),
772
790
  s)), Promise.resolve().then(() => (a(), i)), Promise.resolve().then(() => (c(),
773
791
  l)), Promise.resolve().then(() => (u(), b)), Promise.resolve().then(() => (f(),
774
- d)), Promise.resolve().then(() => (g(), m)), Promise.resolve().then(() => (p(),
775
- h)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
776
- T)), Promise.resolve().then(() => (P(), O)), Promise.resolve().then(() => (_(),
777
- w)), Promise.resolve().then(() => (k(), S)) ]), Object.preventExtensions(idb), Object.seal(idb),
792
+ d)), Promise.resolve().then(() => (h(), m)), Promise.resolve().then(() => (p(),
793
+ g)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
794
+ T)), Promise.resolve().then(() => (P(), O)), Promise.resolve().then(() => (S(),
795
+ w)), Promise.resolve().then(() => (k(), _)) ]), Object.preventExtensions(idb), Object.seal(idb),
778
796
  Object.freeze(idb);
779
797
  })() : (Object.defineProperty(globalThis, "idb", {
780
798
  value: {
package/index.js CHANGED
@@ -61,7 +61,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
61
61
  }
62
62
  };
63
63
  }
64
- }), m = {}, g = t({
64
+ }), m = {}, h = t({
65
65
  "functions/idb/tools/db.version.ts"() {
66
66
  idb.db.version = e => {
67
67
  let t = 0;
@@ -72,7 +72,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
72
72
  return t;
73
73
  };
74
74
  }
75
- }), h = {}, p = t({
75
+ }), g = {}, p = t({
76
76
  "functions/idb/tools/db.support.ts"() {
77
77
  idb.db.support = () => {
78
78
  const e = "indexedDB" in globalThis;
@@ -156,7 +156,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
156
156
  }, s.onerror = () => r(s.error);
157
157
  });
158
158
  }
159
- }), w = {}, _ = t({
159
+ }), w = {}, S = t({
160
160
  "functions/idb/crud/data.set.ts"() {
161
161
  idb.data.set = (e, t, o) => new Promise((r, s) => {
162
162
  const n = indexedDB.open(e);
@@ -174,7 +174,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
174
174
  };
175
175
  });
176
176
  }
177
- }), S = {}, k = t({
177
+ }), _ = {}, k = t({
178
178
  "functions/idb/crud/data.get.ts"() {
179
179
  idb.data.get = (e, t, o) => new Promise((r, s) => {
180
180
  const n = indexedDB.open(e);
@@ -204,7 +204,7 @@ function x() {
204
204
  return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
205
205
  }
206
206
 
207
- function N() {
207
+ function E() {
208
208
  try {
209
209
  if ("undefined" != typeof sessionStorage) {
210
210
  const e = "__memorio_test__";
@@ -214,7 +214,7 @@ function N() {
214
214
  return null;
215
215
  }
216
216
 
217
- function E() {
217
+ function N() {
218
218
  try {
219
219
  if ("undefined" != typeof localStorage) {
220
220
  const e = "__memorio_test__";
@@ -235,8 +235,8 @@ function D() {
235
235
  }(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
236
236
  return {
237
237
  platform: e,
238
- hasSessionStorage: null !== N(),
239
- hasLocalStorage: null !== E(),
238
+ hasSessionStorage: null !== E(),
239
+ hasLocalStorage: null !== N(),
240
240
  hasIndexedDB: I(),
241
241
  hasDispatchEvent: "function" == typeof globalThis.dispatchEvent,
242
242
  hasNavigator: "undefined" != typeof navigator,
@@ -310,7 +310,7 @@ Object.defineProperty(globalThis, "memorio", {
310
310
  }), Object.defineProperty(memorio, "version", {
311
311
  writable: !1,
312
312
  enumerable: !1,
313
- value: "2.7.4"
313
+ value: "2.8.0"
314
314
  });
315
315
 
316
316
  var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
@@ -581,10 +581,10 @@ Object.defineProperty(globalThis, "useObserver", {
581
581
  }
582
582
  }, Object.freeze(globalThis.useObserver);
583
583
 
584
- var R = E(), M = new Map, q = null !== R, W = `memorio_store_${globalThis.memorio?._sessionId || "default"}_`;
584
+ var R = N(), W = new Map, M = null !== R, q = "memorio_store_";
585
585
 
586
586
  function L(e) {
587
- return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? W + e : "" : "";
587
+ return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? q + e : "" : "";
588
588
  }
589
589
 
590
590
  Object.defineProperty(globalThis, "store", {
@@ -597,12 +597,12 @@ Object.defineProperty(globalThis, "store", {
597
597
  if (!e) return;
598
598
  const t = L(e);
599
599
  try {
600
- if (q) {
600
+ if (M) {
601
601
  const e = R.getItem(t);
602
602
  return e ? JSON.parse(e) : e;
603
603
  }
604
604
  {
605
- const e = M.get(t);
605
+ const e = W.get(t);
606
606
  return e ? JSON.parse(e) : e;
607
607
  }
608
608
  } catch (e) {}
@@ -614,7 +614,7 @@ Object.defineProperty(globalThis, "store", {
614
614
  if (!e) return;
615
615
  const o = L(e);
616
616
  try {
617
- q ? null == t ? R.setItem(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || R.setItem(o, JSON.stringify(t)) : null == t ? M.set(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || M.set(o, JSON.stringify(t));
617
+ M ? null == t ? R.setItem(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || R.setItem(o, JSON.stringify(t)) : null == t ? W.set(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || W.set(o, JSON.stringify(t));
618
618
  } catch (e) {}
619
619
  return null;
620
620
  }
@@ -624,9 +624,9 @@ Object.defineProperty(globalThis, "store", {
624
624
  if (!e) return;
625
625
  const t = L(e);
626
626
  try {
627
- if (q) {
627
+ if (M) {
628
628
  if (R.getItem(t)) return R.removeItem(t), !0;
629
- } else if (M.has(t)) return M.delete(t), !0;
629
+ } else if (W.has(t)) return W.delete(t), !0;
630
630
  } catch (e) {}
631
631
  return !1;
632
632
  }
@@ -635,7 +635,17 @@ Object.defineProperty(globalThis, "store", {
635
635
  value: e => (store.remove(e), !0)
636
636
  },
637
637
  removeAll: {
638
- value: () => (q ? R.clear() : M.clear(), !0)
638
+ value: () => {
639
+ if (M) {
640
+ const e = [];
641
+ for (let t = 0; t < R.length; t++) {
642
+ const o = R.key(t);
643
+ o?.startsWith(q) && e.push(o);
644
+ }
645
+ e.forEach(e => R.removeItem(e));
646
+ } else W.clear();
647
+ return !0;
648
+ }
639
649
  },
640
650
  clearAll: {
641
651
  value: () => (store.removeAll(), !0)
@@ -646,22 +656,22 @@ Object.defineProperty(globalThis, "store", {
646
656
  size: {
647
657
  value: () => {
648
658
  let e = 0;
649
- return q ? Object.keys(R).forEach(t => {
650
- if (t.startsWith(W)) {
659
+ return M ? Object.keys(R).forEach(t => {
660
+ if (t.startsWith(q)) {
651
661
  const o = R.getItem(t);
652
662
  o && (e += o.length);
653
663
  }
654
- }) : M.forEach(t => {
664
+ }) : W.forEach(t => {
655
665
  e += t.length;
656
666
  }), e;
657
667
  }
658
668
  },
659
669
  isPersistent: {
660
- get: () => q
670
+ get: () => M
661
671
  }
662
672
  }), Object.freeze(store);
663
673
 
664
- var U = N(), V = new Map, F = null !== U, K = `memorio_session_${globalThis.memorio?._sessionId || "default"}_`;
674
+ var U = E(), V = new Map, F = null !== U, K = "memorio_session_";
665
675
 
666
676
  function Z(e) {
667
677
  return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? K + e : "" : "";
@@ -712,7 +722,17 @@ Object.defineProperty(globalThis, "session", {
712
722
  value: e => (session.remove(e), !0)
713
723
  },
714
724
  removeAll: {
715
- value: () => (F ? U.clear() : V.clear(), !0)
725
+ value: () => {
726
+ if (F) {
727
+ const e = [];
728
+ for (let t = 0; t < U.length; t++) {
729
+ const o = U.key(t);
730
+ o?.startsWith(K) && e.push(o);
731
+ }
732
+ e.forEach(e => U.removeItem(e));
733
+ } else V.clear();
734
+ return !0;
735
+ }
716
736
  },
717
737
  clearAll: {
718
738
  value: () => (session.removeAll(), !0)
@@ -769,10 +789,10 @@ Object.defineProperty(globalThis, "cache", {
769
789
  }), await Promise.all([ Promise.resolve().then(() => (r(), o)), Promise.resolve().then(() => (n(),
770
790
  s)), Promise.resolve().then(() => (a(), i)), Promise.resolve().then(() => (c(),
771
791
  l)), Promise.resolve().then(() => (u(), b)), Promise.resolve().then(() => (f(),
772
- d)), Promise.resolve().then(() => (g(), m)), Promise.resolve().then(() => (p(),
773
- h)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
774
- T)), Promise.resolve().then(() => (P(), O)), Promise.resolve().then(() => (_(),
775
- w)), Promise.resolve().then(() => (k(), S)) ]), Object.preventExtensions(idb), Object.seal(idb),
792
+ d)), Promise.resolve().then(() => (h(), m)), Promise.resolve().then(() => (p(),
793
+ g)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
794
+ T)), Promise.resolve().then(() => (P(), O)), Promise.resolve().then(() => (S(),
795
+ w)), Promise.resolve().then(() => (k(), _)) ]), Object.preventExtensions(idb), Object.seal(idb),
776
796
  Object.freeze(idb);
777
797
  })() : (Object.defineProperty(globalThis, "idb", {
778
798
  value: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "memorio",
3
3
  "code": "memorio",
4
- "version": "2.7.4",
4
+ "version": "2.8.0",
5
5
  "description": "Memorio, State + Observer, Store and iDB for an easy life - Cross-platform compatible",
6
6
  "main": "./index.cjs",
7
7
  "browser": "./index.cjs",