uni-types 1.0.0-beta.0 → 1.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,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 saqqdy <saqqdy@qq.com>
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 ADDED
@@ -0,0 +1,274 @@
1
+ <div align="center">
2
+
3
+ # uni-types
4
+
5
+ **Universal TypeScript Type Utilities**
6
+
7
+ A comprehensive collection of type helpers for TypeScript development
8
+
9
+ [![NPM version][npm-image]][npm-url]
10
+ [![NPM downloads][download-image]][download-url]
11
+ ![TypeScript][typescript-url]
12
+ [![Codecov][codecov-image]][codecov-url]
13
+ [![License][license-image]][license-url]
14
+
15
+ [**Documentation**](https://saqqdy.github.io/uni-types/) · [**中文文档**](./README_CN.md)
16
+
17
+ </div>
18
+
19
+ ## Features
20
+
21
+ - 🎯 **100+ Type Utilities** - Comprehensive type helpers for every use case
22
+ - 🔒 **Type Safe** - Full TypeScript support with strict type checking
23
+ - 📦 **Zero Dependencies** - Lightweight and tree-shakeable
24
+ - 🚀 **TypeScript 5.x** - Built with the latest TypeScript features
25
+ - 🌍 **Bilingual Docs** - Documentation in English and Chinese
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ # pnpm
31
+ pnpm add uni-types
32
+
33
+ # yarn
34
+ yarn add uni-types
35
+
36
+ # npm
37
+ npm install uni-types
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ```typescript
43
+ import type {
44
+ PickRequired,
45
+ DeepPartial,
46
+ IsArray,
47
+ Brand,
48
+ If,
49
+ Paths
50
+ } from 'uni-types'
51
+
52
+ // Core: Make specific properties required
53
+ interface User {
54
+ name?: string
55
+ age?: number
56
+ email: string
57
+ }
58
+
59
+ type RequiredUser = PickRequired<User, 'name' | 'age'>
60
+ // { name: string; age: number; email: string }
61
+
62
+ // Deep: Make all nested properties optional
63
+ interface Config {
64
+ database: {
65
+ host: string
66
+ port: number
67
+ }
68
+ }
69
+
70
+ type PartialConfig = DeepPartial<Config>
71
+ // { database?: { host?: string; port?: number } }
72
+
73
+ // Brand: Create nominal types
74
+ type UserId = Brand<string, 'UserId'>
75
+ type OrderId = Brand<string, 'OrderId'>
76
+ // UserId and OrderId are not interchangeable!
77
+
78
+ // Conditional: Type-level logic
79
+ type Result = If<true, 'success', 'error'> // 'success'
80
+ ```
81
+
82
+ ## API Reference
83
+
84
+ ### Core Operations
85
+
86
+ | Type | Description |
87
+ |------|-------------|
88
+ | `PickRequired<T, K>` | Make specified properties required |
89
+ | `OmitRequired<T, K>` | Make properties except specified ones required |
90
+ | `PickPartial<T, K>` | Make specified properties optional |
91
+ | `OmitPartial<T, K>` | Make properties except specified ones optional |
92
+
93
+ ### Tuple Operations
94
+
95
+ | Type | Description |
96
+ |------|-------------|
97
+ | `Head<T>` | Get first element of tuple |
98
+ | `Last<T>` | Get last element of tuple |
99
+ | `Tail<T>` | Get all elements except first |
100
+ | `Init<T>` | Get all elements except last |
101
+ | `Reverse<T>` | Reverse a tuple |
102
+ | `Flatten<T>` | Flatten nested tuples |
103
+ | `TupleLength<T>` | Get tuple length |
104
+ | `IsEmptyTuple<T>` | Check if tuple is empty |
105
+
106
+ ### Deep Operations
107
+
108
+ | Type | Description |
109
+ |------|-------------|
110
+ | `DeepPartial<T>` | Make all nested properties optional |
111
+ | `DeepRequired<T>` | Make all nested properties required |
112
+ | `DeepReadonly<T>` | Make all nested properties readonly |
113
+ | `DeepMutable<T>` | Make all nested properties mutable |
114
+ | `DeepOmit<T, P>` | Omit properties by path |
115
+ | `DeepPick<T, P>` | Pick properties by path |
116
+
117
+ ### Type Guards
118
+
119
+ | Type | Description |
120
+ |------|-------------|
121
+ | `IsArray<T>` | Check if type is an array |
122
+ | `IsTuple<T>` | Check if type is a tuple |
123
+ | `IsEqual<X, Y>` | Check if two types are equal |
124
+ | `IsAny<T>` | Check if type is `any` |
125
+ | `IsNever<T>` | Check if type is `never` |
126
+ | `IsUnknown<T>` | Check if type is `unknown` |
127
+ | `IsFunction<T>` | Check if type is a function |
128
+ | `IsAsyncFunction<T>` | Check if type is an async function |
129
+
130
+ ### Conditional Types *(v1.1.0)*
131
+
132
+ | Type | Description |
133
+ |------|-------------|
134
+ | `If<C, T, F>` | Type-level if-then-else |
135
+ | `Not<B>` | Logical NOT for boolean types |
136
+ | `And<A, B>` | Logical AND for boolean types |
137
+ | `Or<A, B>` | Logical OR for boolean types |
138
+ | `Assert<T, U>` | Type constraint assertion |
139
+
140
+ ### Brand Types *(v1.1.0)*
141
+
142
+ | Type | Description |
143
+ |------|-------------|
144
+ | `Brand<T, B>` | Create a branded type for nominal typing |
145
+ | `Unbrand<T>` | Extract underlying type from branded type |
146
+
147
+ ### Function Utilities *(v1.1.0)*
148
+
149
+ | Type | Description |
150
+ |------|-------------|
151
+ | `Parameters<T>` | Get function parameters as tuple |
152
+ | `ReturnType<T>` | Get function return type |
153
+ | `NthParameter<T, N>` | Get Nth parameter type |
154
+ | `AsyncReturnType<T>` | Extract async function return type |
155
+ | `ThisParameterType<T>` | Get `this` parameter type |
156
+ | `OmitThisParameter<T>` | Omit `this` parameter from function |
157
+
158
+ ### Template Literal Utilities *(v1.1.0)*
159
+
160
+ | Type | Description |
161
+ |------|-------------|
162
+ | `ReplaceAll<S, From, To>` | Replace all occurrences |
163
+ | `Replace<S, From, To>` | Replace first occurrence |
164
+ | `Trim<S>` | Trim whitespace |
165
+ | `StringToArray<S>` | Convert string to array |
166
+ | `CapitalizeAll<S>` | Capitalize all words |
167
+ | `StartsWith<S, P>` | Check if string starts with prefix |
168
+ | `EndsWith<S, P>` | Check if string ends with suffix |
169
+ | `StringLength<S>` | Get string length |
170
+
171
+ ### Numeric Utilities *(v1.1.0)*
172
+
173
+ | Type | Description |
174
+ |------|-------------|
175
+ | `Inc<N>` | Increment number |
176
+ | `Dec<N>` | Decrement number |
177
+ | `Add<A, B>` | Add two numbers |
178
+ | `Subtract<A, B>` | Subtract two numbers |
179
+ | `GreaterThan<A, B>` | Check if A > B |
180
+ | `LessThan<A, B>` | Check if A < B |
181
+ | `Max<A, B>` | Maximum of two numbers |
182
+ | `Min<A, B>` | Minimum of two numbers |
183
+
184
+ ### Path Types
185
+
186
+ | Type | Description |
187
+ |------|-------------|
188
+ | `Paths<T>` | Get all nested property paths |
189
+ | `PathValue<T, P>` | Get value type at path |
190
+ | `ValidPath<T, P>` | Check if path is valid |
191
+ | `ArrayPaths<T>` | Get paths including array indices |
192
+ | `LeafPaths<T>` | Get paths to primitive values |
193
+
194
+ ### Key Utilities *(v1.1.0)*
195
+
196
+ | Type | Description |
197
+ |------|-------------|
198
+ | `Keys<T>` | Get all keys |
199
+ | `RenameKeys<T, M>` | Rename keys based on mapping |
200
+ | `PrefixKeys<T, P>` | Add prefix to all keys |
201
+ | `SuffixKeys<T, S>` | Add suffix to all keys |
202
+ | `KeysByValueType<T, V>` | Get keys by value type |
203
+
204
+ ### Record Utilities *(v1.1.0)*
205
+
206
+ | Type | Description |
207
+ |------|-------------|
208
+ | `DeepNullable<T>` | Make all properties nullable |
209
+ | `DeepOptional<T>` | Make all properties optional |
210
+ | `Immutable<T>` | Make all properties readonly |
211
+ | `Mutable<T>` | Make all properties mutable |
212
+ | `DeepNonNullable<T>` | Remove null/undefined from all properties |
213
+ | `Exact<T, Shape>` | Ensure exact shape match |
214
+
215
+ ## Examples
216
+
217
+ ```typescript
218
+ import type {
219
+ SnakeCase,
220
+ CamelCaseKeys,
221
+ UnionToIntersection,
222
+ AtLeastOne
223
+ } from 'uni-types'
224
+
225
+ // String case conversion
226
+ SnakeCase<'XMLParser'> // 'xml_parser'
227
+ CamelCaseKeys<{ user_name: string, user_age: number }>
228
+ // { userName: string, userAge: number }
229
+
230
+ // Union to intersection
231
+ UnionToIntersection<{ a: string } | { b: number }>
232
+ // { a: string } & { b: number }
233
+
234
+ // Require at least one property
235
+ type Options = AtLeastOne<{ a?: string; b?: number; c?: boolean }>
236
+ // Must have at least one of a, b, or c
237
+ ```
238
+
239
+ ## Development
240
+
241
+ ```bash
242
+ # Install dependencies
243
+ pnpm install
244
+
245
+ # Run tests
246
+ pnpm test
247
+
248
+ # Build
249
+ pnpm build
250
+
251
+ # Type check
252
+ pnpm typecheck
253
+
254
+ # Start docs dev server
255
+ pnpm docs:dev
256
+ ```
257
+
258
+ ## Contributing
259
+
260
+ Contributions are welcome! Please read our [Contributing Guide](./CONTRIBUTING.md) for details.
261
+
262
+ ## License
263
+
264
+ [MIT](LICENSE) © [saqqdy](https://github.com/saqqdy)
265
+
266
+ [npm-image]: https://img.shields.io/npm/v/uni-types.svg?style=flat-square
267
+ [npm-url]: https://npmjs.org/package/uni-types
268
+ [typescript-url]: https://img.shields.io/badge/TypeScript-5.x-3178c6?style=flat-square&logo=typescript&logoColor=white
269
+ [codecov-image]: https://img.shields.io/codecov/c/github/saqqdy/uni-types.svg?style=flat-square
270
+ [codecov-url]: https://codecov.io/github/saqqdy/uni-types
271
+ [download-image]: https://img.shields.io/npm/dm/uni-types.svg?style=flat-square
272
+ [download-url]: https://npmjs.org/package/uni-types
273
+ [license-image]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square
274
+ [license-url]: LICENSE