use-good-hooks 1.0.21 → 1.0.23

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.
@@ -3,70 +3,72 @@ import O from "lodash/isEmpty";
3
3
  import m from "lodash/isFunction";
4
4
  import T from "lodash/isMap";
5
5
  import U from "lodash/isSet";
6
- import _ from "use-json";
6
+ import E from "use-json";
7
7
  import h from "lodash/merge";
8
- import E from "lodash/omit";
9
- import b from "lodash/omitBy";
10
- import d from "lodash/pick";
11
- import w from "lodash/pickBy";
12
- import p from "lodash/size";
13
- import { i as I } from "./is-BPZNFd2v.mjs";
8
+ import b from "lodash/omit";
9
+ import d from "lodash/omitBy";
10
+ import w from "lodash/pick";
11
+ import I from "lodash/pickBy";
12
+ import a from "lodash/size";
13
+ import { i as u } from "./is-BPZNFd2v.mjs";
14
14
  import j from "./use-debounce.js";
15
- const k = 500, u = "local", C = (i, r) => T(r) ? {
15
+ const k = 500, S = "local", C = (c, r) => T(r) ? {
16
16
  __type: "Map",
17
17
  value: Array.from(r.entries())
18
18
  } : U(r) ? {
19
19
  __type: "Set",
20
20
  value: Array.from(r)
21
- } : r, L = (i, r) => r && r.__type === "Map" ? new Map(r.value) : r && r.__type === "Set" ? new Set(r.value) : r, $ = (i, r, K) => {
22
- const a = D(K || {}), R = () => {
21
+ } : r, L = (c, r) => r && r.__type === "Map" ? new Map(r.value) : r && r.__type === "Set" ? new Set(r.value) : r, $ = (c, r, K) => {
22
+ const p = D(K || {}), R = () => {
23
+ if (!u.browser())
24
+ return r;
23
25
  const {
24
- storage: f = u,
25
- omitKeys: t,
26
+ storage: f = S,
27
+ omitKeys: e,
26
28
  onError: n,
27
- pickKeys: e
28
- } = a.current;
29
+ pickKeys: o
30
+ } = p.current, i = f === "local" ? localStorage : sessionStorage;
29
31
  try {
30
- const c = f === "local" ? localStorage : sessionStorage, o = c == null ? void 0 : c.getItem(i);
31
- if (o) {
32
- let s = _.parse(o, L);
33
- return t && (p(t) || m(t)) && (s = m(t) ? b(s, t) : E(s, t)), e && (p(e) || m(e)) && (s = m(e) ? w(s, e) : d(s, e)), O(s) ? r : h({}, r, s);
32
+ const t = i == null ? void 0 : i.getItem(c);
33
+ if (t) {
34
+ let s = E.parse(t, L);
35
+ return e && (a(e) || m(e)) && (s = m(e) ? d(s, e) : b(s, e)), o && (a(o) || m(o)) && (s = m(o) ? I(s, o) : w(s, o)), O(s) ? r : h({}, r, s);
34
36
  }
35
- } catch (c) {
36
- n && n(c);
37
+ } catch (t) {
38
+ n && n(t);
37
39
  }
38
40
  return r;
39
- }, [S, g] = M(R), y = j(
40
- S,
41
- a.current.debounce ?? k
41
+ }, [g, y] = M(R), l = j(
42
+ g,
43
+ p.current.debounce ?? k
42
44
  );
43
45
  B(() => {
44
- if (!I.browser())
46
+ if (!u.browser())
45
47
  return;
46
48
  const {
47
- storage: f = u,
48
- onError: t,
49
+ storage: f = S,
50
+ onError: e,
49
51
  omitKeys: n,
50
- pickKeys: e
51
- } = a.current, c = f === "local" ? localStorage : sessionStorage;
52
- if (c)
52
+ pickKeys: o
53
+ } = p.current, i = f === "local" ? localStorage : sessionStorage;
54
+ if (i)
53
55
  try {
54
- let o = y;
55
- n && (p(n) || m(n)) && (o = m(n) ? b(o, n) : E(o, n)), e && (p(e) || m(e)) && (o = m(e) ? w(o, e) : d(o, e));
56
- const s = c.getItem(i), l = _.stringify(o, C);
57
- s !== l && c.setItem(i, l);
58
- } catch (o) {
59
- t && t(o);
56
+ let t = l;
57
+ n && (a(n) || m(n)) && (t = m(n) ? d(t, n) : b(t, n)), o && (a(o) || m(o)) && (t = m(o) ? I(t, o) : w(t, o));
58
+ const s = i.getItem(c), _ = E.stringify(t, C);
59
+ s !== _ && i.setItem(c, _);
60
+ } catch (t) {
61
+ e && e(t);
60
62
  }
61
- }, [i, y]);
63
+ }, [c, l]);
62
64
  const A = F(() => {
63
- if (!I.browser())
65
+ if (!u.browser())
64
66
  return;
65
- g(r);
66
- const { storage: f = u } = a.current, t = f === "local" ? localStorage : sessionStorage;
67
- t == null || t.removeItem(i);
68
- }, [i, r]);
69
- return [S, g, { removeKey: A }];
67
+ y(r);
68
+ const { storage: f = S } = p.current, e = f === "local" ? localStorage : sessionStorage;
69
+ e == null || e.removeItem(c);
70
+ }, [c, r]);
71
+ return [g, y, { removeKey: A }];
70
72
  };
71
73
  export {
72
74
  $ as default,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "use-good-hooks",
3
3
  "dependencies": {
4
- "use-json": "^1.0.0",
4
+ "use-json": "^1.0.1",
5
5
  "use-qs": "^1.0.4"
6
6
  },
7
7
  "devDependencies": {
@@ -49,5 +49,5 @@
49
49
  "test": "vitest",
50
50
  "test:coverage": "vitest --coverage"
51
51
  },
52
- "version": "1.0.21"
52
+ "version": "1.0.23"
53
53
  }