use-good-hooks 1.0.0 → 1.0.2
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.
- package/README.md +0 -1
- package/dist/index.d.ts +56 -0
- package/dist/index.mjs +2720 -0
- package/package.json +5 -7
- package/dist-export/index.d.ts +0 -1
- package/dist-export/index.js +0 -192
package/package.json
CHANGED
|
@@ -30,10 +30,9 @@
|
|
|
30
30
|
"vitest": "^3.0.7"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
|
-
"dist
|
|
33
|
+
"dist"
|
|
34
34
|
],
|
|
35
|
-
"main": "dist
|
|
36
|
-
"module": "index.ts",
|
|
35
|
+
"main": "dist/index.js",
|
|
37
36
|
"name": "use-good-hooks",
|
|
38
37
|
"peerDependencies": {
|
|
39
38
|
"lodash": "^4.17.21",
|
|
@@ -41,12 +40,11 @@
|
|
|
41
40
|
"react-dom": "^19.0.0"
|
|
42
41
|
},
|
|
43
42
|
"scripts": {
|
|
44
|
-
"build": "vite build",
|
|
45
|
-
"build:export": "yarn lint && yarn build --outDir ./dist-export --mode export",
|
|
43
|
+
"build": "yarn lint && vite build --mode export",
|
|
46
44
|
"dev": "vite",
|
|
47
45
|
"lint": "prettier --write . && eslint .",
|
|
46
|
+
"npm-publish": "yarn test --run && yarn build && yarn version --patch --no-git-tag-version && yarn publish --non-interactive",
|
|
48
47
|
"test": "vitest"
|
|
49
48
|
},
|
|
50
|
-
"
|
|
51
|
-
"version": "1.0.0"
|
|
49
|
+
"version": "1.0.2"
|
|
52
50
|
}
|
package/dist-export/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|
package/dist-export/index.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import t from "lodash";
|
|
2
|
-
import { useState as S, useRef as b, useEffect as y, useCallback as D } from "react";
|
|
3
|
-
import k from "use-json";
|
|
4
|
-
import w from "use-qs";
|
|
5
|
-
const _ = 300, R = (r, e = _) => {
|
|
6
|
-
const [l, d] = S(r), f = b(
|
|
7
|
-
t.debounce((p) => {
|
|
8
|
-
d(p);
|
|
9
|
-
}, e)
|
|
10
|
-
);
|
|
11
|
-
return y(() => {
|
|
12
|
-
f.current(r);
|
|
13
|
-
}, [r]), y(() => {
|
|
14
|
-
const p = f.current;
|
|
15
|
-
return () => {
|
|
16
|
-
p.cancel();
|
|
17
|
-
};
|
|
18
|
-
}, []), l;
|
|
19
|
-
}, B = (r, e) => r === e, M = (r, e = {}) => {
|
|
20
|
-
const l = b(!1), d = b(e), f = b(r), p = b(
|
|
21
|
-
t.debounce((i) => {
|
|
22
|
-
const { compare: o, deep: s } = d.current;
|
|
23
|
-
!(t.isFunction(o) ? o : s ? t.isEqual : B)(i, f.current) && (F({
|
|
24
|
-
distinct: !0,
|
|
25
|
-
prevValue: f.current,
|
|
26
|
-
value: i
|
|
27
|
-
}), f.current = i);
|
|
28
|
-
}, d.current.debounce ?? 0)
|
|
29
|
-
), [m, F] = S({
|
|
30
|
-
distinct: !1,
|
|
31
|
-
prevValue: void 0,
|
|
32
|
-
value: r
|
|
33
|
-
}), a = D(() => {
|
|
34
|
-
l.current = !1, F((i) => ({
|
|
35
|
-
...i,
|
|
36
|
-
distinct: !1
|
|
37
|
-
}));
|
|
38
|
-
}, []);
|
|
39
|
-
return y(() => {
|
|
40
|
-
if (m.distinct && l.current) {
|
|
41
|
-
a();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const i = p.current;
|
|
45
|
-
i(r);
|
|
46
|
-
}), y(() => {
|
|
47
|
-
m.distinct && (l.current = !0);
|
|
48
|
-
}, [m.distinct]), y(() => {
|
|
49
|
-
const i = p.current;
|
|
50
|
-
return () => {
|
|
51
|
-
i.cancel();
|
|
52
|
-
};
|
|
53
|
-
}, []), m;
|
|
54
|
-
}, O = (r) => {
|
|
55
|
-
const e = b(void 0);
|
|
56
|
-
return y(() => {
|
|
57
|
-
e.current = r;
|
|
58
|
-
}), e.current;
|
|
59
|
-
}, A = () => typeof window < "u", g = { browser: A }, K = 500, h = "local", U = (r, e) => t.isMap(e) ? {
|
|
60
|
-
__type: "Map",
|
|
61
|
-
value: Array.from(e.entries())
|
|
62
|
-
} : t.isSet(e) ? {
|
|
63
|
-
__type: "Set",
|
|
64
|
-
value: Array.from(e)
|
|
65
|
-
} : e, z = (r, e) => e && e.__type === "Map" ? new Map(e.value) : e && e.__type === "Set" ? new Set(e.value) : e, $ = (r, e, l) => {
|
|
66
|
-
const d = b(l || {}), f = b(!1), [p, m] = S(e), F = R(
|
|
67
|
-
p,
|
|
68
|
-
d.current.debounce ?? K
|
|
69
|
-
);
|
|
70
|
-
y(() => {
|
|
71
|
-
if (!g.browser() || !f.current)
|
|
72
|
-
return;
|
|
73
|
-
const {
|
|
74
|
-
storage: i = h,
|
|
75
|
-
onError: o,
|
|
76
|
-
omitKeys: s,
|
|
77
|
-
pickKeys: u
|
|
78
|
-
} = d.current, c = i === "local" ? localStorage : sessionStorage;
|
|
79
|
-
if (c)
|
|
80
|
-
try {
|
|
81
|
-
let n = F;
|
|
82
|
-
s && (t.size(s) || t.isFunction(s)) && (n = t.isFunction(s) ? t.omitBy(n, s) : t.omit(n, s)), u && (t.size(u) || t.isFunction(u)) && (n = t.isFunction(u) ? t.pickBy(n, u) : t.pick(n, u)), c.setItem(r, k.stringify(n, U));
|
|
83
|
-
} catch (n) {
|
|
84
|
-
o && o(n);
|
|
85
|
-
}
|
|
86
|
-
}, [r, F]), y(() => {
|
|
87
|
-
const {
|
|
88
|
-
storage: i = h,
|
|
89
|
-
omitKeys: o,
|
|
90
|
-
onError: s,
|
|
91
|
-
pickKeys: u
|
|
92
|
-
} = d.current;
|
|
93
|
-
try {
|
|
94
|
-
const c = i === "local" ? localStorage : sessionStorage, n = c == null ? void 0 : c.getItem(r);
|
|
95
|
-
if (n) {
|
|
96
|
-
let E = k.parse(n, z);
|
|
97
|
-
o && (t.size(o) || t.isFunction(o)) && (E = t.isFunction(o) ? t.omitBy(E, o) : t.omit(E, o)), u && (t.size(u) || t.isFunction(u)) && (E = t.isFunction(u) ? t.pickBy(E, u) : t.pick(E, u)), m(
|
|
98
|
-
t.isEmpty(E) ? e : t.merge({}, e, E)
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
} catch (c) {
|
|
102
|
-
s && s(c);
|
|
103
|
-
} finally {
|
|
104
|
-
f.current = !0;
|
|
105
|
-
}
|
|
106
|
-
}, []);
|
|
107
|
-
const a = D(() => {
|
|
108
|
-
if (!g.browser())
|
|
109
|
-
return;
|
|
110
|
-
m(e);
|
|
111
|
-
const { storage: i = h } = d.current, o = i === "local" ? localStorage : sessionStorage;
|
|
112
|
-
o == null || o.removeItem(r);
|
|
113
|
-
}, [r, e]);
|
|
114
|
-
return [p, m, { removeKey: a }];
|
|
115
|
-
}, C = 300, v = (r, e = C) => {
|
|
116
|
-
const [l, d] = S(r), f = b(
|
|
117
|
-
t.throttle((p) => {
|
|
118
|
-
d(p);
|
|
119
|
-
}, e)
|
|
120
|
-
);
|
|
121
|
-
return y(() => {
|
|
122
|
-
f.current(r);
|
|
123
|
-
}, [r]), y(() => {
|
|
124
|
-
const p = f.current;
|
|
125
|
-
return () => {
|
|
126
|
-
p.cancel();
|
|
127
|
-
};
|
|
128
|
-
}, []), l;
|
|
129
|
-
}, T = 500, x = (r, e) => {
|
|
130
|
-
const l = b(e), d = () => {
|
|
131
|
-
const {
|
|
132
|
-
kebabCase: F = !0,
|
|
133
|
-
omitKeys: a,
|
|
134
|
-
omitValues: i,
|
|
135
|
-
onError: o,
|
|
136
|
-
pickKeys: s,
|
|
137
|
-
prefix: u = "",
|
|
138
|
-
url: c
|
|
139
|
-
} = l.current;
|
|
140
|
-
if (!c.search)
|
|
141
|
-
return r;
|
|
142
|
-
try {
|
|
143
|
-
let n = w.parse(decodeURIComponent(c.search), {
|
|
144
|
-
case: F ? "kebab-case" : "camelCase",
|
|
145
|
-
omitValues: i,
|
|
146
|
-
prefix: u
|
|
147
|
-
});
|
|
148
|
-
return a && (t.size(a) || t.isFunction(a)) && (n = t.isFunction(a) ? t.omitBy(n, a) : t.omit(n, a)), s && (t.size(s) || t.isFunction(s)) && (n = t.isFunction(s) ? t.pickBy(n, s) : t.pick(n, s)), t.isEmpty(n) ? r : t.merge({}, r, n);
|
|
149
|
-
} catch (n) {
|
|
150
|
-
return o && o(n), r;
|
|
151
|
-
}
|
|
152
|
-
}, [f, p] = S(d), m = R(
|
|
153
|
-
f,
|
|
154
|
-
l.current.debounce ?? T
|
|
155
|
-
);
|
|
156
|
-
return y(() => {
|
|
157
|
-
if (!g.browser())
|
|
158
|
-
return;
|
|
159
|
-
const {
|
|
160
|
-
kebabCase: F = !0,
|
|
161
|
-
omitKeys: a,
|
|
162
|
-
omitValues: i,
|
|
163
|
-
onError: o,
|
|
164
|
-
pickKeys: s,
|
|
165
|
-
prefix: u = ""
|
|
166
|
-
} = l.current;
|
|
167
|
-
try {
|
|
168
|
-
let c = m;
|
|
169
|
-
a && (t.size(a) || t.isFunction(a)) && (c = t.isFunction(a) ? t.omitBy(c, a) : t.omit(c, a)), s && (t.size(s) || t.isFunction(s)) && (c = t.isFunction(s) ? t.pickBy(c, s) : t.pick(c, s));
|
|
170
|
-
const n = w.stringify(c, {
|
|
171
|
-
case: F ? "kebab-case" : "camelCase",
|
|
172
|
-
omitValues: i,
|
|
173
|
-
prefix: u
|
|
174
|
-
});
|
|
175
|
-
n ? window.history.replaceState(
|
|
176
|
-
{},
|
|
177
|
-
"",
|
|
178
|
-
`${window.location.pathname}${n}`
|
|
179
|
-
) : window.history.replaceState({}, "", window.location.pathname);
|
|
180
|
-
} catch (c) {
|
|
181
|
-
o && o(c);
|
|
182
|
-
}
|
|
183
|
-
}, [m]), [f, p];
|
|
184
|
-
};
|
|
185
|
-
export {
|
|
186
|
-
R as useDebounce,
|
|
187
|
-
M as useDistinct,
|
|
188
|
-
O as usePrev,
|
|
189
|
-
$ as useStorageState,
|
|
190
|
-
v as useThrottle,
|
|
191
|
-
x as useUrlState
|
|
192
|
-
};
|