@wistia/utils 1.2.0 → 1.3.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 +6 -0
- package/README.md +1 -0
- package/dist/index.d.mts +31 -205
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +134 -194
- package/dist/index.mjs.map +1 -1
- package/llms-full.txt +29 -0
- package/llms.txt +1 -0
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
|
-
* @license @wistia/utils v1.
|
|
3
|
+
* @license @wistia/utils v1.3.0
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) 2023-2026, Wistia, Inc. and its affiliates.
|
|
6
6
|
*
|
|
7
7
|
* This source code is unlicensed, all rights reserved.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// src/guards/isNull.ts
|
|
11
11
|
/**
|
|
12
12
|
* Checks if the provided value is null.
|
|
13
13
|
*
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
* @category Primitives
|
|
22
22
|
*/
|
|
23
23
|
const isNull = (value) => value === null;
|
|
24
|
-
|
|
25
|
-
//#region src/guards/isUndefined.ts
|
|
24
|
+
// src/guards/isUndefined.ts
|
|
26
25
|
/**
|
|
27
26
|
* Checks if the provided value is undefined.
|
|
28
27
|
*
|
|
@@ -36,8 +35,7 @@ const isNull = (value) => value === null;
|
|
|
36
35
|
* @category Primitives
|
|
37
36
|
*/
|
|
38
37
|
const isUndefined = (value) => value === void 0;
|
|
39
|
-
|
|
40
|
-
//#region src/guards/isNil.ts
|
|
38
|
+
// src/guards/isNil.ts
|
|
41
39
|
/**
|
|
42
40
|
* Checks if the provided value is null or undefined.
|
|
43
41
|
*
|
|
@@ -51,8 +49,7 @@ const isUndefined = (value) => value === void 0;
|
|
|
51
49
|
* @category Primitives
|
|
52
50
|
*/
|
|
53
51
|
const isNil = (value) => isNull(value) || isUndefined(value);
|
|
54
|
-
|
|
55
|
-
//#region src/guards/isNotNil.ts
|
|
52
|
+
// src/guards/isNotNil.ts
|
|
56
53
|
/**
|
|
57
54
|
* Checks if the provided value is neither null nor undefined.
|
|
58
55
|
*
|
|
@@ -73,8 +70,7 @@ const isNil = (value) => isNull(value) || isUndefined(value);
|
|
|
73
70
|
* @category Negated
|
|
74
71
|
*/
|
|
75
72
|
const isNotNil = (value) => !isNil(value);
|
|
76
|
-
|
|
77
|
-
//#region src/guards/isRecord.ts
|
|
73
|
+
// src/guards/isRecord.ts
|
|
78
74
|
/**
|
|
79
75
|
* Checks if the provided value is a non-null object that is not an array.
|
|
80
76
|
*
|
|
@@ -88,8 +84,7 @@ const isNotNil = (value) => !isNil(value);
|
|
|
88
84
|
* @category Records
|
|
89
85
|
*/
|
|
90
86
|
const isRecord = (value) => isNotNil(value) && typeof value === "object" && !Array.isArray(value);
|
|
91
|
-
|
|
92
|
-
//#region src/guards/isNonEmptyRecord.ts
|
|
87
|
+
// src/guards/isNonEmptyRecord.ts
|
|
93
88
|
/**
|
|
94
89
|
* Checks if the provided value is an object with at least one own property.
|
|
95
90
|
*
|
|
@@ -103,8 +98,7 @@ const isRecord = (value) => isNotNil(value) && typeof value === "object" && !Arr
|
|
|
103
98
|
* @category Records
|
|
104
99
|
*/
|
|
105
100
|
const isNonEmptyRecord = (value) => isRecord(value) && Object.keys(value).length > 0;
|
|
106
|
-
|
|
107
|
-
//#region src/guards/hasKey.ts
|
|
101
|
+
// src/guards/hasKey.ts
|
|
108
102
|
/**
|
|
109
103
|
* Curried function that tests if an input is an object
|
|
110
104
|
* _and_ that a key that was passed in is a property of that object.
|
|
@@ -121,8 +115,7 @@ const isNonEmptyRecord = (value) => isRecord(value) && Object.keys(value).length
|
|
|
121
115
|
* @category Records
|
|
122
116
|
*/
|
|
123
117
|
const hasKey = (value, key) => isNonEmptyRecord(value) && key in value;
|
|
124
|
-
|
|
125
|
-
//#region src/guards/isArray.ts
|
|
118
|
+
// src/guards/isArray.ts
|
|
126
119
|
/**
|
|
127
120
|
* Checks if the provided value is an array.
|
|
128
121
|
*
|
|
@@ -136,8 +129,7 @@ const hasKey = (value, key) => isNonEmptyRecord(value) && key in value;
|
|
|
136
129
|
* @category Arrays
|
|
137
130
|
*/
|
|
138
131
|
const isArray = (value) => isNotNil(value) && typeof value === "object" && Array.isArray(value);
|
|
139
|
-
|
|
140
|
-
//#region src/guards/isFunction.ts
|
|
132
|
+
// src/guards/isFunction.ts
|
|
141
133
|
/**
|
|
142
134
|
* Checks if the provided value is a function.
|
|
143
135
|
*
|
|
@@ -151,8 +143,7 @@ const isArray = (value) => isNotNil(value) && typeof value === "object" && Array
|
|
|
151
143
|
* @category Primitives
|
|
152
144
|
*/
|
|
153
145
|
const isFunction = (value) => isNotNil(value) && typeof value === "function";
|
|
154
|
-
|
|
155
|
-
//#region src/guards/isAsyncFunction.ts
|
|
146
|
+
// src/guards/isAsyncFunction.ts
|
|
156
147
|
/**
|
|
157
148
|
* Checks if the provided value is an async function.
|
|
158
149
|
*
|
|
@@ -176,8 +167,7 @@ const isFunction = (value) => isNotNil(value) && typeof value === "function";
|
|
|
176
167
|
const isAsyncFunction = (value) => {
|
|
177
168
|
return isFunction(value) && value.constructor?.name === "AsyncFunction";
|
|
178
169
|
};
|
|
179
|
-
|
|
180
|
-
//#region src/guards/isBigInt.ts
|
|
170
|
+
// src/guards/isBigInt.ts
|
|
181
171
|
/**
|
|
182
172
|
* Checks if the provided value is a bigint.
|
|
183
173
|
*
|
|
@@ -191,8 +181,7 @@ const isAsyncFunction = (value) => {
|
|
|
191
181
|
* @category Primitives
|
|
192
182
|
*/
|
|
193
183
|
const isBigInt = (value) => typeof value === "bigint";
|
|
194
|
-
|
|
195
|
-
//#region src/guards/isBoolean.ts
|
|
184
|
+
// src/guards/isBoolean.ts
|
|
196
185
|
/**
|
|
197
186
|
* Checks if the provided value is a boolean.
|
|
198
187
|
*
|
|
@@ -206,8 +195,7 @@ const isBigInt = (value) => typeof value === "bigint";
|
|
|
206
195
|
* @category Primitives
|
|
207
196
|
*/
|
|
208
197
|
const isBoolean = (value) => isNotNil(value) && typeof value === "boolean";
|
|
209
|
-
|
|
210
|
-
//#region src/guards/isDate.ts
|
|
198
|
+
// src/guards/isDate.ts
|
|
211
199
|
/**
|
|
212
200
|
* Checks if the provided value is an instance of Date.
|
|
213
201
|
*
|
|
@@ -227,8 +215,7 @@ const isBoolean = (value) => isNotNil(value) && typeof value === "boolean";
|
|
|
227
215
|
const isDate = (value) => {
|
|
228
216
|
return isNotNil(value) && value instanceof Date;
|
|
229
217
|
};
|
|
230
|
-
|
|
231
|
-
//#region src/guards/isEmptyArray.ts
|
|
218
|
+
// src/guards/isEmptyArray.ts
|
|
232
219
|
/**
|
|
233
220
|
* Checks if the provided value is an empty array.
|
|
234
221
|
*
|
|
@@ -242,8 +229,7 @@ const isDate = (value) => {
|
|
|
242
229
|
* @category Arrays
|
|
243
230
|
*/
|
|
244
231
|
const isEmptyArray = (value) => isArray(value) && value.length === 0;
|
|
245
|
-
|
|
246
|
-
//#region src/guards/isEmptyRecord.ts
|
|
232
|
+
// src/guards/isEmptyRecord.ts
|
|
247
233
|
/**
|
|
248
234
|
* Checks if the provided value is an object with no own properties.
|
|
249
235
|
*
|
|
@@ -257,8 +243,7 @@ const isEmptyArray = (value) => isArray(value) && value.length === 0;
|
|
|
257
243
|
* @category Records
|
|
258
244
|
*/
|
|
259
245
|
const isEmptyRecord = (value) => isRecord(value) && Object.keys(value).length === 0;
|
|
260
|
-
|
|
261
|
-
//#region src/guards/isString.ts
|
|
246
|
+
// src/guards/isString.ts
|
|
262
247
|
/**
|
|
263
248
|
* Checks if the provided value is a string.
|
|
264
249
|
*
|
|
@@ -272,8 +257,7 @@ const isEmptyRecord = (value) => isRecord(value) && Object.keys(value).length ==
|
|
|
272
257
|
* @category Primitives
|
|
273
258
|
*/
|
|
274
259
|
const isString = (value) => typeof value === "string";
|
|
275
|
-
|
|
276
|
-
//#region src/guards/isEmptyString.ts
|
|
260
|
+
// src/guards/isEmptyString.ts
|
|
277
261
|
/**
|
|
278
262
|
* Checks if the provided value is an empty string.
|
|
279
263
|
*
|
|
@@ -287,8 +271,7 @@ const isString = (value) => typeof value === "string";
|
|
|
287
271
|
* @category Strings
|
|
288
272
|
*/
|
|
289
273
|
const isEmptyString = (value) => isString(value) && value === "";
|
|
290
|
-
|
|
291
|
-
//#region src/guards/isError.ts
|
|
274
|
+
// src/guards/isError.ts
|
|
292
275
|
/**
|
|
293
276
|
* Checks if the provided value is an instance of Error.
|
|
294
277
|
*
|
|
@@ -307,8 +290,7 @@ const isEmptyString = (value) => isString(value) && value === "";
|
|
|
307
290
|
const isError = (value) => {
|
|
308
291
|
return isNotNil(value) && value instanceof Error;
|
|
309
292
|
};
|
|
310
|
-
|
|
311
|
-
//#region src/guards/_falsyValues.ts
|
|
293
|
+
// src/guards/_falsyValues.ts
|
|
312
294
|
const FALSY_VALUES = [
|
|
313
295
|
false,
|
|
314
296
|
0,
|
|
@@ -319,8 +301,7 @@ const FALSY_VALUES = [
|
|
|
319
301
|
void 0,
|
|
320
302
|
NaN
|
|
321
303
|
];
|
|
322
|
-
|
|
323
|
-
//#region src/guards/isFalsy.ts
|
|
304
|
+
// src/guards/isFalsy.ts
|
|
324
305
|
/**
|
|
325
306
|
* Checks if the provided value is falsy.
|
|
326
307
|
*
|
|
@@ -338,8 +319,7 @@ const FALSY_VALUES = [
|
|
|
338
319
|
* @category Truthy / falsy
|
|
339
320
|
*/
|
|
340
321
|
const isFalsy = (value) => FALSY_VALUES.includes(value) || Number.isNaN(value);
|
|
341
|
-
|
|
342
|
-
//#region src/guards/isNumber.ts
|
|
322
|
+
// src/guards/isNumber.ts
|
|
343
323
|
/**
|
|
344
324
|
* Checks if the provided value is a number.
|
|
345
325
|
*
|
|
@@ -357,8 +337,7 @@ const isFalsy = (value) => FALSY_VALUES.includes(value) || Number.isNaN(value);
|
|
|
357
337
|
* @category Primitives
|
|
358
338
|
*/
|
|
359
339
|
const isNumber = (value) => typeof value === "number";
|
|
360
|
-
|
|
361
|
-
//#region src/guards/isFiniteNumber.ts
|
|
340
|
+
// src/guards/isFiniteNumber.ts
|
|
362
341
|
/**
|
|
363
342
|
* Checks if the provided value is a finite number.
|
|
364
343
|
*
|
|
@@ -372,8 +351,7 @@ const isNumber = (value) => typeof value === "number";
|
|
|
372
351
|
* @category Primitives
|
|
373
352
|
*/
|
|
374
353
|
const isFiniteNumber = (value) => isNumber(value) && Number.isFinite(value);
|
|
375
|
-
|
|
376
|
-
//#region src/guards/isHtmlButtonElement.ts
|
|
354
|
+
// src/guards/isHtmlButtonElement.ts
|
|
377
355
|
/**
|
|
378
356
|
* Checks if the provided value is an HTMLButtonElement.
|
|
379
357
|
*
|
|
@@ -387,8 +365,7 @@ const isFiniteNumber = (value) => isNumber(value) && Number.isFinite(value);
|
|
|
387
365
|
* @category DOM
|
|
388
366
|
*/
|
|
389
367
|
const isHtmlButtonElement = (value) => value instanceof HTMLButtonElement;
|
|
390
|
-
|
|
391
|
-
//#region src/guards/isHtmlElement.ts
|
|
368
|
+
// src/guards/isHtmlElement.ts
|
|
392
369
|
/**
|
|
393
370
|
* Checks if the provided value is an HTMLElement.
|
|
394
371
|
*
|
|
@@ -402,8 +379,7 @@ const isHtmlButtonElement = (value) => value instanceof HTMLButtonElement;
|
|
|
402
379
|
* @category DOM
|
|
403
380
|
*/
|
|
404
381
|
const isHtmlElement = (value) => value instanceof HTMLElement;
|
|
405
|
-
|
|
406
|
-
//#region src/guards/isHtmlInputElement.ts
|
|
382
|
+
// src/guards/isHtmlInputElement.ts
|
|
407
383
|
/**
|
|
408
384
|
* Checks if the provided value is an HTMLInputElement.
|
|
409
385
|
*
|
|
@@ -417,8 +393,7 @@ const isHtmlElement = (value) => value instanceof HTMLElement;
|
|
|
417
393
|
* @category DOM
|
|
418
394
|
*/
|
|
419
395
|
const isHtmlInputElement = (value) => value instanceof HTMLInputElement;
|
|
420
|
-
|
|
421
|
-
//#region src/guards/isHtmlVideoElement.ts
|
|
396
|
+
// src/guards/isHtmlVideoElement.ts
|
|
422
397
|
/**
|
|
423
398
|
* Checks if the provided value is an HTMLVideoElement.
|
|
424
399
|
*
|
|
@@ -432,8 +407,7 @@ const isHtmlInputElement = (value) => value instanceof HTMLInputElement;
|
|
|
432
407
|
* @category DOM
|
|
433
408
|
*/
|
|
434
409
|
const isHtmlVideoElement = (value) => value instanceof HTMLVideoElement;
|
|
435
|
-
|
|
436
|
-
//#region src/guards/isInteger.ts
|
|
410
|
+
// src/guards/isInteger.ts
|
|
437
411
|
/**
|
|
438
412
|
* Checks if the provided value is an integer.
|
|
439
413
|
*
|
|
@@ -451,8 +425,7 @@ const isHtmlVideoElement = (value) => value instanceof HTMLVideoElement;
|
|
|
451
425
|
* @category Primitives
|
|
452
426
|
*/
|
|
453
427
|
const isInteger = (value) => Number.isInteger(value);
|
|
454
|
-
|
|
455
|
-
//#region src/guards/isIterable.ts
|
|
428
|
+
// src/guards/isIterable.ts
|
|
456
429
|
/**
|
|
457
430
|
* Checks if the provided value implements the iterable protocol.
|
|
458
431
|
*
|
|
@@ -473,8 +446,7 @@ const isIterable = (value) => {
|
|
|
473
446
|
if (!isNotNil(value)) return false;
|
|
474
447
|
return typeof value[Symbol.iterator] === "function";
|
|
475
448
|
};
|
|
476
|
-
|
|
477
|
-
//#region src/guards/isMap.ts
|
|
449
|
+
// src/guards/isMap.ts
|
|
478
450
|
/**
|
|
479
451
|
* Checks if the provided value is an instance of Map.
|
|
480
452
|
*
|
|
@@ -493,8 +465,7 @@ const isIterable = (value) => {
|
|
|
493
465
|
const isMap = (value) => {
|
|
494
466
|
return isNotNil(value) && value instanceof Map;
|
|
495
467
|
};
|
|
496
|
-
|
|
497
|
-
//#region src/guards/isMouseEvent.ts
|
|
468
|
+
// src/guards/isMouseEvent.ts
|
|
498
469
|
/**
|
|
499
470
|
* Checks if the provided value is a MouseEvent.
|
|
500
471
|
*
|
|
@@ -508,8 +479,7 @@ const isMap = (value) => {
|
|
|
508
479
|
* @category DOM
|
|
509
480
|
*/
|
|
510
481
|
const isMouseEvent = (value) => value instanceof MouseEvent;
|
|
511
|
-
|
|
512
|
-
//#region src/guards/isNaN.ts
|
|
482
|
+
// src/guards/isNaN.ts
|
|
513
483
|
/**
|
|
514
484
|
* Checks if the provided value is NaN (Not a Number).
|
|
515
485
|
*
|
|
@@ -527,8 +497,7 @@ const isMouseEvent = (value) => value instanceof MouseEvent;
|
|
|
527
497
|
* @category Primitives
|
|
528
498
|
*/
|
|
529
499
|
const isNaN = (value) => Number.isNaN(value);
|
|
530
|
-
|
|
531
|
-
//#region src/guards/isNonBlankString.ts
|
|
500
|
+
// src/guards/isNonBlankString.ts
|
|
532
501
|
/**
|
|
533
502
|
* Checks if the provided value is a non-blank string (not empty and not whitespace-only).
|
|
534
503
|
* Use {@link isNonEmptyString} when whitespace-only strings are acceptable (e.g. preserving
|
|
@@ -544,8 +513,7 @@ const isNaN = (value) => Number.isNaN(value);
|
|
|
544
513
|
* @category Strings
|
|
545
514
|
*/
|
|
546
515
|
const isNonBlankString = (value) => isString(value) && value.trim() !== "";
|
|
547
|
-
|
|
548
|
-
//#region src/guards/isNonEmptyArray.ts
|
|
516
|
+
// src/guards/isNonEmptyArray.ts
|
|
549
517
|
/**
|
|
550
518
|
* Checks if the provided value is a non-empty array.
|
|
551
519
|
*
|
|
@@ -559,8 +527,7 @@ const isNonBlankString = (value) => isString(value) && value.trim() !== "";
|
|
|
559
527
|
* @category Arrays
|
|
560
528
|
*/
|
|
561
529
|
const isNonEmptyArray = (value) => isArray(value) && value.length > 0;
|
|
562
|
-
|
|
563
|
-
//#region src/guards/isNonEmptyString.ts
|
|
530
|
+
// src/guards/isNonEmptyString.ts
|
|
564
531
|
/**
|
|
565
532
|
* Checks if the provided value is a non-empty string. Whitespace-only strings like `" "` pass.
|
|
566
533
|
* Use {@link isNonBlankString} when whitespace-only strings should be rejected (e.g. user input
|
|
@@ -576,8 +543,7 @@ const isNonEmptyArray = (value) => isArray(value) && value.length > 0;
|
|
|
576
543
|
* @category Strings
|
|
577
544
|
*/
|
|
578
545
|
const isNonEmptyString = (value) => isString(value) && !isEmptyString(value);
|
|
579
|
-
|
|
580
|
-
//#region src/guards/isNonNaNNumber.ts
|
|
546
|
+
// src/guards/isNonNaNNumber.ts
|
|
581
547
|
/**
|
|
582
548
|
* Checks if the provided value is a number that is not NaN.
|
|
583
549
|
*
|
|
@@ -591,8 +557,7 @@ const isNonEmptyString = (value) => isString(value) && !isEmptyString(value);
|
|
|
591
557
|
* @category Primitives
|
|
592
558
|
*/
|
|
593
559
|
const isNonNaNNumber = (value) => isNumber(value) && !isNaN(value);
|
|
594
|
-
|
|
595
|
-
//#region src/guards/isNotArray.ts
|
|
560
|
+
// src/guards/isNotArray.ts
|
|
596
561
|
/**
|
|
597
562
|
* Checks if the provided value is not an array.
|
|
598
563
|
*
|
|
@@ -606,8 +571,7 @@ const isNonNaNNumber = (value) => isNumber(value) && !isNaN(value);
|
|
|
606
571
|
* @category Negated
|
|
607
572
|
*/
|
|
608
573
|
const isNotArray = (value) => !isArray(value);
|
|
609
|
-
|
|
610
|
-
//#region src/guards/isNotBoolean.ts
|
|
574
|
+
// src/guards/isNotBoolean.ts
|
|
611
575
|
/**
|
|
612
576
|
* Checks if the provided value is not a boolean.
|
|
613
577
|
*
|
|
@@ -621,8 +585,7 @@ const isNotArray = (value) => !isArray(value);
|
|
|
621
585
|
* @category Negated
|
|
622
586
|
*/
|
|
623
587
|
const isNotBoolean = (value) => !isBoolean(value);
|
|
624
|
-
|
|
625
|
-
//#region src/guards/isNotFunction.ts
|
|
588
|
+
// src/guards/isNotFunction.ts
|
|
626
589
|
/**
|
|
627
590
|
* Checks if the provided value is not a function.
|
|
628
591
|
*
|
|
@@ -636,8 +599,7 @@ const isNotBoolean = (value) => !isBoolean(value);
|
|
|
636
599
|
* @category Negated
|
|
637
600
|
*/
|
|
638
601
|
const isNotFunction = (value) => !isFunction(value);
|
|
639
|
-
|
|
640
|
-
//#region src/guards/isNotNull.ts
|
|
602
|
+
// src/guards/isNotNull.ts
|
|
641
603
|
/**
|
|
642
604
|
* Checks if the provided value is not null.
|
|
643
605
|
*
|
|
@@ -651,8 +613,7 @@ const isNotFunction = (value) => !isFunction(value);
|
|
|
651
613
|
* @category Negated
|
|
652
614
|
*/
|
|
653
615
|
const isNotNull = (value) => !isNull(value);
|
|
654
|
-
|
|
655
|
-
//#region src/guards/isNotNumber.ts
|
|
616
|
+
// src/guards/isNotNumber.ts
|
|
656
617
|
/**
|
|
657
618
|
* Checks if the provided value is not a number.
|
|
658
619
|
*
|
|
@@ -666,8 +627,7 @@ const isNotNull = (value) => !isNull(value);
|
|
|
666
627
|
* @category Negated
|
|
667
628
|
*/
|
|
668
629
|
const isNotNumber = (value) => !isNumber(value);
|
|
669
|
-
|
|
670
|
-
//#region src/guards/isNotRecord.ts
|
|
630
|
+
// src/guards/isNotRecord.ts
|
|
671
631
|
/**
|
|
672
632
|
* Checks if the provided value is not an object.
|
|
673
633
|
*
|
|
@@ -681,8 +641,7 @@ const isNotNumber = (value) => !isNumber(value);
|
|
|
681
641
|
* @category Negated
|
|
682
642
|
*/
|
|
683
643
|
const isNotRecord = (value) => !isRecord(value);
|
|
684
|
-
|
|
685
|
-
//#region src/guards/isNotString.ts
|
|
644
|
+
// src/guards/isNotString.ts
|
|
686
645
|
/**
|
|
687
646
|
* Checks if the provided value is not a string.
|
|
688
647
|
*
|
|
@@ -696,8 +655,7 @@ const isNotRecord = (value) => !isRecord(value);
|
|
|
696
655
|
* @category Negated
|
|
697
656
|
*/
|
|
698
657
|
const isNotString = (value) => !isString(value);
|
|
699
|
-
|
|
700
|
-
//#region src/guards/isNotUndefined.ts
|
|
658
|
+
// src/guards/isNotUndefined.ts
|
|
701
659
|
/**
|
|
702
660
|
* Checks if the provided value is not undefined.
|
|
703
661
|
*
|
|
@@ -711,8 +669,7 @@ const isNotString = (value) => !isString(value);
|
|
|
711
669
|
* @category Negated
|
|
712
670
|
*/
|
|
713
671
|
const isNotUndefined = (value) => !isUndefined(value);
|
|
714
|
-
|
|
715
|
-
//#region src/guards/isVoid.ts
|
|
672
|
+
// src/guards/isVoid.ts
|
|
716
673
|
/**
|
|
717
674
|
* Checks if the provided value is void.
|
|
718
675
|
*
|
|
@@ -726,8 +683,7 @@ const isNotUndefined = (value) => !isUndefined(value);
|
|
|
726
683
|
* @category Primitives
|
|
727
684
|
*/
|
|
728
685
|
const isVoid = (value) => value === void 0;
|
|
729
|
-
|
|
730
|
-
//#region src/guards/isNotVoid.ts
|
|
686
|
+
// src/guards/isNotVoid.ts
|
|
731
687
|
/**
|
|
732
688
|
* Checks if the provided value is not void.
|
|
733
689
|
*
|
|
@@ -741,8 +697,7 @@ const isVoid = (value) => value === void 0;
|
|
|
741
697
|
* @category Negated
|
|
742
698
|
*/
|
|
743
699
|
const isNotVoid = (value) => !isVoid(value);
|
|
744
|
-
|
|
745
|
-
//#region src/guards/isPlainObject.ts
|
|
700
|
+
// src/guards/isPlainObject.ts
|
|
746
701
|
/**
|
|
747
702
|
* Checks if the provided value is a plain object created with `{}` or `Object.create(null)`.
|
|
748
703
|
* Returns false for arrays, `Date`, `Map`, `RegExp`, boxed primitives, and class instances.
|
|
@@ -762,8 +717,7 @@ const isPlainObject = (value) => {
|
|
|
762
717
|
const proto = Object.getPrototypeOf(value);
|
|
763
718
|
return proto === Object.prototype || proto === null;
|
|
764
719
|
};
|
|
765
|
-
|
|
766
|
-
//#region src/guards/isPromise.ts
|
|
720
|
+
// src/guards/isPromise.ts
|
|
767
721
|
/**
|
|
768
722
|
* Checks if the provided value is a Promise, including promise-like objects
|
|
769
723
|
* that implement `then`, `catch`, and `finally`.
|
|
@@ -787,8 +741,7 @@ const isPromise = (value) => {
|
|
|
787
741
|
const candidate = value;
|
|
788
742
|
return typeof candidate.then === "function" && typeof candidate.catch === "function" && typeof candidate.finally === "function";
|
|
789
743
|
};
|
|
790
|
-
|
|
791
|
-
//#region src/guards/isRegExp.ts
|
|
744
|
+
// src/guards/isRegExp.ts
|
|
792
745
|
/**
|
|
793
746
|
* Checks if the provided value is an instance of RegExp.
|
|
794
747
|
*
|
|
@@ -804,8 +757,7 @@ const isPromise = (value) => {
|
|
|
804
757
|
const isRegExp = (value) => {
|
|
805
758
|
return isNotNil(value) && value instanceof RegExp;
|
|
806
759
|
};
|
|
807
|
-
|
|
808
|
-
//#region src/guards/isSet.ts
|
|
760
|
+
// src/guards/isSet.ts
|
|
809
761
|
/**
|
|
810
762
|
* Checks if the provided value is an instance of Set.
|
|
811
763
|
*
|
|
@@ -824,8 +776,7 @@ const isRegExp = (value) => {
|
|
|
824
776
|
const isSet = (value) => {
|
|
825
777
|
return isNotNil(value) && value instanceof Set;
|
|
826
778
|
};
|
|
827
|
-
|
|
828
|
-
//#region src/guards/isSvgElement.ts
|
|
779
|
+
// src/guards/isSvgElement.ts
|
|
829
780
|
/**
|
|
830
781
|
* Checks if the provided value is an SVGElement.
|
|
831
782
|
*
|
|
@@ -839,8 +790,7 @@ const isSet = (value) => {
|
|
|
839
790
|
* @category DOM
|
|
840
791
|
*/
|
|
841
792
|
const isSvgElement = (value) => value instanceof SVGElement;
|
|
842
|
-
|
|
843
|
-
//#region src/guards/isSymbol.ts
|
|
793
|
+
// src/guards/isSymbol.ts
|
|
844
794
|
/**
|
|
845
795
|
* Checks if the provided value is a symbol.
|
|
846
796
|
*
|
|
@@ -854,8 +804,7 @@ const isSvgElement = (value) => value instanceof SVGElement;
|
|
|
854
804
|
* @category Primitives
|
|
855
805
|
*/
|
|
856
806
|
const isSymbol = (value) => typeof value === "symbol";
|
|
857
|
-
|
|
858
|
-
//#region src/guards/isTextNode.ts
|
|
807
|
+
// src/guards/isTextNode.ts
|
|
859
808
|
/**
|
|
860
809
|
* Checks if the provided value is a Text node.
|
|
861
810
|
*
|
|
@@ -869,8 +818,7 @@ const isSymbol = (value) => typeof value === "symbol";
|
|
|
869
818
|
* @category DOM
|
|
870
819
|
*/
|
|
871
820
|
const isTextNode = (value) => value.nodeName === "#text";
|
|
872
|
-
|
|
873
|
-
//#region src/guards/isTruthy.ts
|
|
821
|
+
// src/guards/isTruthy.ts
|
|
874
822
|
/**
|
|
875
823
|
* Checks if the provided value is truthy.
|
|
876
824
|
*
|
|
@@ -888,8 +836,7 @@ const isTextNode = (value) => value.nodeName === "#text";
|
|
|
888
836
|
* @category Truthy / falsy
|
|
889
837
|
*/
|
|
890
838
|
const isTruthy = (value) => !FALSY_VALUES.includes(value) && !Number.isNaN(value);
|
|
891
|
-
|
|
892
|
-
//#region src/guards/isWeakMap.ts
|
|
839
|
+
// src/guards/isWeakMap.ts
|
|
893
840
|
/**
|
|
894
841
|
* Checks if the provided value is an instance of WeakMap.
|
|
895
842
|
*
|
|
@@ -909,8 +856,7 @@ const isTruthy = (value) => !FALSY_VALUES.includes(value) && !Number.isNaN(value
|
|
|
909
856
|
const isWeakMap = (value) => {
|
|
910
857
|
return isNotNil(value) && value instanceof WeakMap;
|
|
911
858
|
};
|
|
912
|
-
|
|
913
|
-
//#region src/guards/isWeakSet.ts
|
|
859
|
+
// src/guards/isWeakSet.ts
|
|
914
860
|
/**
|
|
915
861
|
* Checks if the provided value is an instance of WeakSet.
|
|
916
862
|
*
|
|
@@ -930,8 +876,7 @@ const isWeakMap = (value) => {
|
|
|
930
876
|
const isWeakSet = (value) => {
|
|
931
877
|
return isNotNil(value) && value instanceof WeakSet;
|
|
932
878
|
};
|
|
933
|
-
|
|
934
|
-
//#region src/guards/readonlyArrayIncludes.ts
|
|
879
|
+
// src/guards/readonlyArrayIncludes.ts
|
|
935
880
|
/**
|
|
936
881
|
* Checks if a readonly array includes the given element, with type narrowing.
|
|
937
882
|
*
|
|
@@ -947,8 +892,7 @@ const isWeakSet = (value) => {
|
|
|
947
892
|
* @category Arrays
|
|
948
893
|
*/
|
|
949
894
|
const readonlyArrayIncludes = (arr, elem) => arr.includes(elem);
|
|
950
|
-
|
|
951
|
-
//#region src/utilities/asyncNoOpFn.ts
|
|
895
|
+
// src/utilities/asyncNoOpFn.ts
|
|
952
896
|
/**
|
|
953
897
|
* An async function that does nothing. Useful as a default or placeholder
|
|
954
898
|
* callback where a promise is expected.
|
|
@@ -959,14 +903,12 @@ const readonlyArrayIncludes = (arr, elem) => arr.includes(elem);
|
|
|
959
903
|
* await asyncNoOpFn(); // undefined
|
|
960
904
|
*/
|
|
961
905
|
const asyncNoOpFn = async () => {};
|
|
962
|
-
|
|
963
|
-
//#region src/utilities/_constants.ts
|
|
906
|
+
// src/utilities/_constants.ts
|
|
964
907
|
const defaultLocales = ["en-US"];
|
|
965
908
|
const defaultTimeZone = /* @__PURE__ */ (() => Intl.DateTimeFormat().resolvedOptions().timeZone)();
|
|
966
909
|
const milisecondsInSecond = 1e3;
|
|
967
910
|
const millisecondsInDay = 86400 * milisecondsInSecond;
|
|
968
|
-
|
|
969
|
-
//#region src/utilities/buildTimeDuration.ts
|
|
911
|
+
// src/utilities/buildTimeDuration.ts
|
|
970
912
|
/**
|
|
971
913
|
* Returns an object representing a duration in seconds, minutes and hours.
|
|
972
914
|
*
|
|
@@ -986,8 +928,7 @@ const buildTimeDuration = (numberOfMilliseconds) => {
|
|
|
986
928
|
hours: numberOfHours
|
|
987
929
|
};
|
|
988
930
|
};
|
|
989
|
-
|
|
990
|
-
//#region src/utilities/coerceToBoolean.ts
|
|
931
|
+
// src/utilities/coerceToBoolean.ts
|
|
991
932
|
/**
|
|
992
933
|
* Converts the boolean string values 'true' and 'false' into the
|
|
993
934
|
* corresponding boolean. Any other value is coerced with `Boolean()`.
|
|
@@ -1004,8 +945,7 @@ const coerceToBoolean = (value) => {
|
|
|
1004
945
|
if (value === "true" || value === "false") return value === "true";
|
|
1005
946
|
return Boolean(value);
|
|
1006
947
|
};
|
|
1007
|
-
|
|
1008
|
-
//#region src/utilities/_isInvalidDate.ts
|
|
948
|
+
// src/utilities/_isInvalidDate.ts
|
|
1009
949
|
/**
|
|
1010
950
|
* Checks whether a value is not a usable Date. Note that the Unix epoch
|
|
1011
951
|
* (getTime() === 0) is treated as invalid.
|
|
@@ -1018,8 +958,7 @@ const isInvalidDate = (date) => {
|
|
|
1018
958
|
const time = date.getTime();
|
|
1019
959
|
return time === 0 || Number.isNaN(time);
|
|
1020
960
|
};
|
|
1021
|
-
|
|
1022
|
-
//#region src/utilities/dateOnlyISOString.ts
|
|
961
|
+
// src/utilities/dateOnlyISOString.ts
|
|
1023
962
|
/**
|
|
1024
963
|
* Converts a Date object into a date only string formatted to ISO 8601,
|
|
1025
964
|
* e.g. '2021-06-03'.
|
|
@@ -1050,8 +989,7 @@ const dateOnlyISOString = (date, { timeZone = defaultTimeZone } = {}) => {
|
|
|
1050
989
|
return "";
|
|
1051
990
|
}
|
|
1052
991
|
};
|
|
1053
|
-
|
|
1054
|
-
//#region src/utilities/dateOnlyString.ts
|
|
992
|
+
// src/utilities/dateOnlyString.ts
|
|
1055
993
|
/**
|
|
1056
994
|
* Converts a Date object into a date only string, e.g. 'Jun 3, 2021',
|
|
1057
995
|
* or 'Jun 3' if omitYear is true. Formats with the en-US locale.
|
|
@@ -1082,8 +1020,7 @@ const dateOnlyString = (date, { timeZone = defaultTimeZone, omitYear = false } =
|
|
|
1082
1020
|
return "";
|
|
1083
1021
|
}
|
|
1084
1022
|
};
|
|
1085
|
-
|
|
1086
|
-
//#region src/utilities/dateOnlyStringForSentence.ts
|
|
1023
|
+
// src/utilities/dateOnlyStringForSentence.ts
|
|
1087
1024
|
/**
|
|
1088
1025
|
* Converts a Date object into a date only string for use in a sentence,
|
|
1089
1026
|
* e.g. 'June 3, 2021'. Formats with the en-US locale.
|
|
@@ -1108,8 +1045,7 @@ const dateOnlyStringForSentence = (date, { timeZone = defaultTimeZone } = {}) =>
|
|
|
1108
1045
|
return "";
|
|
1109
1046
|
}
|
|
1110
1047
|
};
|
|
1111
|
-
|
|
1112
|
-
//#region src/utilities/dateOnlyStringNumeric.ts
|
|
1048
|
+
// src/utilities/dateOnlyStringNumeric.ts
|
|
1113
1049
|
/**
|
|
1114
1050
|
* Converts a Date object into a date only string formatted numerically,
|
|
1115
1051
|
* e.g. '06/03/2021'. Formats with the en-US locale.
|
|
@@ -1136,8 +1072,7 @@ const dateOnlyStringNumeric = (date, { timeZone = defaultTimeZone } = {}) => {
|
|
|
1136
1072
|
return "";
|
|
1137
1073
|
}
|
|
1138
1074
|
};
|
|
1139
|
-
|
|
1140
|
-
//#region src/utilities/dateTimeToDate.ts
|
|
1075
|
+
// src/utilities/dateTimeToDate.ts
|
|
1141
1076
|
/**
|
|
1142
1077
|
* Converts a plain object of date and time parts into a Date object.
|
|
1143
1078
|
*
|
|
@@ -1153,8 +1088,7 @@ const dateTimeToDate = (dateTime) => {
|
|
|
1153
1088
|
if (year !== void 0 && month !== void 0 && dayOfMonth !== void 0) return new Date(year, month, dayOfMonth, hours ?? 0, minutes ?? 0);
|
|
1154
1089
|
return null;
|
|
1155
1090
|
};
|
|
1156
|
-
|
|
1157
|
-
//#region src/utilities/dateTimeToISO.ts
|
|
1091
|
+
// src/utilities/dateTimeToISO.ts
|
|
1158
1092
|
/**
|
|
1159
1093
|
* Converts a plain object of date and time parts into an ISO-8601 string.
|
|
1160
1094
|
*
|
|
@@ -1166,8 +1100,7 @@ const dateTimeToDate = (dateTime) => {
|
|
|
1166
1100
|
* // '2015-11-07T04:15:00.000Z' (in UTC)
|
|
1167
1101
|
*/
|
|
1168
1102
|
const dateTimeToISO = (dateTime) => dateTimeToDate(dateTime)?.toISOString() ?? null;
|
|
1169
|
-
|
|
1170
|
-
//#region src/utilities/dateToDateTime.ts
|
|
1103
|
+
// src/utilities/dateToDateTime.ts
|
|
1171
1104
|
/**
|
|
1172
1105
|
* Converts a Date object into a plain object of its local date and time parts.
|
|
1173
1106
|
*
|
|
@@ -1188,8 +1121,7 @@ const dateToDateTime = (date) => {
|
|
|
1188
1121
|
minutes: date.getMinutes()
|
|
1189
1122
|
};
|
|
1190
1123
|
};
|
|
1191
|
-
|
|
1192
|
-
//#region src/utilities/dateTimeRounded.ts
|
|
1124
|
+
// src/utilities/dateTimeRounded.ts
|
|
1193
1125
|
/**
|
|
1194
1126
|
* Rounds a Date up to the next half hour boundary.
|
|
1195
1127
|
*
|
|
@@ -1213,8 +1145,7 @@ const dateTimeRounded = (dateTime, toISOString = true) => {
|
|
|
1213
1145
|
if (toISOString) return dateTimeToISO(dateWithTime);
|
|
1214
1146
|
return dateTimeToDate(dateWithTime);
|
|
1215
1147
|
};
|
|
1216
|
-
|
|
1217
|
-
//#region src/utilities/dateTimeString.ts
|
|
1148
|
+
// src/utilities/dateTimeString.ts
|
|
1218
1149
|
/**
|
|
1219
1150
|
* Converts a Date, timestamp, or date string into a date and time string,
|
|
1220
1151
|
* e.g. 'Jun 3, 2021, 11:52 AM'. Formats with the en-US locale.
|
|
@@ -1253,8 +1184,7 @@ const dateTimeString = (date, { timeZone = defaultTimeZone, omitYear = false } =
|
|
|
1253
1184
|
return "";
|
|
1254
1185
|
}
|
|
1255
1186
|
};
|
|
1256
|
-
|
|
1257
|
-
//#region src/utilities/dateTimeStringForSentence.ts
|
|
1187
|
+
// src/utilities/dateTimeStringForSentence.ts
|
|
1258
1188
|
/**
|
|
1259
1189
|
* Converts a Date object into a date and time string for use in a sentence,
|
|
1260
1190
|
* e.g. 'June 3, 2021, 11:52 AM'. Formats with the en-US locale.
|
|
@@ -1290,8 +1220,7 @@ const dateTimeStringForSentence = (date, { timeZone = defaultTimeZone } = {}) =>
|
|
|
1290
1220
|
return "";
|
|
1291
1221
|
}
|
|
1292
1222
|
};
|
|
1293
|
-
|
|
1294
|
-
//#region src/utilities/dateUTCOffset.ts
|
|
1223
|
+
// src/utilities/dateUTCOffset.ts
|
|
1295
1224
|
/**
|
|
1296
1225
|
* Given a date, shows the UTC offset of the current time zone, e.g. '+02:00'.
|
|
1297
1226
|
*
|
|
@@ -1307,8 +1236,7 @@ const dateUTCOffset = (date) => {
|
|
|
1307
1236
|
const minutes = (offsetInHours - hours) * 60;
|
|
1308
1237
|
return `${hours >= 0 ? "+" : ""}${`${hours}`.padStart(2, "0")}:${`${minutes}`.padStart(2, "0")}`;
|
|
1309
1238
|
};
|
|
1310
|
-
|
|
1311
|
-
//#region src/utilities/dayOfWeekString.ts
|
|
1239
|
+
// src/utilities/dayOfWeekString.ts
|
|
1312
1240
|
/**
|
|
1313
1241
|
* Converts a Date object into a day of the week string, e.g. 'Thursday'.
|
|
1314
1242
|
* Formats with the en-US locale.
|
|
@@ -1333,8 +1261,7 @@ const dayOfWeekString = (date, { timeZone = defaultTimeZone } = {}) => {
|
|
|
1333
1261
|
return "";
|
|
1334
1262
|
}
|
|
1335
1263
|
};
|
|
1336
|
-
|
|
1337
|
-
//#region src/utilities/deepMerge.ts
|
|
1264
|
+
// src/utilities/deepMerge.ts
|
|
1338
1265
|
const UNSAFE_KEYS = /* @__PURE__ */ new Set([
|
|
1339
1266
|
"__proto__",
|
|
1340
1267
|
"constructor",
|
|
@@ -1373,8 +1300,7 @@ const deepMerge = (...objects) => {
|
|
|
1373
1300
|
}
|
|
1374
1301
|
return result;
|
|
1375
1302
|
};
|
|
1376
|
-
|
|
1377
|
-
//#region src/utilities/getObjectEntries.ts
|
|
1303
|
+
// src/utilities/getObjectEntries.ts
|
|
1378
1304
|
/**
|
|
1379
1305
|
* Returns the entries of an object with strongly typed keys and values.
|
|
1380
1306
|
*
|
|
@@ -1385,8 +1311,7 @@ const deepMerge = (...objects) => {
|
|
|
1385
1311
|
* getObjectEntries({ a: 1, b: 2 }); // [['a', 1], ['b', 2]]
|
|
1386
1312
|
*/
|
|
1387
1313
|
const getObjectEntries = (obj) => Object.keys(obj).map((key) => [key, obj[key]]);
|
|
1388
|
-
|
|
1389
|
-
//#region src/utilities/getObjectKeys.ts
|
|
1314
|
+
// src/utilities/getObjectKeys.ts
|
|
1390
1315
|
/**
|
|
1391
1316
|
* Returns the keys of an object with strongly typed key type.
|
|
1392
1317
|
*
|
|
@@ -1397,8 +1322,7 @@ const getObjectEntries = (obj) => Object.keys(obj).map((key) => [key, obj[key]])
|
|
|
1397
1322
|
* getObjectKeys({ a: 1, b: 2 }); // ['a', 'b']
|
|
1398
1323
|
*/
|
|
1399
1324
|
const getObjectKeys = (obj) => Object.keys(obj);
|
|
1400
|
-
|
|
1401
|
-
//#region src/utilities/getObjectValues.ts
|
|
1325
|
+
// src/utilities/getObjectValues.ts
|
|
1402
1326
|
/**
|
|
1403
1327
|
* Returns the values of an object with strongly typed value type.
|
|
1404
1328
|
*
|
|
@@ -1409,8 +1333,43 @@ const getObjectKeys = (obj) => Object.keys(obj);
|
|
|
1409
1333
|
* getObjectValues({ a: 1, b: 2 }); // [1, 2]
|
|
1410
1334
|
*/
|
|
1411
1335
|
const getObjectValues = (obj) => Object.values(obj);
|
|
1412
|
-
|
|
1413
|
-
|
|
1336
|
+
// src/utilities/hashString.ts
|
|
1337
|
+
const MULTIPLIER = 31;
|
|
1338
|
+
/**
|
|
1339
|
+
* Turns text into a whole number that is always the same for the same text.
|
|
1340
|
+
*
|
|
1341
|
+
* @param text - The text to hash.
|
|
1342
|
+
* @returns A whole number from 0 to 2,147,483,648.
|
|
1343
|
+
*
|
|
1344
|
+
* @remarks
|
|
1345
|
+
* Use it to pick a stable item from a list, for example an avatar color for a
|
|
1346
|
+
* name. The result is a whole number from 0 to 2,147,483,648, so for a list
|
|
1347
|
+
* that is not empty, `hashString(text) % list.length` is always a valid index.
|
|
1348
|
+
* An empty string gives 0.
|
|
1349
|
+
*
|
|
1350
|
+
* The result is the absolute value of Java's `String.hashCode`, with one
|
|
1351
|
+
* difference: it reads the text by Unicode code point. So a character above
|
|
1352
|
+
* U+FFFF, such as `'😀'`, counts once as its full value, where Java counts its
|
|
1353
|
+
* two UTF-16 halves. An emoji made of several code points, such as `'👍🏽'` or a
|
|
1354
|
+
* flag, counts once for each code point. A lone surrogate counts as its own
|
|
1355
|
+
* value.
|
|
1356
|
+
*
|
|
1357
|
+
* Spaces count like any other character, so `'Ada'` and `' Ada'` give
|
|
1358
|
+
* different numbers. It does not normalize the text, so `'é'` and `'e'` plus a
|
|
1359
|
+
* combining accent give different numbers. Different text can give the same
|
|
1360
|
+
* number, for example `'Aa'` and `'BB'`. Do not use it for security. The type requires a string: `null` or `undefined` throws a
|
|
1361
|
+
* `TypeError`.
|
|
1362
|
+
*
|
|
1363
|
+
* @example
|
|
1364
|
+
* const colors = ['blue', 'green', 'pink'];
|
|
1365
|
+
* const color = colors[hashString('Ada Lovelace') % colors.length];
|
|
1366
|
+
*/
|
|
1367
|
+
const hashString = (text) => {
|
|
1368
|
+
let hash = 0;
|
|
1369
|
+
for (const character of text) hash = Math.imul(MULTIPLIER, hash) + Number(character.codePointAt(0));
|
|
1370
|
+
return Math.abs(Math.imul(hash, 1));
|
|
1371
|
+
};
|
|
1372
|
+
// src/utilities/isEmail.ts
|
|
1414
1373
|
/**
|
|
1415
1374
|
* Loosely validates an email address string.
|
|
1416
1375
|
*
|
|
@@ -1422,8 +1381,7 @@ const getObjectValues = (obj) => Object.values(obj);
|
|
|
1422
1381
|
* isEmail('user@example'); // false
|
|
1423
1382
|
*/
|
|
1424
1383
|
const isEmail = (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
1425
|
-
|
|
1426
|
-
//#region src/utilities/isUrl.ts
|
|
1384
|
+
// src/utilities/isUrl.ts
|
|
1427
1385
|
/**
|
|
1428
1386
|
* Loosely validates a URL string.
|
|
1429
1387
|
*
|
|
@@ -1443,8 +1401,7 @@ const isUrl = (value) => {
|
|
|
1443
1401
|
if (remaining === void 0) return false;
|
|
1444
1402
|
return localhostDomain.test(remaining) || nonLocalhostDomain.test(remaining);
|
|
1445
1403
|
};
|
|
1446
|
-
|
|
1447
|
-
//#region src/utilities/_padTimeInteger.ts
|
|
1404
|
+
// src/utilities/_padTimeInteger.ts
|
|
1448
1405
|
/**
|
|
1449
1406
|
* Pads an integer with a leading zero.
|
|
1450
1407
|
*
|
|
@@ -1452,8 +1409,7 @@ const isUrl = (value) => {
|
|
|
1452
1409
|
* @returns The integer as a string with padding.
|
|
1453
1410
|
*/
|
|
1454
1411
|
const padTimeInteger = (num) => num.toString().padStart(2, "0");
|
|
1455
|
-
|
|
1456
|
-
//#region src/utilities/mediaDurationString.ts
|
|
1412
|
+
// src/utilities/mediaDurationString.ts
|
|
1457
1413
|
/**
|
|
1458
1414
|
* A string representation of a duration for a media. Assumes most medias
|
|
1459
1415
|
* are under an hour so only shows hours if media is over an hour.
|
|
@@ -1470,8 +1426,7 @@ const mediaDurationString = (numberOfMilliseconds) => {
|
|
|
1470
1426
|
if (hours < 1) return `${minutes}:${padTimeInteger(seconds)}`;
|
|
1471
1427
|
return `${hours}:${padTimeInteger(minutes)}:${padTimeInteger(seconds)}`;
|
|
1472
1428
|
};
|
|
1473
|
-
|
|
1474
|
-
//#region src/utilities/millisecondsToDurationISOString.ts
|
|
1429
|
+
// src/utilities/millisecondsToDurationISOString.ts
|
|
1475
1430
|
/**
|
|
1476
1431
|
* Given a number of milliseconds, returns the ISO 8601 duration string
|
|
1477
1432
|
* rounded down from the number of seconds.
|
|
@@ -1492,8 +1447,7 @@ const millisecondsToDurationISOString = (numberOfMilliseconds) => {
|
|
|
1492
1447
|
if (!(seconds || minutes || hours)) string += "0S";
|
|
1493
1448
|
return string;
|
|
1494
1449
|
};
|
|
1495
|
-
|
|
1496
|
-
//#region src/utilities/monthDayStringNumeric.ts
|
|
1450
|
+
// src/utilities/monthDayStringNumeric.ts
|
|
1497
1451
|
/**
|
|
1498
1452
|
* Converts a Date object into a month and day string formatted numerically,
|
|
1499
1453
|
* e.g. '06/03'. Formats with the en-US locale.
|
|
@@ -1519,8 +1473,7 @@ const monthDayStringNumeric = (date, { timeZone = defaultTimeZone } = {}) => {
|
|
|
1519
1473
|
return "";
|
|
1520
1474
|
}
|
|
1521
1475
|
};
|
|
1522
|
-
|
|
1523
|
-
//#region src/utilities/noOpFn.ts
|
|
1476
|
+
// src/utilities/noOpFn.ts
|
|
1524
1477
|
/**
|
|
1525
1478
|
* A function that does nothing. Useful as a default or placeholder callback.
|
|
1526
1479
|
*
|
|
@@ -1530,8 +1483,7 @@ const monthDayStringNumeric = (date, { timeZone = defaultTimeZone } = {}) => {
|
|
|
1530
1483
|
* noOpFn(); // undefined
|
|
1531
1484
|
*/
|
|
1532
1485
|
const noOpFn = () => {};
|
|
1533
|
-
|
|
1534
|
-
//#region src/utilities/noOpFnReturningFalse.ts
|
|
1486
|
+
// src/utilities/noOpFnReturningFalse.ts
|
|
1535
1487
|
/**
|
|
1536
1488
|
* A function that does nothing and returns `false`. Useful as a default or
|
|
1537
1489
|
* placeholder callback where `false` is expected.
|
|
@@ -1542,8 +1494,7 @@ const noOpFn = () => {};
|
|
|
1542
1494
|
* noOpFnReturningFalse(); // false
|
|
1543
1495
|
*/
|
|
1544
1496
|
const noOpFnReturningFalse = () => false;
|
|
1545
|
-
|
|
1546
|
-
//#region src/utilities/noOpFnReturningNull.ts
|
|
1497
|
+
// src/utilities/noOpFnReturningNull.ts
|
|
1547
1498
|
/**
|
|
1548
1499
|
* A function that does nothing and returns `null`. Useful as a default or
|
|
1549
1500
|
* placeholder callback where `null` is expected.
|
|
@@ -1554,8 +1505,7 @@ const noOpFnReturningFalse = () => false;
|
|
|
1554
1505
|
* noOpFnReturningNull(); // null
|
|
1555
1506
|
*/
|
|
1556
1507
|
const noOpFnReturningNull = () => null;
|
|
1557
|
-
|
|
1558
|
-
//#region src/utilities/parseDateString.ts
|
|
1508
|
+
// src/utilities/parseDateString.ts
|
|
1559
1509
|
const MONTH_NAMES = [
|
|
1560
1510
|
"January",
|
|
1561
1511
|
"February",
|
|
@@ -1674,8 +1624,7 @@ const parseDateString = (str) => {
|
|
|
1674
1624
|
if (!Number.isNaN(native.getTime())) return startOfDay(native);
|
|
1675
1625
|
return null;
|
|
1676
1626
|
};
|
|
1677
|
-
|
|
1678
|
-
//#region src/utilities/sessionDurationString.ts
|
|
1627
|
+
// src/utilities/sessionDurationString.ts
|
|
1679
1628
|
/**
|
|
1680
1629
|
* A string representation of a duration for a user session. Assumes that
|
|
1681
1630
|
* sessions may or may not be more than an hour. To prevent confusion all
|
|
@@ -1691,8 +1640,7 @@ const sessionDurationString = (numberOfMilliseconds) => {
|
|
|
1691
1640
|
const { hours, minutes, seconds } = buildTimeDuration(numberOfMilliseconds);
|
|
1692
1641
|
return `${hours}:${padTimeInteger(minutes)}:${padTimeInteger(seconds)}`;
|
|
1693
1642
|
};
|
|
1694
|
-
|
|
1695
|
-
//#region src/utilities/stripExtension.ts
|
|
1643
|
+
// src/utilities/stripExtension.ts
|
|
1696
1644
|
/**
|
|
1697
1645
|
* Removes the file extension from a string.
|
|
1698
1646
|
*
|
|
@@ -1704,8 +1652,7 @@ const sessionDurationString = (numberOfMilliseconds) => {
|
|
|
1704
1652
|
* stripExtension('example.test.ts'); // 'example.test'
|
|
1705
1653
|
*/
|
|
1706
1654
|
const stripExtension = (str) => (str || "").replace(/\.[^/.]{1,4}$/, "");
|
|
1707
|
-
|
|
1708
|
-
//#region src/utilities/_getLocalDateParts.ts
|
|
1655
|
+
// src/utilities/_getLocalDateParts.ts
|
|
1709
1656
|
/**
|
|
1710
1657
|
* Get local year, month, day parts from a Date using Intl.DateTimeFormat.
|
|
1711
1658
|
* This ignores the time of day (hours, minutes, etc.).
|
|
@@ -1729,8 +1676,7 @@ const getLocalDateParts = (date) => {
|
|
|
1729
1676
|
day: Math.trunc(Number(partsAsObject.day))
|
|
1730
1677
|
};
|
|
1731
1678
|
};
|
|
1732
|
-
|
|
1733
|
-
//#region src/utilities/_differenceInCalendarDays.ts
|
|
1679
|
+
// src/utilities/_differenceInCalendarDays.ts
|
|
1734
1680
|
/**
|
|
1735
1681
|
* Returns the difference in calendar days between two dates in local time,
|
|
1736
1682
|
* ignoring the time of day.
|
|
@@ -1748,8 +1694,7 @@ const differenceInCalendarDays = (dateLeft, dateRight) => {
|
|
|
1748
1694
|
const msDiff = new Date(y1, m1 - 1, d1).getTime() - new Date(y2, m2 - 1, d2).getTime();
|
|
1749
1695
|
return Math.round(msDiff / millisecondsInDay);
|
|
1750
1696
|
};
|
|
1751
|
-
|
|
1752
|
-
//#region src/utilities/timeAgoString.ts
|
|
1697
|
+
// src/utilities/timeAgoString.ts
|
|
1753
1698
|
/**
|
|
1754
1699
|
* Shows time ago relative to current time, e.g. '< 1 minute ago',
|
|
1755
1700
|
* '33 minutes ago', 'Today, 3:30 PM', 'Yesterday, 6:22 AM',
|
|
@@ -1789,8 +1734,7 @@ const timeAgoString = (date, { nowAnchor = /* @__PURE__ */ new Date(), includeTi
|
|
|
1789
1734
|
if (differenceInDays < 7 && !includeTime) return `on ${dayOfWeekString(date)}`;
|
|
1790
1735
|
return includeTime ? dateTimeString(date, { omitYear: isSameYear }) : dateOnlyString(date, { omitYear: false });
|
|
1791
1736
|
};
|
|
1792
|
-
|
|
1793
|
-
//#region src/utilities/timeOnlyString.ts
|
|
1737
|
+
// src/utilities/timeOnlyString.ts
|
|
1794
1738
|
/**
|
|
1795
1739
|
* Converts a Date object into a time only string, e.g. '7:30 AM'.
|
|
1796
1740
|
* Formats with the en-US locale.
|
|
@@ -1815,8 +1759,7 @@ const timeOnlyString = (date, { timeZone = defaultTimeZone } = {}) => {
|
|
|
1815
1759
|
return "";
|
|
1816
1760
|
}
|
|
1817
1761
|
};
|
|
1818
|
-
|
|
1819
|
-
//#region src/utilities/truncateString.ts
|
|
1762
|
+
// src/utilities/truncateString.ts
|
|
1820
1763
|
let graphemeSegmenter;
|
|
1821
1764
|
const takeGraphemes = (value, count) => {
|
|
1822
1765
|
graphemeSegmenter ??= new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
@@ -1855,8 +1798,7 @@ const truncateString = (text, maxLength, { ellipsis = "…" } = {}) => {
|
|
|
1855
1798
|
if (limit <= ellipsisLength) return graphemes.slice(0, limit).join("");
|
|
1856
1799
|
return `${graphemes.slice(0, limit - ellipsisLength).join("")}${ellipsis}`;
|
|
1857
1800
|
};
|
|
1858
|
-
|
|
1859
|
-
//#region src/utilities/tupleIncludes.ts
|
|
1801
|
+
// src/utilities/tupleIncludes.ts
|
|
1860
1802
|
/**
|
|
1861
1803
|
* Checks if a tuple includes the given item, with type narrowing.
|
|
1862
1804
|
*
|
|
@@ -1870,8 +1812,7 @@ const truncateString = (text, maxLength, { ellipsis = "…" } = {}) => {
|
|
|
1870
1812
|
* tupleIncludes(tuple, 'z'); // false
|
|
1871
1813
|
*/
|
|
1872
1814
|
const tupleIncludes = (tuple, item) => tuple.includes(item);
|
|
1873
|
-
|
|
1874
|
-
//#region src/utilities/wait.ts
|
|
1815
|
+
// src/utilities/wait.ts
|
|
1875
1816
|
const MAX_DELAY_MS = 2147483647;
|
|
1876
1817
|
/**
|
|
1877
1818
|
* Waits for about the given number of milliseconds.
|
|
@@ -1894,7 +1835,6 @@ const wait = async (milliseconds) => {
|
|
|
1894
1835
|
setTimeout(resolve, delay);
|
|
1895
1836
|
});
|
|
1896
1837
|
};
|
|
1897
|
-
|
|
1898
|
-
export { asyncNoOpFn, buildTimeDuration, coerceToBoolean, dateOnlyISOString, dateOnlyString, dateOnlyStringForSentence, dateOnlyStringNumeric, dateTimeRounded, dateTimeString, dateTimeStringForSentence, dateTimeToDate, dateTimeToISO, dateToDateTime, dateUTCOffset, dayOfWeekString, deepMerge, getObjectEntries, getObjectKeys, getObjectValues, hasKey, isArray, isAsyncFunction, isBigInt, isBoolean, isDate, isEmail, isEmptyArray, isEmptyRecord, isEmptyString, isError, isFalsy, isFiniteNumber, isFunction, isHtmlButtonElement, isHtmlElement, isHtmlInputElement, isHtmlVideoElement, isInteger, isIterable, isMap, isMouseEvent, isNaN, isNil, isNonBlankString, isNonEmptyArray, isNonEmptyRecord, isNonEmptyString, isNonNaNNumber, isNotArray, isNotBoolean, isNotFunction, isNotNil, isNotNull, isNotNumber, isNotRecord, isNotString, isNotUndefined, isNotVoid, isNull, isNumber, isPlainObject, isPromise, isRecord, isRegExp, isSet, isString, isSvgElement, isSymbol, isTextNode, isTruthy, isUndefined, isUrl, isVoid, isWeakMap, isWeakSet, mediaDurationString, millisecondsToDurationISOString, monthDayStringNumeric, noOpFn, noOpFnReturningFalse, noOpFnReturningNull, parseDateString, readonlyArrayIncludes, sessionDurationString, stripExtension, timeAgoString, timeOnlyString, truncateString, tupleIncludes, wait };
|
|
1838
|
+
export { asyncNoOpFn, buildTimeDuration, coerceToBoolean, dateOnlyISOString, dateOnlyString, dateOnlyStringForSentence, dateOnlyStringNumeric, dateTimeRounded, dateTimeString, dateTimeStringForSentence, dateTimeToDate, dateTimeToISO, dateToDateTime, dateUTCOffset, dayOfWeekString, deepMerge, getObjectEntries, getObjectKeys, getObjectValues, hasKey, hashString, isArray, isAsyncFunction, isBigInt, isBoolean, isDate, isEmail, isEmptyArray, isEmptyRecord, isEmptyString, isError, isFalsy, isFiniteNumber, isFunction, isHtmlButtonElement, isHtmlElement, isHtmlInputElement, isHtmlVideoElement, isInteger, isIterable, isMap, isMouseEvent, isNaN, isNil, isNonBlankString, isNonEmptyArray, isNonEmptyRecord, isNonEmptyString, isNonNaNNumber, isNotArray, isNotBoolean, isNotFunction, isNotNil, isNotNull, isNotNumber, isNotRecord, isNotString, isNotUndefined, isNotVoid, isNull, isNumber, isPlainObject, isPromise, isRecord, isRegExp, isSet, isString, isSvgElement, isSymbol, isTextNode, isTruthy, isUndefined, isUrl, isVoid, isWeakMap, isWeakSet, mediaDurationString, millisecondsToDurationISOString, monthDayStringNumeric, noOpFn, noOpFnReturningFalse, noOpFnReturningNull, parseDateString, readonlyArrayIncludes, sessionDurationString, stripExtension, timeAgoString, timeOnlyString, truncateString, tupleIncludes, wait };
|
|
1899
1839
|
|
|
1900
1840
|
//# sourceMappingURL=index.mjs.map
|