@ts-hooks-kit/core 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ This project is based on usehooks-ts (https://github.com/juliencrn/usehooks-ts) by Julien CARON, also licensed under MIT.
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2025-present Naufaldi Rafif S
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @ts-hooks-kit/core
2
+
3
+ An actively maintained React hooks library based on usehooks-ts, upgraded for React 18/19 compatibility.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@ts-hooks-kit/core)](https://www.npmjs.com/package/@ts-hooks-kit/core)
6
+ [![license](https://img.shields.io/npm/l/@ts-hooks-kit/core)](https://github.com/naufaldi/ts-hooks-kit/blob/master/LICENSE)
7
+ [![CI](https://github.com/naufaldi/ts-hooks-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/naufaldi/ts-hooks-kit/actions/workflows/ci.yml)
8
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@ts-hooks-kit/core)](https://bundlephobia.com/package/@ts-hooks-kit/core)
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @ts-hooks-kit/core
14
+ # or
15
+ pnpm add @ts-hooks-kit/core
16
+ # or
17
+ yarn add @ts-hooks-kit/core
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ```tsx
23
+ import { useBoolean, useLocalStorage } from '@ts-hooks-kit/core'
24
+
25
+ export function Example() {
26
+ const [enabled, toggleEnabled] = useBoolean(false)
27
+ const [name, setName] = useLocalStorage('name', 'ts-hooks-kit')
28
+
29
+ return (
30
+ <button type="button" onClick={toggleEnabled}>
31
+ {enabled ? `Enabled for ${name}` : 'Disabled'}
32
+ </button>
33
+ )
34
+ }
35
+ ```
36
+
37
+ ## Features
38
+
39
+ - **50 hooks** ready for production use
40
+ - **React ^18 || ^19** — CI-tested on both versions
41
+ - **TypeScript-first** — full type inference, exported types for all hooks
42
+ - **Zero runtime dependencies** — React as peer dependency only
43
+ - **ESM + CJS** — dual output via tsdown, tree-shakeable (`sideEffects: false`)
44
+ - **SSR-safe** — server guards on browser-dependent hooks
45
+
46
+ ## Hooks
47
+
48
+ ### State & Lifecycle
49
+
50
+ | Hook | Description |
51
+ |------|-------------|
52
+ | `useBoolean` | Boolean state with toggle/set helpers |
53
+ | `useCounter` | Numeric counter with increment/decrement/set/reset |
54
+ | `useList` | Enhanced array state management |
55
+ | `useMap` | Reactive Map data structure |
56
+ | `useSet` | Reactive Set data structure |
57
+ | `useQueue` | FIFO queue data structure |
58
+ | `useToggle` | Toggle between two values |
59
+ | `useStep` | Step-based state navigation |
60
+ | `useStateList` | Navigate through a list of states |
61
+ | `usePrevious` | Track previous state/prop value |
62
+ | `useDisclosure` | Modal/drawer open/close/toggle state |
63
+ | `usePagination` | Pagination logic with range generation |
64
+ | `useUpdate` | Force component re-render |
65
+ | `useUnmount` | Run cleanup on unmount |
66
+ | `useIsMounted` | Check if component is mounted |
67
+ | `useIsClient` | Check if running on client side |
68
+
69
+ ### Effects & Callbacks
70
+
71
+ | Hook | Description |
72
+ |------|-------------|
73
+ | `useUpdateEffect` | useEffect that skips initial mount |
74
+ | `useEventCallback` | Stable callback reference |
75
+ | `useMemoizedFn` | Stable function reference without deps |
76
+ | `useIsomorphicLayoutEffect` | SSR-safe useLayoutEffect |
77
+ | `useAsync` | Async function state with loading/error/retry |
78
+
79
+ ### Timing & Debounce
80
+
81
+ | Hook | Description |
82
+ |------|-------------|
83
+ | `useDebounceCallback` | Debounced callback with cancel/flush |
84
+ | `useDebounceValue` | Debounced value |
85
+ | `useThrottle` | Throttle execution (fn + value variants) |
86
+ | `useTimeout` | setTimeout with auto-cleanup |
87
+ | `useInterval` | setInterval with auto-cleanup |
88
+ | `useCountdown` | Countdown timer |
89
+ | `useIdle` | Detect user idle state |
90
+
91
+ ### DOM & Browser
92
+
93
+ | Hook | Description |
94
+ |------|-------------|
95
+ | `useEventListener` | Type-safe event listener binding |
96
+ | `useClickAnyWhere` | Detect clicks anywhere on the page |
97
+ | `useOnClickOutside` | Detect clicks outside an element |
98
+ | `useHover` | Detect hover state |
99
+ | `useIntersectionObserver` | Intersection Observer API wrapper |
100
+ | `useResizeObserver` | Resize Observer API wrapper |
101
+ | `useScrollLock` | Lock body scroll |
102
+ | `useDocumentTitle` | Set document title |
103
+ | `useScript` | Dynamic script loading |
104
+ | `useWindowSize` | Track window dimensions |
105
+ | `useScreen` | Track screen properties |
106
+ | `usePageLeave` | Detect when user leaves page |
107
+
108
+ ### Storage
109
+
110
+ | Hook | Description |
111
+ |------|-------------|
112
+ | `useLocalStorage` | Persistent state in localStorage |
113
+ | `useSessionStorage` | Persistent state in sessionStorage |
114
+ | `useReadLocalStorage` | Read-only localStorage access |
115
+ | `useCopyToClipboard` | Copy text to clipboard |
116
+
117
+ ### Media & Network
118
+
119
+ | Hook | Description |
120
+ |------|-------------|
121
+ | `useMediaQuery` | Responsive media query matching |
122
+ | `useDarkMode` | Dark mode toggle |
123
+ | `useTernaryDarkMode` | Dark/light/system mode |
124
+ | `useNetwork` | Network status monitoring |
125
+ | `useGeolocation` | Browser geolocation API |
126
+ | `usePermission` | Browser permissions API |
127
+
128
+ ## Migrating from usehooks-ts
129
+
130
+ This package is API-compatible with `usehooks-ts@3.1.1`. To migrate, change your imports:
131
+
132
+ ```ts
133
+ // before
134
+ import { useLocalStorage } from 'usehooks-ts'
135
+
136
+ // after
137
+ import { useLocalStorage } from '@ts-hooks-kit/core'
138
+ ```
139
+
140
+ A codemod is available for automated migration — see the [migration guide](https://github.com/naufaldi/ts-hooks-kit/blob/master/docs/migration.md).
141
+
142
+ ## License
143
+
144
+ MIT — see [LICENSE](./LICENSE) for details.
145
+
146
+ Based on [usehooks-ts](https://github.com/juliencrn/usehooks-ts) by [Julien CARON](https://github.com/juliencrn).