@wistia/utils 0.0.0-stage → 0.17.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 +22 -0
- package/README.md +237 -2
- package/dist/index.cjs +1921 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1560 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +1560 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1833 -0
- package/dist/index.mjs.map +1 -0
- package/llms-full.txt +1195 -0
- package/llms.txt +158 -0
- package/package.json +81 -4
package/llms.txt
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# @wistia/utils
|
|
2
|
+
|
|
3
|
+
> Runtime type guards, utility types, and utility functions for TypeScript. Every guard is a `value is T` predicate that narrows `unknown` values; every type is a small composable building block; utilities are general-purpose helper functions.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @wistia/utils
|
|
9
|
+
yarn add @wistia/utils
|
|
10
|
+
pnpm add @wistia/utils
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Import
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { isString, isNotNil, type Nilable } from '@wistia/utils';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Guards
|
|
20
|
+
|
|
21
|
+
<!-- AUTOGEN:LLMS-GUARDS:START -->
|
|
22
|
+
Primitives:
|
|
23
|
+
|
|
24
|
+
- `isAsyncFunction(value)` — `value is (...args: unknown[]) => Promise<unknown>`
|
|
25
|
+
- `isBigInt(value)` — `value is bigint`
|
|
26
|
+
- `isBoolean(value)` — `value is boolean`
|
|
27
|
+
- `isDate(value)` — `value is Date`
|
|
28
|
+
- `isError(value)` — `value is Error`
|
|
29
|
+
- `isFiniteNumber(value)` — `value is number`
|
|
30
|
+
- `isFunction(value)` — `value is (...args: unknown[]) => unknown`
|
|
31
|
+
- `isInteger(value)` — `value is number`
|
|
32
|
+
- `isIterable(value)` — `value is Iterable<unknown>`
|
|
33
|
+
- `isMap(value)` — `value is Map<unknown, unknown>`
|
|
34
|
+
- `isNaN(value)` — `value is number`
|
|
35
|
+
- `isNil(value)` — `value is Nil`
|
|
36
|
+
- `isNonNaNNumber(value)` — `value is number`
|
|
37
|
+
- `isNull(value)` — `value is null`
|
|
38
|
+
- `isNumber(value)` — `value is number`
|
|
39
|
+
- `isPromise(value)` — `value is Promise<unknown>`
|
|
40
|
+
- `isRegExp(value)` — `value is RegExp`
|
|
41
|
+
- `isSet(value)` — `value is Set<unknown>`
|
|
42
|
+
- `isString(value)` — `value is string`
|
|
43
|
+
- `isSymbol(value)` — `value is symbol`
|
|
44
|
+
- `isUndefined(value)` — `value is undefined`
|
|
45
|
+
- `isVoid(value)` — `value is void`
|
|
46
|
+
- `isWeakMap(value)` — `value is WeakMap<WeakKey, unknown>`
|
|
47
|
+
- `isWeakSet(value)` — `value is WeakSet<WeakKey>`
|
|
48
|
+
|
|
49
|
+
Arrays:
|
|
50
|
+
|
|
51
|
+
- `isArray(value)` — `value is unknown[]`
|
|
52
|
+
- `isEmptyArray(value)` — `value is never[]`
|
|
53
|
+
- `isNonEmptyArray(value)` — `value is NonEmptyArray<T>`
|
|
54
|
+
- `readonlyArrayIncludes(arr, elem)` — `value is T`
|
|
55
|
+
|
|
56
|
+
Records (plain objects, not arrays):
|
|
57
|
+
|
|
58
|
+
- `hasKey(value, key)` — `value is Record<Key, Value>`
|
|
59
|
+
- `isEmptyRecord(value)` — `value is EmptyObject`
|
|
60
|
+
- `isNonEmptyRecord(value)` — `value is Record<string, unknown>`
|
|
61
|
+
- `isPlainObject(value)` — `value is Record<string, unknown>`
|
|
62
|
+
- `isRecord(value)` — `value is Record<string, unknown>`
|
|
63
|
+
|
|
64
|
+
Strings:
|
|
65
|
+
|
|
66
|
+
- `isEmptyString(value)` — `value is ''`
|
|
67
|
+
- `isNonBlankString(value)` — `value is string`
|
|
68
|
+
- `isNonEmptyString(value)` — `value is string`
|
|
69
|
+
|
|
70
|
+
Truthy / falsy:
|
|
71
|
+
|
|
72
|
+
- `isFalsy(value)` — `value is Falsy`
|
|
73
|
+
- `isTruthy(value)` — returns `boolean`
|
|
74
|
+
|
|
75
|
+
Negated:
|
|
76
|
+
|
|
77
|
+
- `isNotArray(value)` — `value is Exclude<unknown, unknown[]>`
|
|
78
|
+
- `isNotBoolean(value)` — `value is Exclude<unknown, boolean>`
|
|
79
|
+
- `isNotFunction(value)` — `value is Exclude<unknown, (...args: unknown[]) => unknown>`
|
|
80
|
+
- `isNotNil(value)` — `value is T`
|
|
81
|
+
- `isNotNull(value)` — `value is Exclude<T, null>`
|
|
82
|
+
- `isNotNumber(value)` — `value is Exclude<unknown, number>`
|
|
83
|
+
- `isNotRecord(value)` — `value is Exclude<unknown, Record<string, unknown>>`
|
|
84
|
+
- `isNotString(value)` — `value is Exclude<unknown, string>`
|
|
85
|
+
- `isNotUndefined(value)` — `value is Exclude<T, undefined>`
|
|
86
|
+
- `isNotVoid(value)` — `value is Exclude<unknown, void>`
|
|
87
|
+
|
|
88
|
+
DOM:
|
|
89
|
+
|
|
90
|
+
- `isHtmlButtonElement(value)` — `value is HTMLButtonElement`
|
|
91
|
+
- `isHtmlElement(value)` — `value is HTMLElement`
|
|
92
|
+
- `isHtmlInputElement(value)` — `value is HTMLInputElement`
|
|
93
|
+
- `isHtmlVideoElement(value)` — `value is HTMLVideoElement`
|
|
94
|
+
- `isMouseEvent(value)` — `value is MouseEvent`
|
|
95
|
+
- `isSvgElement(value)` — `value is SVGElement`
|
|
96
|
+
- `isTextNode(value)` — `value is Text`
|
|
97
|
+
<!-- AUTOGEN:LLMS-GUARDS:END -->
|
|
98
|
+
|
|
99
|
+
## Types
|
|
100
|
+
|
|
101
|
+
<!-- AUTOGEN:LLMS-TYPES:START -->
|
|
102
|
+
- `Arrayable<T>` — `T | T[]`
|
|
103
|
+
- `Falsy` — `typeof Number.NaN | '' | 0n | false | null | undefined`
|
|
104
|
+
- `NestedNonNullable<T, P extends Paths<T> & string>` — `NonNullable<Get<T, P>>`
|
|
105
|
+
- `Nil` — `null | undefined`
|
|
106
|
+
- `Nilable<A>` — `A | Nil`
|
|
107
|
+
- `NilableArray<T>` — `Nilable<Nilable<T>[]>`
|
|
108
|
+
- `NonEmptyArray<T>` — `[T, ...T[]]`
|
|
109
|
+
- `NotNilable<A>` — `Exclude<A, Nil>`
|
|
110
|
+
- `Nullable<A>` — `A | null`
|
|
111
|
+
- `NullableProperties<T extends UnknownRecord>` — `{ [Key in keyof T]: Nullable<T[Key]> }`
|
|
112
|
+
- `Truthy<T>` — `Exclude<T, Falsy>`
|
|
113
|
+
- `Undefinable<A>` — `A | undefined`
|
|
114
|
+
<!-- AUTOGEN:LLMS-TYPES:END -->
|
|
115
|
+
|
|
116
|
+
## Utilities
|
|
117
|
+
|
|
118
|
+
<!-- AUTOGEN:LLMS-UTILITIES:START -->
|
|
119
|
+
- `asyncNoOpFn()` — returns `Promise<void>`
|
|
120
|
+
- `buildTimeDuration(numberOfMilliseconds)` — returns `TimeDuration`
|
|
121
|
+
- `coerceToBoolean(value)` — returns `boolean`
|
|
122
|
+
- `dateOnlyISOString(date, { timeZone = defaultTimeZone })` — returns `string`
|
|
123
|
+
- `dateOnlyString(date, { timeZone = defaultTimeZone, omitYear = false })` — returns `string`
|
|
124
|
+
- `dateOnlyStringForSentence(date, { timeZone = defaultTimeZone })` — returns `string`
|
|
125
|
+
- `dateOnlyStringNumeric(date, { timeZone = defaultTimeZone })` — returns `string`
|
|
126
|
+
- `dateTimeRounded(dateTime, toISOString = true)` — returns `string | Date | null`
|
|
127
|
+
- `dateTimeString(date, { timeZone = defaultTimeZone, omitYear = false })` — returns `string`
|
|
128
|
+
- `dateTimeStringForSentence(date, { timeZone = defaultTimeZone })` — returns `string`
|
|
129
|
+
- `dateTimeToDate(dateTime)` — returns `Date | null`
|
|
130
|
+
- `dateTimeToISO(dateTime)` — returns `string | null`
|
|
131
|
+
- `dateToDateTime(date)` — returns `WistiaDateTimeObject | null`
|
|
132
|
+
- `dateUTCOffset(date)` — returns `string`
|
|
133
|
+
- `dayOfWeekString(date, { timeZone = defaultTimeZone })` — returns `string`
|
|
134
|
+
- `deepMerge(...objects)` — returns `DeepMergeResult<T>`
|
|
135
|
+
- `getObjectEntries(obj)` — returns `[keyof T, T[keyof T]][]`
|
|
136
|
+
- `getObjectKeys(obj)` — returns `(keyof T)[]`
|
|
137
|
+
- `getObjectValues(obj)` — returns `T[keyof T][]`
|
|
138
|
+
- `isEmail(value)` — returns `boolean`
|
|
139
|
+
- `isUrl(value)` — returns `boolean`
|
|
140
|
+
- `mediaDurationString(numberOfMilliseconds)` — returns `string`
|
|
141
|
+
- `millisecondsToDurationISOString(numberOfMilliseconds)` — returns `string`
|
|
142
|
+
- `monthDayStringNumeric(date, { timeZone = defaultTimeZone })` — returns `string`
|
|
143
|
+
- `noOpFn()` — returns `void`
|
|
144
|
+
- `noOpFnReturningFalse()` — returns `false`
|
|
145
|
+
- `noOpFnReturningNull()` — returns `null`
|
|
146
|
+
- `parseDateString(str)` — returns `Date | null`
|
|
147
|
+
- `sessionDurationString(numberOfMilliseconds)` — returns `string`
|
|
148
|
+
- `stripExtension(str)` — returns `string`
|
|
149
|
+
- `timeAgoString(date, { nowAnchor = new Date(), includeTime = true })` — returns `string`
|
|
150
|
+
- `timeOnlyString(date, { timeZone = defaultTimeZone })` — returns `string`
|
|
151
|
+
- `tupleIncludes(tuple, item)` — returns `item is TTuple[number]`
|
|
152
|
+
<!-- AUTOGEN:LLMS-UTILITIES:END -->
|
|
153
|
+
|
|
154
|
+
## See also
|
|
155
|
+
|
|
156
|
+
- `llms-full.txt` — every export with signature and example, in a single document
|
|
157
|
+
- `README.md` — human-readable docs
|
|
158
|
+
- `dist/index.d.mts` — typed entry point with full TSDoc on every export
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wistia/utils",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.17.0",
|
|
4
|
+
"packageManager": "yarn@4.18.1",
|
|
5
|
+
"description": "Type guards",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"llms.txt",
|
|
9
|
+
"llms-full.txt"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "dist/index.cjs",
|
|
14
|
+
"module": "dist/index.mjs",
|
|
15
|
+
"types": "dist/index.d.mts",
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
".": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"default": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"default": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsdown --config tsdown.config.mts",
|
|
31
|
+
"changeset": "changeset",
|
|
32
|
+
"clean": "rm -rf ./dist",
|
|
33
|
+
"docs": "typedoc --entryPoints src/index.ts --out docs",
|
|
34
|
+
"docs:gen": "node scripts/build-docs.mjs && yarn format",
|
|
35
|
+
"docs:check": "yarn docs:gen && git diff --exit-code -- README.md llms.txt llms-full.txt",
|
|
36
|
+
"format": "oxfmt --config oxfmt.config.ts --write .",
|
|
37
|
+
"format:ci": "oxfmt --config oxfmt.config.ts --check .",
|
|
38
|
+
"lint": "oxlint --config oxlint.config.ts .",
|
|
39
|
+
"lint:ci": "oxlint --format=github --config oxlint.config.ts . ",
|
|
40
|
+
"outdated": "yarn upgrade-interactive",
|
|
41
|
+
"publint": "npx publint run .",
|
|
42
|
+
"release": "yarn run build && changeset publish",
|
|
43
|
+
"test": "vitest",
|
|
44
|
+
"test:ci": "vitest run --coverage"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"type-fest": "^5.10.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@changesets/changelog-github": "^1.0.1",
|
|
51
|
+
"@changesets/cli": "^3.0.3",
|
|
52
|
+
"@types/node": "^26.6.5",
|
|
53
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
54
|
+
"@wistia/oxlint-config": "^1.12.12",
|
|
55
|
+
"eslint": "^10.13.0",
|
|
56
|
+
"oxfmt": "^0.74.0",
|
|
57
|
+
"oxlint": "^1.89.0",
|
|
58
|
+
"oxlint-tsgolint": "^7.0.2004",
|
|
59
|
+
"publint": "^0.3.25",
|
|
60
|
+
"tsdown": "^0.23.1",
|
|
61
|
+
"typedoc": "^0.28.20",
|
|
62
|
+
"typescript": "^7.0.2",
|
|
63
|
+
"vite": "^8.3.4",
|
|
64
|
+
"vitest": "^5.0.5"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": "^22.16.0 || >=24.0.0 || >=26.0.0"
|
|
68
|
+
},
|
|
69
|
+
"keywords": [
|
|
70
|
+
"guards",
|
|
71
|
+
"ts",
|
|
72
|
+
"type-checking",
|
|
73
|
+
"type-guards",
|
|
74
|
+
"type-predicates",
|
|
75
|
+
"type-safety",
|
|
76
|
+
"types",
|
|
77
|
+
"typescript",
|
|
78
|
+
"utility-types",
|
|
79
|
+
"validation"
|
|
80
|
+
],
|
|
81
|
+
"license": "MIT",
|
|
82
|
+
"author": "Wistia Engineering"
|
|
83
|
+
}
|