typetify 0.1.2 → 0.1.3
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 +43 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Typetify
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/typetify)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -12,27 +12,26 @@
|
|
|
12
12
|
|
|
13
13
|
TypeScript is powerful, but it doesn't protect you at runtime. **Typetify** fills this gap with type-safe utilities that work when it matters most.
|
|
14
14
|
|
|
15
|
-
<img src="
|
|
16
|
-
|
|
17
|
-
[Documentation](#modules) | [Installation](#installation) | [Examples](#quick-start)
|
|
15
|
+
<img src="https://typetify.hosby.io/typetify-1.png" alt="Typetify Logo" width="300" />
|
|
18
16
|
|
|
17
|
+
[Documentation](https://typetify.hosby.io)
|
|
19
18
|
</div>
|
|
20
19
|
|
|
21
20
|
---
|
|
22
21
|
|
|
23
|
-
##
|
|
22
|
+
## Features
|
|
24
23
|
|
|
25
24
|
<table>
|
|
26
25
|
<tr>
|
|
27
26
|
<td width="50%">
|
|
28
27
|
|
|
29
|
-
###
|
|
28
|
+
### Runtime Safety
|
|
30
29
|
Guards and assertions that protect you when TypeScript can't — at runtime, where it matters.
|
|
31
30
|
|
|
32
31
|
</td>
|
|
33
32
|
<td width="50%">
|
|
34
33
|
|
|
35
|
-
###
|
|
34
|
+
### Perfect Types
|
|
36
35
|
IntelliSense that actually helps. Every function is designed for maximum type inference.
|
|
37
36
|
|
|
38
37
|
</td>
|
|
@@ -40,26 +39,26 @@ IntelliSense that actually helps. Every function is designed for maximum type in
|
|
|
40
39
|
<tr>
|
|
41
40
|
<td width="50%">
|
|
42
41
|
|
|
43
|
-
###
|
|
42
|
+
### Zero Dependencies
|
|
44
43
|
Lightweight and tree-shakable. Only bundle what you use.
|
|
45
44
|
|
|
46
45
|
</td>
|
|
47
46
|
<td width="50%">
|
|
48
47
|
|
|
49
|
-
###
|
|
48
|
+
### No Magic
|
|
50
49
|
Boring, predictable API. No config, no setup, just functions that work.
|
|
51
50
|
|
|
52
51
|
</td>
|
|
53
52
|
</tr>
|
|
54
53
|
</table>
|
|
55
54
|
|
|
56
|
-
##
|
|
55
|
+
## Installation
|
|
57
56
|
|
|
58
57
|
```bash
|
|
59
58
|
npm install typetify
|
|
60
59
|
```
|
|
61
60
|
|
|
62
|
-
##
|
|
61
|
+
## Quick Start
|
|
63
62
|
|
|
64
63
|
```typescript
|
|
65
64
|
import { isDefined, pick, awaitTo, safeJsonParse } from 'typetify'
|
|
@@ -89,9 +88,29 @@ if (result.ok) {
|
|
|
89
88
|
}
|
|
90
89
|
```
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
### Using Underscore `_` (Lodash-style)
|
|
92
|
+
|
|
93
|
+
If you have naming conflicts with existing functions, use the underscore `_` namespace:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// Import with underscore _ (just like Lodash!)
|
|
97
|
+
import { _ } from 'typetify'
|
|
98
|
+
|
|
99
|
+
// Use _.methodName() to avoid conflicts
|
|
100
|
+
const defined = items.filter(_.isDefined)
|
|
101
|
+
const safe = _.pick(user, ['id', 'name'])
|
|
102
|
+
const [error, data] = await _.awaitTo(fetchUser(id))
|
|
103
|
+
|
|
104
|
+
// Also works with default import
|
|
105
|
+
import _ from 'typetify'
|
|
106
|
+
|
|
107
|
+
// Or import * as
|
|
108
|
+
import * as _ from 'typetify'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Modules
|
|
93
112
|
|
|
94
|
-
###
|
|
113
|
+
### Core — Foundations
|
|
95
114
|
|
|
96
115
|
```typescript
|
|
97
116
|
import { isDefined, isNil, assert, assertDefined, fail, noop, identity, unreachable } from 'typetify/core'
|
|
@@ -112,7 +131,7 @@ switch (status) {
|
|
|
112
131
|
}
|
|
113
132
|
```
|
|
114
133
|
|
|
115
|
-
###
|
|
134
|
+
### Guards — Type Guards
|
|
116
135
|
|
|
117
136
|
```typescript
|
|
118
137
|
import { isObject, isString, isNumber, hasKey, hasKeys, isEmpty } from 'typetify/guards'
|
|
@@ -134,7 +153,7 @@ isEmpty({}) // true
|
|
|
134
153
|
isEmpty(null) // true
|
|
135
154
|
```
|
|
136
155
|
|
|
137
|
-
###
|
|
156
|
+
### Object — Object Manipulation
|
|
138
157
|
|
|
139
158
|
```typescript
|
|
140
159
|
import { pick, omit, keysTyped, mapObject, get, set } from 'typetify/object'
|
|
@@ -156,7 +175,7 @@ get(user, ['profile', 'name'])
|
|
|
156
175
|
set(user, ['profile', 'age'], 30)
|
|
157
176
|
```
|
|
158
177
|
|
|
159
|
-
###
|
|
178
|
+
### Async — Async Utilities
|
|
160
179
|
|
|
161
180
|
```typescript
|
|
162
181
|
import { awaitTo, retry, sleep, withTimeout, debounce, throttle, parallel } from 'typetify/async'
|
|
@@ -185,7 +204,7 @@ const debouncedSearch = debounce(search, 300)
|
|
|
185
204
|
const throttledScroll = throttle(onScroll, 100)
|
|
186
205
|
```
|
|
187
206
|
|
|
188
|
-
###
|
|
207
|
+
### Collection — Array Utilities
|
|
189
208
|
|
|
190
209
|
```typescript
|
|
191
210
|
import { unique, groupBy, partition, chunk, compact, sortBy, range } from 'typetify/collection'
|
|
@@ -214,7 +233,7 @@ sortBy(users, u => u.name)
|
|
|
214
233
|
range(0, 5) // [0, 1, 2, 3, 4]
|
|
215
234
|
```
|
|
216
235
|
|
|
217
|
-
###
|
|
236
|
+
### Input — Parse External Data
|
|
218
237
|
|
|
219
238
|
```typescript
|
|
220
239
|
import { safeJsonParse, parseNumber, parseBoolean, parseDate, coerceArray, defaults } from 'typetify/input'
|
|
@@ -241,7 +260,7 @@ defaults(null, 'fallback') // 'fallback'
|
|
|
241
260
|
defaults('', 'fallback') // 'fallback'
|
|
242
261
|
```
|
|
243
262
|
|
|
244
|
-
###
|
|
263
|
+
### Flow — Functional Utilities
|
|
245
264
|
|
|
246
265
|
```typescript
|
|
247
266
|
import { pipe, tap, when, match, tryCatch, ifElse } from 'typetify/flow'
|
|
@@ -274,7 +293,7 @@ if (result.ok) {
|
|
|
274
293
|
}
|
|
275
294
|
```
|
|
276
295
|
|
|
277
|
-
###
|
|
296
|
+
### DX — Developer Experience
|
|
278
297
|
|
|
279
298
|
```typescript
|
|
280
299
|
import { debug, invariant, assertNever, todo, measure } from 'typetify/dx'
|
|
@@ -334,7 +353,7 @@ type PartialUser = DeepPartial<User>
|
|
|
334
353
|
type MergedConfig = Merge<DefaultConfig, UserConfig>
|
|
335
354
|
```
|
|
336
355
|
|
|
337
|
-
##
|
|
356
|
+
## Tree Shaking
|
|
338
357
|
|
|
339
358
|
Import only what you need:
|
|
340
359
|
|
|
@@ -347,17 +366,17 @@ import { pick } from 'typetify/object'
|
|
|
347
366
|
import { isDefined, pick, awaitTo } from 'typetify'
|
|
348
367
|
```
|
|
349
368
|
|
|
350
|
-
##
|
|
369
|
+
## Philosophy
|
|
351
370
|
|
|
352
371
|
1. **Runtime first** — Types are great, but runtime safety matters more
|
|
353
372
|
2. **No magic** — Every function does exactly what it says
|
|
354
373
|
3. **Composable** — Small functions that work together
|
|
355
374
|
4. **TypeScript-native** — Built for TS, not ported from JS
|
|
356
375
|
|
|
357
|
-
##
|
|
376
|
+
## Contributing
|
|
358
377
|
|
|
359
378
|
Contributions are welcome! Please read our contributing guidelines first.
|
|
360
379
|
|
|
361
|
-
##
|
|
380
|
+
## License
|
|
362
381
|
|
|
363
382
|
MIT © typetify
|