@webdeveric/utils 0.19.0 → 0.20.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.
Files changed (42) hide show
  1. package/dist/cjs/type-predicate-factory.js +19 -0
  2. package/dist/cjs/type-predicate-factory.js.map +1 -0
  3. package/dist/cjs/type-predicate.js +8 -24
  4. package/dist/cjs/type-predicate.js.map +1 -1
  5. package/dist/mjs/type-predicate-factory.js +11 -0
  6. package/dist/mjs/type-predicate-factory.js.map +1 -0
  7. package/dist/mjs/type-predicate.js +7 -15
  8. package/dist/mjs/type-predicate.js.map +1 -1
  9. package/dist/types/type-predicate-factory.d.ts +7 -0
  10. package/dist/types/type-predicate-factory.d.ts.map +1 -0
  11. package/dist/types/type-predicate.d.ts +7 -9
  12. package/dist/types/type-predicate.d.ts.map +1 -1
  13. package/package.json +22 -21
  14. package/src/asArray.ts +0 -3
  15. package/src/capitalize.ts +0 -1
  16. package/src/clamp.ts +0 -7
  17. package/src/compose.ts +0 -13
  18. package/src/convert.ts +0 -30
  19. package/src/delay.ts +0 -23
  20. package/src/delayAnimationFrame.ts +0 -35
  21. package/src/getMaxValue.ts +0 -16
  22. package/src/getMinValue.ts +0 -16
  23. package/src/getOwnKeys.ts +0 -3
  24. package/src/getOwnProperties.ts +0 -3
  25. package/src/getType.ts +0 -3
  26. package/src/index.ts +0 -24
  27. package/src/isEmpty.ts +0 -21
  28. package/src/isObject.ts +0 -3
  29. package/src/joinStrings.ts +0 -6
  30. package/src/node/fcrdns.ts +0 -37
  31. package/src/node/index.ts +0 -1
  32. package/src/normalize.ts +0 -102
  33. package/src/secToString.ts +0 -45
  34. package/src/toPascalCase.ts +0 -29
  35. package/src/trimEnd.ts +0 -5
  36. package/src/trimIndentation.ts +0 -18
  37. package/src/trimStart.ts +0 -5
  38. package/src/type-assertion.ts +0 -319
  39. package/src/type-predicate.ts +0 -101
  40. package/src/types.ts +0 -48
  41. package/src/uniqueItems.ts +0 -3
  42. package/src/until.ts +0 -130
