@wistia/utils 0.0.0-stage → 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,159 @@
1
+ # @wistia/utils
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#280](https://github.com/wistia/utils/pull/280) [`4201db5`](https://github.com/wistia/utils/commit/4201db5b2561fa55400a97ae8fd0446d96b0e725) Thanks [@okize](https://github.com/okize)! - feat!: drop commonJS support (ESM only)
8
+
9
+ ## 0.17.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#275](https://github.com/wistia/type-guards/pull/275) [`feabe44`](https://github.com/wistia/type-guards/commit/feabe441245825095c43ed58a37bdf2724d23a70) Thanks [@okize](https://github.com/okize)! - Add the `isEmail` utility, ported from the Wistia app
14
+
15
+ ## 0.16.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#273](https://github.com/wistia/type-guards/pull/273) [`1e36fd8`](https://github.com/wistia/type-guards/commit/1e36fd8762af671d8bd24e028787c58589129ac1) Thanks [@okize](https://github.com/okize)! - Add the `noOpFn`, `noOpFnReturningFalse`, `noOpFnReturningNull`, and `asyncNoOpFn` utilities and the `NoOpFn`, `NoOpFnReturningFalse`, `NoOpFnReturningNull`, `AsyncNoOpFn`, and `AsyncOrSyncNoOpFn` types. Each function does nothing; they serve as default or placeholder callbacks
20
+
21
+ ## 0.15.0
22
+
23
+ ### Minor Changes
24
+
25
+ - [#251](https://github.com/wistia/type-guards/pull/251) [`7740fc8`](https://github.com/wistia/type-guards/commit/7740fc8d652831074d429aa207500e226c49f8e5) Thanks [@okize](https://github.com/okize)! - Add the `deepMerge` utility and `DeepMerged` type. Deeply merges objects without mutating them, inferring the return type from the inputs; plain objects merge recursively, arrays concatenate with duplicates removed, and other values are overwritten in argument order
26
+
27
+ ## 0.14.0
28
+
29
+ ### Minor Changes
30
+
31
+ - [#247](https://github.com/wistia/type-guards/pull/247) [`e4c822c`](https://github.com/wistia/type-guards/commit/e4c822cde3e776b2985da90cfc20ddbaa03d5435) Thanks [@okize](https://github.com/okize)! - Add the date and time utilities from `@wistia/ui`: `buildTimeDuration`, `dateOnlyISOString`, `dateOnlyString`, `dateOnlyStringForSentence`, `dateOnlyStringNumeric`, `dateTimeRounded`, `dateTimeString`, `dateTimeStringForSentence`, `dateTimeToDate`, `dateTimeToISO`, `dateToDateTime`, `dateUTCOffset`, `dayOfWeekString`, `mediaDurationString`, `millisecondsToDurationISOString`, `monthDayStringNumeric`, `parseDateString`, `sessionDurationString`, `timeAgoString`, and `timeOnlyString`, plus the `DateOnlyStringOptions`, `DateTimeRoundedOverload`, `TimeAgoOptions`, `TimeDuration`, and `WistiaDateTimeObject` types
32
+
33
+ ## 0.13.1
34
+
35
+ ### Patch Changes
36
+
37
+ - [#240](https://github.com/wistia/type-guards/pull/240) [`9e86ea9`](https://github.com/wistia/type-guards/commit/9e86ea9b9271da61f3e90dbd41b2e01b347ad0ba) Thanks [@okize](https://github.com/okize)! - fix: narrow `isRecord` to `Record<string, unknown>` instead of `EmptyObject | Record<string, unknown>`
38
+
39
+ The `EmptyObject` union member was redundant — `Record<string, unknown>` already
40
+ accepts `{}` — and it broke the guard's primary use: because `EmptyObject` has no
41
+ index signature, every `value['someKey']` read after a passing `isRecord` check
42
+ failed with TS7053. `isNotRecord`'s declared type is updated to match; its
43
+ resolved type is unchanged.
44
+
45
+ ## 0.13.0
46
+
47
+ ### Minor Changes
48
+
49
+ - [#235](https://github.com/wistia/type-guards/pull/235) [`6a92f7f`](https://github.com/wistia/type-guards/commit/6a92f7f744b6268308031dadd9ddc0b4c475297c) Thanks [@okize](https://github.com/okize)! - feat: add guards `isRegExp`, `isBigInt`, `isSymbol`, `isPromise`, `isIterable`, `isMap`, `isSet`, `isWeakMap`, `isWeakSet`, `isAsyncFunction`
50
+
51
+ ## 0.12.0
52
+
53
+ ### Minor Changes
54
+
55
+ - [#233](https://github.com/wistia/type-guards/pull/233) [`ff94757`](https://github.com/wistia/type-guards/commit/ff947573899f4265e68a3a8ab9e7842da8d9fedf) Thanks [@okize](https://github.com/okize)! - feat: add guards `isNonBlankString`, `isNonNaNNumber`, `isFiniteNumber`, `isPlainObject`, `isHtmlElement`, `isHtmlInputElement`, `isHtmlVideoElement`, `isHtmlButtonElement`, `isSvgElement`, `isTextNode`, `readonlyArrayIncludes`, `isMouseEvent` and utilities `getObjectEntries`, `getObjectKeys`, `getObjectValues`, `tupleIncludes`
56
+
57
+ ## 0.11.4
58
+
59
+ ### Patch Changes
60
+
61
+ - [#225](https://github.com/wistia/type-guards/pull/225) [`d3b2734`](https://github.com/wistia/type-guards/commit/d3b273448baff8c4e17061846214eb5bbfca9466) Thanks [@okize](https://github.com/okize)! - feat: add `NullableProperties` type
62
+
63
+ ## 0.11.3
64
+
65
+ ### Patch Changes
66
+
67
+ - [#217](https://github.com/wistia/type-guards/pull/217) [`0f0b7bb`](https://github.com/wistia/type-guards/commit/0f0b7bba1cd0dd8af8d5d0dda4ff80d88e9e6ee4) Thanks [@okize](https://github.com/okize)! - feat: add llms.txt and llms-full.txt for agent consumption
68
+
69
+ ## 0.11.2
70
+
71
+ ### Patch Changes
72
+
73
+ - [#211](https://github.com/wistia/type-guards/pull/211) [`6c2bbcd`](https://github.com/wistia/type-guards/commit/6c2bbcdd41a68886429d9d0ef2ff7784cedc7207) Thanks [@okize](https://github.com/okize)! - fix: split index.ts into per-guard files under `src`
74
+
75
+ ## 0.11.1
76
+
77
+ ### Patch Changes
78
+
79
+ - [#206](https://github.com/wistia/type-guards/pull/206) [`ec39edd`](https://github.com/wistia/type-guards/commit/ec39edd03204174e1956e16d4567efb2c6122253) Thanks [@okize](https://github.com/okize)! - feat: add `Arrayable` type
80
+
81
+ ## 0.11.0
82
+
83
+ ### Minor Changes
84
+
85
+ - [#194](https://github.com/wistia/type-guards/pull/194) [`ef44620`](https://github.com/wistia/type-guards/commit/ef446209c3099ac53cbc17a18b18df09d779c0a3) Thanks [@okize](https://github.com/okize)! - feat: add `isDate` type guard
86
+
87
+ ## 0.10.0
88
+
89
+ ### Minor Changes
90
+
91
+ - [#182](https://github.com/wistia/type-guards/pull/182) [`b1ce2fe`](https://github.com/wistia/type-guards/commit/b1ce2fe8beccb9375cbc25bf534ab57b313bb45c) Thanks [@okize](https://github.com/okize)! - feat: switch build from `tsup` to `tsdown`
92
+
93
+ ## 0.9.3
94
+
95
+ ### Patch Changes
96
+
97
+ - [#163](https://github.com/wistia/type-guards/pull/163) [`67fe310`](https://github.com/wistia/type-guards/commit/67fe310ce9dd5f14e24694bdd3cd5342476c28cf) Thanks [@okize](https://github.com/okize)! - fix: remove remaining GH links from `package.json`
98
+
99
+ ## 0.9.2
100
+
101
+ ### Patch Changes
102
+
103
+ - [#161](https://github.com/wistia/type-guards/pull/161) [`966b9ea`](https://github.com/wistia/type-guards/commit/966b9eafdd667ac0a82891aec91ff73d41879eba) Thanks [@okize](https://github.com/okize)! - fix: set license to MIT
104
+
105
+ ## 0.9.1
106
+
107
+ ### Patch Changes
108
+
109
+ - [#113](https://github.com/wistia/type-guards/pull/113) [`1be4586`](https://github.com/wistia/type-guards/commit/1be458654816bc1b3752fd0648c592d7189e6cb2) Thanks [@okize](https://github.com/okize)! - fix: ensure build emits correct commonjs & esm exports
110
+
111
+ ## 0.9.0
112
+
113
+ ### Minor Changes
114
+
115
+ - [#109](https://github.com/wistia/type-guards/pull/109) [`6f54871`](https://github.com/wistia/type-guards/commit/6f548712fec133bc9d9c47aab226e3d8ed9568bd) Thanks [@okize](https://github.com/okize)! - feat: add isTruthy type guard
116
+
117
+ ## 0.8.0
118
+
119
+ ### Minor Changes
120
+
121
+ - [#107](https://github.com/wistia/type-guards/pull/107) [`2bae8ba`](https://github.com/wistia/type-guards/commit/2bae8baff6f069686d76f53cba0e1b396aa456e1) Thanks [@okize](https://github.com/okize)! - feat: add isFalsy type guard
122
+
123
+ ## 0.7.0
124
+
125
+ ### Minor Changes
126
+
127
+ - [#73](https://github.com/wistia/type-guards/pull/73) [`38c0b23`](https://github.com/wistia/type-guards/commit/38c0b231692a2b16335913d6862387dbc1b0306e) Thanks [@okize](https://github.com/okize)! - feat: add isNotRecord type guard
128
+
129
+ - [#91](https://github.com/wistia/type-guards/pull/91) [`9b2beed`](https://github.com/wistia/type-guards/commit/9b2beeddfbf456007dce87f6afba5e85796f59f1) Thanks [@okize](https://github.com/okize)! - feat: add `isNotVoid` type guard
130
+
131
+ ## 0.6.0
132
+
133
+ ### Minor Changes
134
+
135
+ - [#69](https://github.com/wistia/type-guards/pull/69) [`cacf785`](https://github.com/wistia/type-guards/commit/cacf785d526a01ed134d5dbd6b7d595012dc20f5) Thanks [@okize](https://github.com/okize)! - feat: add isNotArray type guard
136
+
137
+ ## 0.5.0
138
+
139
+ ### Minor Changes
140
+
141
+ - [`ab086eb`](https://github.com/wistia/type-guards/commit/ab086eb1d095522cdfa80d3e1f330afea0bb826f) Thanks [@okize](https://github.com/okize)! - feat: add `isNotBoolean` type guard
142
+
143
+ ## 0.4.0
144
+
145
+ ### Minor Changes
146
+
147
+ - [#61](https://github.com/wistia/type-guards/pull/61) [`41f8d7b`](https://github.com/wistia/type-guards/commit/41f8d7b3d6e18012df2615412df8586ad1872424) Thanks [@okize](https://github.com/okize)! - feat: add `isNotFunction` type guard
148
+
149
+ ## 0.3.0
150
+
151
+ ### Minor Changes
152
+
153
+ - [#56](https://github.com/wistia/type-guards/pull/56) [`08804e5`](https://github.com/wistia/type-guards/commit/08804e53af325090ff26894f953cdc972fe8c660) Thanks [@okize](https://github.com/okize)! - feat: add `isNotNumber` type guard
154
+
155
+ ## 0.2.0
156
+
157
+ ### Minor Changes
158
+
159
+ - [`e873b82`](https://github.com/wistia/type-guards/commit/e873b82478bf8868cb99dc0d5ad70e10226f9d40) Thanks [@okize](https://github.com/okize)! - feat: add `isNotString` type guard
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Wistia, Inc.
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.
22
+
package/README.md CHANGED
@@ -1,3 +1,238 @@
1
- # Temporary Holding Version
1
+ # utils
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This library provides a set of type guards that help safely check and narrow down types at runtime, making it easier to handle data validation and type checking in a type-safe manner. It also ships a set of general-purpose utility functions and utility types.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @wistia/utils
9
+ ```
10
+
11
+ ```sh
12
+ yarn add @wistia/utils
13
+ ```
14
+
15
+ ```sh
16
+ pnpm add @wistia/utils
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Every guard is a `value is T` predicate, so TypeScript narrows the value inside the `if` block:
22
+
23
+ ```ts
24
+ import { isNonEmptyString, isNotNil } from '@wistia/utils';
25
+
26
+ function greet(value: unknown): string {
27
+ if (isNonEmptyString(value)) {
28
+ return `Hello, ${value}`;
29
+ }
30
+ return 'Hello, stranger';
31
+ }
32
+
33
+ const names: (string | null | undefined)[] = ['Alice', null, 'Bob'];
34
+ const cleaned: string[] = names.filter(isNotNil); // ['Alice', 'Bob']
35
+ ```
36
+
37
+ ## Guards
38
+
39
+ <!-- AUTOGEN:README-GUARDS:START -->
40
+
41
+ ### Primitives
42
+
43
+ | Guard | Narrows to |
44
+ | ------------------------ | ------------------------------------------ |
45
+ | `isAsyncFunction(value)` | `(...args: unknown[]) => Promise<unknown>` |
46
+ | `isBigInt(value)` | `bigint` |
47
+ | `isBoolean(value)` | `boolean` |
48
+ | `isDate(value)` | `Date` |
49
+ | `isError(value)` | `Error` |
50
+ | `isFiniteNumber(value)` | `number` |
51
+ | `isFunction(value)` | `(...args: unknown[]) => unknown` |
52
+ | `isInteger(value)` | `number` |
53
+ | `isIterable(value)` | `Iterable<unknown>` |
54
+ | `isMap(value)` | `Map<unknown, unknown>` |
55
+ | `isNaN(value)` | `number` |
56
+ | `isNil(value)` | `Nil` |
57
+ | `isNonNaNNumber(value)` | `number` |
58
+ | `isNull(value)` | `null` |
59
+ | `isNumber(value)` | `number` |
60
+ | `isPromise(value)` | `Promise<unknown>` |
61
+ | `isRegExp(value)` | `RegExp` |
62
+ | `isSet(value)` | `Set<unknown>` |
63
+ | `isString(value)` | `string` |
64
+ | `isSymbol(value)` | `symbol` |
65
+ | `isUndefined(value)` | `undefined` |
66
+ | `isVoid(value)` | `void` |
67
+ | `isWeakMap(value)` | `WeakMap<WeakKey, unknown>` |
68
+ | `isWeakSet(value)` | `WeakSet<WeakKey>` |
69
+
70
+ ### Arrays
71
+
72
+ | Guard | Narrows to |
73
+ | ---------------------------------- | ------------------ |
74
+ | `isArray(value)` | `unknown[]` |
75
+ | `isEmptyArray(value)` | `never[]` |
76
+ | `isNonEmptyArray(value)` | `NonEmptyArray<T>` |
77
+ | `readonlyArrayIncludes(arr, elem)` | `T` |
78
+
79
+ ### Records (plain objects, not arrays)
80
+
81
+ | Guard | Narrows to |
82
+ | ------------------------- | ------------------------- |
83
+ | `hasKey(value, key)` | `Record<Key, Value>` |
84
+ | `isEmptyRecord(value)` | `EmptyObject` |
85
+ | `isNonEmptyRecord(value)` | `Record<string, unknown>` |
86
+ | `isPlainObject(value)` | `Record<string, unknown>` |
87
+ | `isRecord(value)` | `Record<string, unknown>` |
88
+
89
+ ### Strings
90
+
91
+ | Guard | Narrows to |
92
+ | ------------------------- | ---------- |
93
+ | `isEmptyString(value)` | `''` |
94
+ | `isNonBlankString(value)` | `string` |
95
+ | `isNonEmptyString(value)` | `string` |
96
+
97
+ ### Truthy / falsy
98
+
99
+ | Guard | Narrows to |
100
+ | ----------------- | ---------- |
101
+ | `isFalsy(value)` | `Falsy` |
102
+ | `isTruthy(value)` | `boolean` |
103
+
104
+ ### Negated
105
+
106
+ The `isNot*` variants are useful as `.filter` predicates to drop the unwanted type:
107
+
108
+ | Guard | Narrows to |
109
+ | ----------------------- | --------------------------------------------------- |
110
+ | `isNotArray(value)` | `Exclude<unknown, unknown[]>` |
111
+ | `isNotBoolean(value)` | `Exclude<unknown, boolean>` |
112
+ | `isNotFunction(value)` | `Exclude<unknown, (...args: unknown[]) => unknown>` |
113
+ | `isNotNil(value)` | `T` |
114
+ | `isNotNull(value)` | `Exclude<T, null>` |
115
+ | `isNotNumber(value)` | `Exclude<unknown, number>` |
116
+ | `isNotRecord(value)` | `Exclude<unknown, Record<string, unknown>>` |
117
+ | `isNotString(value)` | `Exclude<unknown, string>` |
118
+ | `isNotUndefined(value)` | `Exclude<T, undefined>` |
119
+ | `isNotVoid(value)` | `Exclude<unknown, void>` |
120
+
121
+ ### DOM
122
+
123
+ | Guard | Narrows to |
124
+ | ---------------------------- | ------------------- |
125
+ | `isHtmlButtonElement(value)` | `HTMLButtonElement` |
126
+ | `isHtmlElement(value)` | `HTMLElement` |
127
+ | `isHtmlInputElement(value)` | `HTMLInputElement` |
128
+ | `isHtmlVideoElement(value)` | `HTMLVideoElement` |
129
+ | `isMouseEvent(value)` | `MouseEvent` |
130
+ | `isSvgElement(value)` | `SVGElement` |
131
+ | `isTextNode(value)` | `Text` |
132
+
133
+ <!-- AUTOGEN:README-GUARDS:END -->
134
+
135
+ ## Types
136
+
137
+ <!-- AUTOGEN:README-TYPES:START -->
138
+
139
+ | Type | Resolves to |
140
+ | --------------------------------------------------- | ------------------------------------------------------------- |
141
+ | `Arrayable<T>` | `T \| T[]` |
142
+ | `Falsy` | `typeof Number.NaN \| '' \| 0n \| false \| null \| undefined` |
143
+ | `NestedNonNullable<T, P extends Paths<T> & string>` | `NonNullable<Get<T, P>>` |
144
+ | `Nil` | `null \| undefined` |
145
+ | `Nilable<A>` | `A \| Nil` |
146
+ | `NilableArray<T>` | `Nilable<Nilable<T>[]>` |
147
+ | `NonEmptyArray<T>` | `[T, ...T[]]` |
148
+ | `NotNilable<A>` | `Exclude<A, Nil>` |
149
+ | `Nullable<A>` | `A \| null` |
150
+ | `NullableProperties<T extends UnknownRecord>` | `{ [Key in keyof T]: Nullable<T[Key]> }` |
151
+ | `Truthy<T>` | `Exclude<T, Falsy>` |
152
+ | `Undefinable<A>` | `A \| undefined` |
153
+
154
+ <!-- AUTOGEN:README-TYPES:END -->
155
+
156
+ ## Utilities
157
+
158
+ General-purpose helper functions that complement the guards. Unlike guards, these are not type predicates.
159
+
160
+ <!-- AUTOGEN:README-UTILITIES:START -->
161
+
162
+ | Utility | Returns |
163
+ | ------------------------------------------------------------------------ | ------------------------------ |
164
+ | `asyncNoOpFn()` | `Promise<void>` |
165
+ | `buildTimeDuration(numberOfMilliseconds)` | `TimeDuration` |
166
+ | `coerceToBoolean(value)` | `boolean` |
167
+ | `dateOnlyISOString(date, { timeZone = defaultTimeZone })` | `string` |
168
+ | `dateOnlyString(date, { timeZone = defaultTimeZone, omitYear = false })` | `string` |
169
+ | `dateOnlyStringForSentence(date, { timeZone = defaultTimeZone })` | `string` |
170
+ | `dateOnlyStringNumeric(date, { timeZone = defaultTimeZone })` | `string` |
171
+ | `dateTimeRounded(dateTime, toISOString = true)` | `string \| Date \| null` |
172
+ | `dateTimeString(date, { timeZone = defaultTimeZone, omitYear = false })` | `string` |
173
+ | `dateTimeStringForSentence(date, { timeZone = defaultTimeZone })` | `string` |
174
+ | `dateTimeToDate(dateTime)` | `Date \| null` |
175
+ | `dateTimeToISO(dateTime)` | `string \| null` |
176
+ | `dateToDateTime(date)` | `WistiaDateTimeObject \| null` |
177
+ | `dateUTCOffset(date)` | `string` |
178
+ | `dayOfWeekString(date, { timeZone = defaultTimeZone })` | `string` |
179
+ | `deepMerge(...objects)` | `DeepMergeResult<T>` |
180
+ | `getObjectEntries(obj)` | `[keyof T, T[keyof T]][]` |
181
+ | `getObjectKeys(obj)` | `(keyof T)[]` |
182
+ | `getObjectValues(obj)` | `T[keyof T][]` |
183
+ | `isEmail(value)` | `boolean` |
184
+ | `isUrl(value)` | `boolean` |
185
+ | `mediaDurationString(numberOfMilliseconds)` | `string` |
186
+ | `millisecondsToDurationISOString(numberOfMilliseconds)` | `string` |
187
+ | `monthDayStringNumeric(date, { timeZone = defaultTimeZone })` | `string` |
188
+ | `noOpFn()` | `void` |
189
+ | `noOpFnReturningFalse()` | `false` |
190
+ | `noOpFnReturningNull()` | `null` |
191
+ | `parseDateString(str)` | `Date \| null` |
192
+ | `sessionDurationString(numberOfMilliseconds)` | `string` |
193
+ | `stripExtension(str)` | `string` |
194
+ | `timeAgoString(date, { nowAnchor = new Date(), includeTime = true })` | `string` |
195
+ | `timeOnlyString(date, { timeZone = defaultTimeZone })` | `string` |
196
+ | `tupleIncludes(tuple, item)` | `item is TTuple[number]` |
197
+
198
+ <!-- AUTOGEN:README-UTILITIES:END -->
199
+
200
+ ## Patterns
201
+
202
+ Filter nullish values from a list, with narrowing:
203
+
204
+ ```ts
205
+ import { isNotNil } from '@wistia/utils';
206
+
207
+ const raw: (string | null | undefined)[] = ['a', null, 'b', undefined];
208
+ const clean: string[] = raw.filter(isNotNil); // ['a', 'b']
209
+ ```
210
+
211
+ Safely access a key on an unknown value:
212
+
213
+ ```ts
214
+ import { hasKey } from '@wistia/utils';
215
+
216
+ function readName(value: unknown): string | undefined {
217
+ if (hasKey<'name', string>(value, 'name') && typeof value.name === 'string') {
218
+ return value.name;
219
+ }
220
+ return undefined;
221
+ }
222
+ ```
223
+
224
+ Combine guards to handle a discriminated input:
225
+
226
+ ```ts
227
+ import { isString, isNonEmptyArray } from '@wistia/utils';
228
+
229
+ function describe(value: unknown): string {
230
+ if (isString(value)) return value.toUpperCase();
231
+ if (isNonEmptyArray<unknown>(value)) return `${value.length} items`;
232
+ return 'other';
233
+ }
234
+ ```
235
+
236
+ ## Agent-friendly docs
237
+
238
+ Every export has a TSDoc `@example` block, so IDEs and LLM agents see usage at the call site via the bundled `.d.ts`. The package also ships `llms.txt` (compact index) and `llms-full.txt` (every signature plus an example) at the package root, following the [llmstxt.org](https://llmstxt.org) convention.