@hairy/react-lib 1.47.0 → 1.50.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.
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT Hairyf <https://github.com/hairyf>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,36 +1,258 @@
1
- # @hairy/react-lib
2
-
3
- [![npm version][npm-version-src]][npm-version-href]
4
- [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
- [![bundle][bundle-src]][bundle-href]
6
- [![JSDocs][jsdocs-src]][jsdocs-href]
7
- [![License][license-src]][license-href]
8
-
9
- ## Install
10
-
11
- ```
12
- ni @hairy/react-lib
13
- ```
14
-
15
- ## CDN
16
-
17
- ```html
18
- <script src="https://unpkg.com/@hairy/react-lib"></script>
19
- ```
20
-
21
- ## License
22
-
23
- [MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
24
-
25
- <!-- Badges -->
26
-
27
- [npm-version-src]: https://img.shields.io/npm/v/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669
28
- [npm-version-href]: https://npmjs.com/package/@hairy/react-lib
29
- [npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669
30
- [npm-downloads-href]: https://npmjs.com/package/@hairy/react-lib
31
- [bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
32
- [bundle-href]: https://bundlephobia.com/result?p=@hairy/react-lib
33
- [license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
34
- [license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
35
- [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
36
- [jsdocs-href]: https://www.jsdocs.io/package/@hairy/react-lib
1
+ # @hairy/react-lib
2
+
3
+ <!-- automd:badges name="@hairy/react-lib" github="hairyf/hairylib" license bundlephobia -->
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@hairy/react-lib)](https://npmjs.com/package/@hairy/react-lib)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@hairy/react-lib)](https://npm.chart.dev/@hairy/react-lib)
7
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@hairy/react-lib)](https://bundlephobia.com/package/@hairy/react-lib)
8
+ [![license](https://img.shields.io/github/license/hairyf/hairylib)](https://github.com/hairyf/hairylib/blob/main/LICENSE)
9
+
10
+ <!-- /automd -->
11
+
12
+ React hooks and utilities for building applications.
13
+
14
+ ## Install
15
+
16
+ <!-- automd:pm-install name="@hairy/react-lib" -->
17
+
18
+ ```sh
19
+ # ✨ Auto-detect
20
+ npx nypm install @hairy/react-lib
21
+
22
+ # npm
23
+ npm install @hairy/react-lib
24
+
25
+ # yarn
26
+ yarn add @hairy/react-lib
27
+
28
+ # pnpm
29
+ pnpm add @hairy/react-lib
30
+
31
+ # bun
32
+ bun install @hairy/react-lib
33
+
34
+ # deno
35
+ deno install npm:@hairy/react-lib
36
+ ```
37
+
38
+ <!-- /automd -->
39
+
40
+ ## API
41
+
42
+ <!-- automd:jsdocs src="./src/index.ts" -->
43
+
44
+ ### `Case(props)`
45
+
46
+ ### `cls()`
47
+
48
+ A simple JavaScript utility for conditionally joining classNames together.
49
+
50
+ ### `Default(props)`
51
+
52
+ ### `Else(props)`
53
+
54
+ ### `If(props)`
55
+
56
+ ### `Injector(props)`
57
+
58
+ ### `Switch(props)`
59
+
60
+ ### `Then(props)`
61
+
62
+ ### `track(fn)`
63
+
64
+ **Example:**
65
+
66
+ ```tsx
67
+ // Obtain externally
68
+ import { track } from '@hairy/lib-react'
69
+ const context = await track(() => useContext(YourContext))
70
+ console.log(context) // { ... }
71
+ ```
72
+
73
+ ### `Trigger()`
74
+
75
+ **Example:**
76
+
77
+ ```tsx
78
+ import { Trigger } from '@hairy/lib-react'
79
+
80
+ // Use triggers to capture context
81
+ function App() {
82
+ return (
83
+ <YourContext.Provider>
84
+ <Trigger />
85
+ </YourContext.Provider>
86
+ )
87
+ }
88
+
89
+ // Obtain externally
90
+ import { track } from '@hairy/lib-react'
91
+ const context = await track(() => useContext(YourContext))
92
+ console.log(context) // { ... }
93
+ ```
94
+
95
+ ### `tryUseCallback(callback, deps)`
96
+
97
+ ### `tryUseEffect(effect, deps)`
98
+
99
+ ### `tryUseInsertionEffect(callback, deps)`
100
+
101
+ ### `tryUseReducer(reducer, initializerArg, initializer?)`
102
+
103
+ ### `tryUseRef(initialValue?)`
104
+
105
+ ### `tryUseState(initialState?)`
106
+
107
+ ### `tryUseUpdate()`
108
+
109
+ ### `Unless(props)`
110
+
111
+ ### `useAsyncCallback(fun)`
112
+
113
+ ### `useAsyncState(fun, deps, options?)`
114
+
115
+ ### `useDebounce(value, delay)`
116
+
117
+ ### `useEventBus(key)`
118
+
119
+ ### `useFetchRequestIntercept(intercept)`
120
+
121
+ ### `useFetchResponseIntercept(intercept)`
122
+
123
+ ### `useMounted()`
124
+
125
+ ### `useOffsetPagination(options)`
126
+
127
+ ### `useUpdate()`
128
+
129
+ ### `useWatch(source, callback, options)`
130
+
131
+ ### `useWhenever(source, cb, options?)`
132
+
133
+ ### `wrapper(asChild, props, children?)`
134
+
135
+ <!-- /automd -->
136
+
137
+ ## Directory structure
138
+
139
+ <!-- automd:dir-tree imports=""maxDepth=2 -->
140
+
141
+ ```
142
+ ├── src/
143
+ │ ├── components/
144
+ │ │ ├── condition/
145
+ │ │ │ ├── Case.ts
146
+ │ │ │ ├── Default.ts
147
+ │ │ │ ├── Else.ts
148
+ │ │ │ ├── If.ts
149
+ │ │ │ ├── index.ts
150
+ │ │ │ ├── Switch.ts
151
+ │ │ │ ├── Then.ts
152
+ │ │ │ └── Unless.ts
153
+ │ │ ├── utils/
154
+ │ │ │ ├── index.ts
155
+ │ │ │ ├── Injector.ts
156
+ │ │ │ └── Trigger.ts
157
+ │ │ └── index.ts
158
+ │ ├── hooks/
159
+ │ │ ├── types/
160
+ │ │ │ └── index.ts
161
+ │ │ ├── index.ts
162
+ │ │ ├── tryUseCallback.ts
163
+ │ │ ├── tryUseEffect.ts
164
+ │ │ ├── tryUseInsertionEffect.ts
165
+ │ │ ├── tryUseReducer.ts
166
+ │ │ ├── tryUseRef.ts
167
+ │ │ ├── tryUseState.ts
168
+ │ │ ├── tryUseUpdate.ts
169
+ │ │ ├── useAsyncCallback.ts
170
+ │ │ ├── useAsyncState.ts
171
+ │ │ ├── useDebounce.ts
172
+ │ │ ├── useEventBus.ts
173
+ │ │ ├── useFetchIntercept.ts
174
+ │ │ ├── useMounted.ts
175
+ │ │ ├── useOffsetPagination.ts
176
+ │ │ ├── usePrevious.ts
177
+ │ │ ├── useUpdate.ts
178
+ │ │ ├── useWatch.ts
179
+ │ │ └── useWhenever.ts
180
+ │ ├── types/
181
+ │ │ ├── html-parse-stringify.d.ts
182
+ │ │ └── index.ts
183
+ │ ├── utils/
184
+ │ │ ├── cls.ts
185
+ │ │ ├── index.ts
186
+ │ │ ├── track.ts
187
+ │ │ └── wrapper.ts
188
+ │ └── index.ts
189
+ ├── test/
190
+ │ └── index.test.ts
191
+ ├── package.json
192
+ ├── README.md
193
+ └── tsdown.config.ts
194
+ ```
195
+
196
+ <!-- /automd -->
197
+
198
+ ## Source
199
+
200
+ <!-- automd:file src="./src/index.ts" code lang="ts" -->
201
+
202
+ ```ts [index.ts]
203
+ export * from './components'
204
+ export * from './hooks'
205
+ export * from './types'
206
+ export * from './utils'
207
+ ```
208
+
209
+ <!-- /automd -->
210
+
211
+ ## Contributors
212
+
213
+ <!-- automd:contributors github="hairyf/hairylib" author="Hairyf" license="MIT" -->
214
+
215
+ Published under the [MIT](https://github.com/hairyf/hairylib/blob/main/LICENSE) license.
216
+ Made by [@Hairyf](https://github.com/Hairyf) and [community](https://github.com/hairyf/hairylib/graphs/contributors) 💛
217
+ <br><br>
218
+ <a href="https://github.com/hairyf/hairylib/graphs/contributors">
219
+ <img src="https://contrib.rocks/image?repo=hairyf/hairylib" />
220
+ </a>
221
+
222
+ <!-- /automd -->
223
+
224
+ ## License
225
+
226
+ <!-- automd:fetch url="gh:hairyf/hairylib/main/LICENSE" -->
227
+
228
+ MIT License
229
+
230
+ Copyright (c) 2025-PRESENT Hairyf <https://github.com/hairyf>
231
+
232
+ Permission is hereby granted, free of charge, to any person obtaining a copy
233
+ of this software and associated documentation files (the "Software"), to deal
234
+ in the Software without restriction, including without limitation the rights
235
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
236
+ copies of the Software, and to permit persons to whom the Software is
237
+ furnished to do so, subject to the following conditions:
238
+
239
+ The above copyright notice and this permission notice shall be included in all
240
+ copies or substantial portions of the Software.
241
+
242
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
243
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
244
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
245
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
246
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
247
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
248
+ SOFTWARE.
249
+
250
+ <!-- /automd -->
251
+
252
+ <!-- automd:with-automd -->
253
+
254
+ ---
255
+
256
+ _🤖 auto updated with [automd](https://automd.unjs.io)_
257
+
258
+ <!-- /automd -->