memorio 2.7.3 → 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 -27
  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
@@ -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.3"
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/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.3"
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.3",
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",