package/src/normalize.ts DELETED
@@ -1,102 +0,0 @@
1
- import cloneDeep from 'lodash.clonedeep';
2
-
3
- import { getOwnProperties } from './getOwnProperties.js';
4
- import { isObject } from './isObject.js';
5
-
6
- import type { AnyRecord, Builtin } from './types.js';
7
-
8
- export type NormalizeContext<OwnerRecordType, ContextData extends AnyRecord> = {
9
- original: Readonly<OwnerRecordType>;
10
- current: OwnerRecordType;
11
- data: ContextData;
12
- };
13
-
14
- export type NormalizerFn<PropertyType, OwnerRecordType = unknown, ContextData extends AnyRecord = AnyRecord> = (
15
- input: PropertyType,
16
- context: NormalizeContext<OwnerRecordType, ContextData>,
17
- ) => PropertyType;
18
-
19
- export type NormalizersRecord<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = {
20
- readonly [Property in keyof RecordType]?: RecordType[Property] extends Builtin
21
- ? NormalizerFn<RecordType[Property], OwnerRecordType, ContextData>
22
- : AnyNormalizer<RecordType[Property], OwnerRecordType, ContextData>;
23
- };
24
-
25
- export type AnyNormalizer<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> =
26
- | NormalizerFn<RecordType, OwnerRecordType, ContextData>
27
- | NormalizersRecord<RecordType, OwnerRecordType, ContextData>;
28
-
29
- export type ContextInitializer<OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (
30
- data: OwnerRecordType,
31
- normalizers: AnyNormalizer<OwnerRecordType, OwnerRecordType, ContextData>,
32
- ) => ContextData;
33
-
34
- /**
35
- * @example
36
- *
37
- * ```ts
38
- * normalize({ demo: true }, { demo: () => false });
39
- * ```
40
- *
41
- * ```ts
42
- * normalize({ demo: true }, () => ({ demo: false }) });
43
- * ```
44
- *
45
- * ```ts
46
- * normalize(true, () => false );
47
- * ```
48
- */
49
- export function normalize<Data extends object, ContextData extends AnyRecord = AnyRecord>(
50
- input: Readonly<Data>,
51
- normalizers: AnyNormalizer<Data, Data, Partial<ContextData>>, // No initializer so data must be partial
52
- ): Data;
53
-
54
- export function normalize<Data extends object, ContextData extends AnyRecord = AnyRecord>(
55
- input: Readonly<Data>,
56
- normalizers: AnyNormalizer<Data, Data, ContextData>,
57
- initContextData: ContextInitializer<Data, ContextData>,
58
- ): Data;
59
-
60
- export function normalize<Data extends object, ContextData extends AnyRecord = AnyRecord>(
61
- input: Readonly<Data>,
62
- normalizers: AnyNormalizer<Data, Data, ContextData>,
63
- initContextData: ContextInitializer<Data, ContextData> = (): AnyRecord => ({}),
64
- ): Data {
65
- const current = cloneDeep(input);
66
-
67
- const context: NormalizeContext<Data, ContextData> = Object.seal({
68
- original: input,
69
- current,
70
- data: initContextData(input, normalizers),
71
- });
72
-
73
- const walk = <CurrentRecord extends AnyRecord>(
74
- currentRecord: CurrentRecord,
75
- currentNormalizers?: AnyNormalizer<CurrentRecord, Data, ContextData>,
76
- ): CurrentRecord => {
77
- if (typeof currentNormalizers === 'function') {
78
- return currentNormalizers(currentRecord, context);
79
- }
80
-
81
- if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
82
- if (typeof currentRecord === 'object' && currentRecord !== null) {
83
- return getOwnProperties(currentNormalizers).reduce((data, key) => {
84
- const normalizers = currentNormalizers[key];
85
- // If the value is undefined but there is a normalizer record, set value to empty object.
86
- const value =
87
- typeof data[key] === 'undefined' && isObject(normalizers)
88
- ? ({} as unknown as CurrentRecord[keyof CurrentRecord])
89
- : data[key];
90
-
91
- data[key] = walk(value, normalizers);
92
-
93
- return data;
94
- }, currentRecord);
95
- }
96
- }
97
-
98
- return currentRecord;
99
- };
100
-
101
- return walk(current, normalizers);
102
- }
@@ -1,45 +0,0 @@
1
- export enum Seconds {
2
- Second = 1,
3
- Minute = 60 * Second,
4
- Hour = 60 * Minute,
5
- Day = 24 * Hour,
6
- Week = 7 * Day,
7
- Month = (365.25 / 12) * Day,
8
- Year = 12 * Month,
9
- Decade = 10 * Year,
10
- Century = 10 * Decade,
11
- Millennium = 10 * Century,
12
- }
13
-
14
- type SecondsTuple = [key: Lowercase<keyof typeof Seconds>, seconds: Seconds];
15
-
16
- export function secToString(time: number, joinString = ' '): string {
17
- const secTime: SecondsTuple[] = [
18
- ['millennium', Seconds.Millennium],
19
- ['century', Seconds.Century],
20
- ['decade', Seconds.Decade],
21
- ['year', Seconds.Year],
22
- ['month', Seconds.Month],
23
- ['week', Seconds.Week],
24
- ['day', Seconds.Day],
25
- ['hour', Seconds.Hour],
26
- ['minute', Seconds.Minute],
27
- ['second', Seconds.Second],
28
- ];
29
-
30
- const parts = secTime.reduce<string[]>((output, [units, seconds]) => {
31
- if (seconds <= time) {
32
- const currentValue = Math.floor(time / seconds);
33
- const suffix = currentValue === 1 ? units : `${units}s`;
34
-
35
- time %= seconds;
36
-
37
- output.push(`${currentValue} ${suffix}`);
38
- }
39
-
40
- return output;
41
- }, []);
42
-
43
- // cSpell:ignore centurys
44
- return parts.join(joinString).replace('centurys', 'centuries');
45
- }
@@ -1,29 +0,0 @@
1
- import { capitalize } from './capitalize.js';
2
- import { getType } from './getType.js';
3
-
4
- import type { KeyValueTuple, StringRecord } from './types.js';
5
-
6
- export function toPascalCase(text: string, customWords?: StringRecord): string {
7
- const words = String(text).match(/[A-Z][a-z']+|\d+|[a-z']+/g);
8
-
9
- if (words === null) {
10
- return '';
11
- }
12
-
13
- let fixedWords = words.map(word => capitalize(word.replace(/'/g, '')));
14
-
15
- if (customWords && getType(customWords) === 'Object') {
16
- const replacements = new Map(
17
- Object.entries(customWords).map<KeyValueTuple<string, string>>(([key, value]) => [key.toLowerCase(), value]),
18
- );
19
-
20
- if (replacements.size) {
21
- // This takes a single word and returns the first matching replacement, if any.
22
- const replaceCustomWords = (word: string): string => replacements.get(word.toLowerCase()) ?? word;
23
-
24
- fixedWords = fixedWords.map(replaceCustomWords);
25
- }
26
- }
27
-
28
- return fixedWords.join('');
29
- }
package/src/trimEnd.ts DELETED
@@ -1,5 +0,0 @@
1
- import escapeRegExp from 'lodash.escaperegexp';
2
-
3
- export function trimEnd(str: string, char?: string): string {
4
- return char ? str.replace(new RegExp(`${escapeRegExp(char)}+$`), '') : str.trimEnd();
5
- }
@@ -1,18 +0,0 @@
1
- const isWhitespaceOnly = (input: string): boolean => /^\s*$/.test(input);
2
-
3
- export function trimIndentation(input: string): string {
4
- const lines = input.split('\n');
5
- const firstNonWhitespaceLine = lines.find(line => !isWhitespaceOnly(line));
6
- const whiteSpace = firstNonWhitespaceLine?.match(/^(?<whiteSpace>\s*)/)?.groups?.whiteSpace;
7
-
8
- if (whiteSpace) {
9
- const wsPattern = new RegExp(`^${whiteSpace}`);
10
-
11
- return lines
12
- .map(line => line.replace(wsPattern, ''))
13
- .join('\n')
14
- .trim();
15
- }
16
-
17
- return input;
18
- }
package/src/trimStart.ts DELETED
@@ -1,5 +0,0 @@
1
- import escapeRegExp from 'lodash.escaperegexp';
2
-
3
- export function trimStart(str: string, char?: string): string {
4
- return char ? str.replace(new RegExp(`^${escapeRegExp(char)}+`), '') : str.trimStart();
5
- }
@@ -1,319 +0,0 @@
1
- import {
2
- isBigInt,
3
- isBoolean,
4
- isFiniteNumber,
5
- isInteger,
6
- isIntString,
7
- isLengthAware,
8
- isNull,
9
- isNumber,
10
- isNumericString,
11
- isNumericValue,
12
- isNumericValueArray,
13
- isObject,
14
- isOptionalBigInt,
15
- isOptionalBoolean,
16
- isOptionalNull,
17
- isOptionalNumber,
18
- isOptionalString,
19
- isOptionalSymbol,
20
- isPositiveFiniteNumber,
21
- isPositiveInteger,
22
- isPrimitive,
23
- isPromiseFulfilledResult,
24
- isPromiseRejectedResult,
25
- isPropertyKey,
26
- isString,
27
- isStringMatching,
28
- isStringRecord,
29
- isStringWithLength,
30
- isSymbol,
31
- isUndefined,
32
- } from './type-predicate.js';
33
-
34
- import type { NumericString, NumericValue, Primitive, StringRecord, UnknownRecord } from './types.js';
35
-
36
- function getError(error: string | Error): Error {
37
- return error instanceof Error ? error : new TypeError(error);
38
- }
39
-
40
- export function assertIsBigInt(
41
- input: unknown,
42
- error: string | Error = 'input is not a bigint',
43
- ): asserts input is bigint {
44
- if (!isBigInt(input)) {
45
- throw getError(error);
46
- }
47
- }
48
-
49
- export function assertIsBoolean(
50
- input: unknown,
51
- error: string | Error = 'input is not a boolean',
52
- ): asserts input is boolean {
53
- if (!isBoolean(input)) {
54
- throw getError(error);
55
- }
56
- }
57
-
58
- export function assertIsFiniteNumber(
59
- input: unknown,
60
- error: string | Error = 'input is not a finite number',
61
- ): asserts input is number {
62
- if (!isFiniteNumber(input)) {
63
- throw getError(error);
64
- }
65
- }
66
-
67
- export function assertIsInteger(
68
- input: unknown,
69
- error: string | Error = 'input is not an integer',
70
- ): asserts input is number {
71
- if (!isInteger(input)) {
72
- throw getError(error);
73
- }
74
- }
75
-
76
- export function assertIsIntString(
77
- input: unknown,
78
- error: string | Error = 'input is not an integer string',
79
- ): asserts input is NumericString {
80
- if (!isIntString(input)) {
81
- throw getError(error);
82
- }
83
- }
84
-
85
- export function assertIsLengthAware(
86
- input: unknown,
87
- error: string | Error = 'input is not length aware',
88
- ): asserts input is { length: number } {
89
- if (!isLengthAware(input)) {
90
- throw getError(error);
91
- }
92
- }
93
-
94
- export function assertIsNull(input: unknown, error: string | Error = 'input is not null'): asserts input is null {
95
- if (!isNull(input)) {
96
- throw getError(error);
97
- }
98
- }
99
-
100
- export function assertIsNumber(
101
- input: unknown,
102
- error: string | Error = 'input is not a number',
103
- ): asserts input is number {
104
- if (!isNumber(input)) {
105
- throw getError(error);
106
- }
107
- }
108
-
109
- export function assertIsNumericString(
110
- input: unknown,
111
- error: string | Error = 'input is not a numeric string',
112
- ): asserts input is NumericString {
113
- if (!isNumericString(input)) {
114
- throw getError(error);
115
- }
116
- }
117
-
118
- export function assertIsNumericValue(
119
- input: unknown,
120
- error: string | Error = 'input is not a numerical value',
121
- ): asserts input is NumericValue {
122
- if (!isNumericValue(input)) {
123
- throw getError(error);
124
- }
125
- }
126
-
127
- export function assertIsNumericValueArray(
128
- input: unknown,
129
- error: string | Error = 'input is not a numerical value array',
130
- ): asserts input is NumericValue[] {
131
- if (!isNumericValueArray(input)) {
132
- throw getError(error);
133
- }
134
- }
135
-
136
- export function assertIsObject<T extends UnknownRecord = UnknownRecord>(
137
- input: unknown,
138
- error: string | Error = 'input is not an object',
139
- ): asserts input is T {
140
- if (!isObject<T>(input)) {
141
- throw getError(error);
142
- }
143
- }
144
-
145
- export function assertIsOptionalBigInt(
146
- input: unknown,
147
- error: string | Error = 'input is not an optional bigint',
148
- ): asserts input is bigint | undefined {
149
- if (!isOptionalBigInt(input)) {
150
- throw getError(error);
151
- }
152
- }
153
-
154
- export function assertIsOptionalBoolean(
155
- input: unknown,
156
- error: string | Error = 'input is not an optional boolean',
157
- ): asserts input is boolean | undefined {
158
- if (!isOptionalBoolean(input)) {
159
- throw getError(error);
160
- }
161
- }
162
-
163
- export function assertIsOptionalNull(
164
- input: unknown,
165
- error: string | Error = 'input is not an optional null',
166
- ): asserts input is null | undefined {
167
- if (!isOptionalNull(input)) {
168
- throw getError(error);
169
- }
170
- }
171
-
172
- export function assertIsOptionalNumber(
173
- input: unknown,
174
- error: string | Error = 'input is not an optional number',
175
- ): asserts input is number | undefined {
176
- if (!isOptionalNumber(input)) {
177
- throw getError(error);
178
- }
179
- }
180
-
181
- export function assertIsOptionalString(
182
- input: unknown,
183
- error: string | Error = 'input is not an optional string',
184
- ): asserts input is string | undefined {
185
- if (!isOptionalString(input)) {
186
- throw getError(error);
187
- }
188
- }
189
-
190
- export function assertIsOptionalSymbol(
191
- input: unknown,
192
- error: string | Error = 'input is not an optional symbol',
193
- ): asserts input is symbol | undefined {
194
- if (!isOptionalSymbol(input)) {
195
- throw getError(error);
196
- }
197
- }
198
-
199
- export function assertIsPositiveFiniteNumber(
200
- input: unknown,
201
- error: string | Error = 'input is not a positive finite number',
202
- ): asserts input is number {
203
- if (!isPositiveFiniteNumber(input)) {
204
- throw getError(error);
205
- }
206
- }
207
-
208
- export function assertIsNumberGTEOne(
209
- input: unknown,
210
- error: string | Error = 'input is not a number >= 1',
211
- ): asserts input is number {
212
- if (!isPositiveFiniteNumber(input) || input < 1) {
213
- throw getError(error);
214
- }
215
- }
216
-
217
- export function assertIsPositiveInteger(
218
- input: unknown,
219
- error: string | Error = 'input is not a positive integer',
220
- ): asserts input is number {
221
- if (!isPositiveInteger(input)) {
222
- throw getError(error);
223
- }
224
- }
225
-
226
- export function assertIsPrimitive(
227
- input: unknown,
228
- error: string | Error = 'input is not primitive',
229
- ): asserts input is Primitive {
230
- if (!isPrimitive(input)) {
231
- throw getError(error);
232
- }
233
- }
234
-
235
- export function assertIsPromiseFulfilledResult<T>(
236
- input: unknown,
237
- error: string | Error = 'input is not a promise fulfilled result',
238
- ): asserts input is PromiseFulfilledResult<T> {
239
- if (!isPromiseFulfilledResult(input)) {
240
- throw getError(error);
241
- }
242
- }
243
-
244
- export function assertIsPromiseRejectedResult(
245
- input: unknown,
246
- error: string | Error = 'input is not a promise rejected result',
247
- ): asserts input is PromiseRejectedResult {
248
- if (!isPromiseRejectedResult(input)) {
249
- throw getError(error);
250
- }
251
- }
252
-
253
- export function assertIsPropertyKey(
254
- input: unknown,
255
- error: string | Error = 'input is not a property key',
256
- ): asserts input is PropertyKey {
257
- if (!isPropertyKey(input)) {
258
- throw getError(error);
259
- }
260
- }
261
-
262
- export function assertIsString(
263
- input: unknown,
264
- error: string | Error = 'input is not a string',
265
- ): asserts input is string {
266
- if (!isString(input)) {
267
- throw getError(error);
268
- }
269
- }
270
-
271
- export function assertIsStringMatching(
272
- input: unknown,
273
- pattern: RegExp,
274
- error: string | Error = 'input is not a string that matches the pattern',
275
- ): asserts input is string {
276
- if (!isStringMatching(input, pattern)) {
277
- throw getError(error);
278
- }
279
- }
280
-
281
- export function assertIsStringRecord(
282
- input: unknown,
283
- error: string | Error = 'input is not a string record',
284
- ): asserts input is StringRecord {
285
- if (!isStringRecord(input)) {
286
- throw getError(error);
287
- }
288
- }
289
-
290
- export function assertIsStringWithLength(
291
- input: unknown,
292
- error: string | Error = 'input is not a string with length',
293
- ): asserts input is string {
294
- if (!isStringWithLength(input)) {
295
- throw getError(error);
296
- }
297
- }
298
-
299
- export function assertIsSymbol(
300
- input: unknown,
301
- error: string | Error = 'input is not a symbol',
302
- ): asserts input is symbol {
303
- if (!isSymbol(input)) {
304
- throw getError(error);
305
- }
306
- }
307
-
308
- export function assertIsUndefined(
309
- input: unknown,
310
- error: string | Error = 'input is not undefined',
311
- ): asserts input is undefined {
312
- if (!isUndefined(input)) {
313
- throw getError(error);
314
- }
315
- }
316
-
317
- export function assertExhaustive(_: never, error: string | Error = 'Failed exhaustive check'): never {
318
- throw getError(error);
319
- }
@@ -1,101 +0,0 @@
1
- import type { NumericString, NumericValue, Primitive, StringRecord, TypePredicateFn, UnknownRecord } from './types.js';
2
-
3
- export const createIsEnumPredicate = <E extends Record<string, unknown>, T = E>(enumObject: E): TypePredicateFn<T> => {
4
- const values = Object.values(enumObject);
5
-
6
- return (input: unknown): input is T => {
7
- return values.includes(input);
8
- };
9
- };
10
-
11
- export const maybeUndefined = <T>(predicate: TypePredicateFn<T>, input: unknown): input is T | undefined => {
12
- return typeof input === 'undefined' || predicate(input);
13
- };
14
-
15
- // Primitives
16
-
17
- export const isString = (input: unknown): input is string => typeof input === 'string';
18
-
19
- export const isNumber = (input: unknown): input is number => typeof input === 'number' && !Number.isNaN(input);
20
-
21
- export const isBigInt = (input: unknown): input is bigint => typeof input === 'bigint';
22
-
23
- export const isBoolean = (input: unknown): input is boolean => typeof input === 'boolean';
24
-
25
- export const isUndefined = (input: unknown): input is undefined => typeof input === 'undefined';
26
-
27
- export const isSymbol = (input: unknown): input is symbol => typeof input === 'symbol';
28
-
29
- export const isNull = (input: unknown): input is null => input === null;
30
-
31
- export const isPrimitive = (input: unknown): input is Primitive =>
32
- isString(input) ||
33
- isNumber(input) ||
34
- isBigInt(input) ||
35
- isBoolean(input) ||
36
- isUndefined(input) ||
37
- isSymbol(input) ||
38
- isNull(input);
39
-
40
- // Optional primitives
41
-
42
- export const isOptionalString = (input: unknown): input is string | undefined => maybeUndefined(isString, input);
43
-
44
- export const isOptionalNumber = (input: unknown): input is number | undefined => maybeUndefined(isNumber, input);
45
-
46
- export const isOptionalBigInt = (input: unknown): input is bigint | undefined => maybeUndefined(isBigInt, input);
47
-
48
- export const isOptionalBoolean = (input: unknown): input is boolean | undefined => maybeUndefined(isBoolean, input);
49
-
50
- export const isOptionalSymbol = (input: unknown): input is symbol | undefined => maybeUndefined(isSymbol, input);
51
-
52
- export const isOptionalNull = (input: unknown): input is null | undefined => maybeUndefined(isNull, input);
53
-
54
- // Primitives with extra checks
55
-
56
- export const isStringWithLength = (input: unknown): input is string => typeof input === 'string' && input.length > 0;
57
-
58
- export const isStringMatching = (input: unknown, pattern: RegExp): input is string =>
59
- typeof input === 'string' && pattern.test(input);
60
-
61
- export const isNumericString = (input: unknown): input is NumericString =>
62
- isStringMatching(input, /^[-+]?\d+(\.\d+)?$/);
63
-
64
- export const isNumericValue = (input: unknown): input is NumericValue =>
65
- typeof input === 'number' || typeof input === 'bigint' || isNumericString(input);
66
-
67
- export const isNumericValueArray = (input: unknown): input is NumericValue[] =>
68
- Array.isArray(input) && input.every(isNumericValue);
69
-
70
- export const isIntString = (input: unknown): input is NumericString => isStringMatching(input, /^[-+]?\d+$/);
71
-
72
- export const isFiniteNumber = (input: unknown): input is number => Number.isFinite(input);
73
-
74
- export const isInteger = (input: unknown): input is number => Number.isInteger(input);
75
-
76
- export const isPositiveInteger = (input: unknown): input is number => isInteger(input) && input >= 0;
77
-
78
- export const isPositiveFiniteNumber = (input: unknown): input is number => isFiniteNumber(input) && input >= 0;
79
-
80
- // Common types
81
-
82
- export const isPropertyKey = (input: unknown): input is PropertyKey =>
83
- typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
84
-
85
- export const isObject = <T extends UnknownRecord = UnknownRecord>(input: unknown): input is T =>
86
- input !== null && typeof input === 'object' && !Array.isArray(input);
87
-
88
- export const isLengthAware = (input: unknown): input is { length: number } =>
89
- input !== null && typeof input === 'object' && 'length' in input && typeof input.length === 'number';
90
-
91
- export const isStringRecord = (input: unknown): input is StringRecord => {
92
- return isObject(input) && Object.entries(input).every(entry => entry.every(isString));
93
- };
94
-
95
- export const isPromiseFulfilledResult = <T>(input: unknown): input is PromiseFulfilledResult<T> => {
96
- return isObject(input) && input.status === 'fulfilled';
97
- };
98
-
99
- export const isPromiseRejectedResult = (input: unknown): input is PromiseRejectedResult => {
100
- return isObject(input) && input.status === 'rejected' && 'reason' in input;
101
- };
package/src/types.ts DELETED
@@ -1,48 +0,0 @@
1
- export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
2
-
3
- // eslint-disable-next-line @typescript-eslint/ban-types
4
- export type Builtin = Date | Error | Function | Primitive | RegExp;
5
-
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- export type AnyRecord = Record<PropertyKey, any>;
8
-
9
- export type StringRecord = Record<string, string>;
10
-
11
- export type UnknownRecord = Record<PropertyKey, unknown>;
12
-
13
- export type NumericString<T extends string | number = number> = `${T}` extends `${number}` ? `${T}` : never;
14
-
15
- export type NumericValue = number | bigint | NumericString;
16
-
17
- export type MaybePlural<T extends string> = T | `${T}s`;
18
-
19
- export type StringKeys<T> = keyof T & string;
20
-
21
- export type IfDefined<T, D, U> = undefined extends T ? U : D;
22
-
23
- export type IfNever<T, N, O> = [T] extends [never] ? N : O;
24
-
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- export type ReturnTypeDefault<F, D = undefined> = F extends (...args: any) => infer R ? R : D;
27
-
28
- export type AnyNewable = {
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- new (...args: any[]): any;
31
- };
32
-
33
- export type JoinTuples<A extends unknown[], B extends unknown[]> = [...A, ...B];
34
-
35
- export type RangeTuple<T> = [min: T, max: T];
36
-
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- export type RangeTupleDistributive<T> = T extends any ? [min: T, max: T] : never;
39
-
40
- export type NumberRangeTuple = RangeTuple<number>;
41
-
42
- export type KeyValueTuple<K extends PropertyKey = PropertyKey, V = unknown> = [key: K, value: V];
43
-
44
- export type Predicate<A, T extends A = A> =
45
- | ((value: T, index: number, array: readonly A[]) => value is T)
46
- | ((value: T, index: number, array: readonly A[]) => unknown);
47
-
48
- export type TypePredicateFn<T> = (input: unknown) => input is T;
@@ -1,3 +0,0 @@
1
- export function uniqueItems<T>(data: T[]): T[] {
2
- return [...new Set<T>(data)];
3
- }