use-good-hooks 1.0.20 → 1.0.22

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