@bytebury/toolkit 1.6.0 → 1.8.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/esm/src/core.d.ts +21 -12
- package/esm/src/core.d.ts.map +1 -1
- package/esm/src/core.js +49 -0
- package/package.json +1 -1
- package/script/src/core.d.ts +21 -12
- package/script/src/core.d.ts.map +1 -1
- package/script/src/core.js +49 -0
package/esm/src/core.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { NonEmptyList } from "./utility_types.js";
|
|
2
1
|
/**
|
|
3
2
|
* Clone an object using structuredClone.
|
|
4
3
|
*/
|
|
@@ -23,31 +22,33 @@ export declare function isEqual(thing1: unknown, thing2: unknown): boolean;
|
|
|
23
22
|
* is a string, then it will return the first character.
|
|
24
23
|
*
|
|
25
24
|
* @remarks
|
|
26
|
-
* If an empty list is passed then this will return undefined.
|
|
25
|
+
* If an empty list or string is passed then this will return undefined.
|
|
27
26
|
*
|
|
28
27
|
* @example
|
|
29
28
|
* ```ts
|
|
30
29
|
* first("hello"); // "h"
|
|
31
30
|
* first([1, 2, 3]); // 1
|
|
31
|
+
* first([]); // undefined
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export declare function first
|
|
35
|
-
export declare function first(
|
|
34
|
+
export declare function first(value: string): string | undefined;
|
|
35
|
+
export declare function first<T>(list: T[]): T | undefined;
|
|
36
36
|
/**
|
|
37
37
|
* Returns the last thing in a list. If the value
|
|
38
38
|
* is a string, then it will return the last character.
|
|
39
39
|
*
|
|
40
40
|
* @remarks
|
|
41
|
-
* If an empty list is passed then this will return undefined.
|
|
41
|
+
* If an empty list or string is passed then this will return undefined.
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
45
45
|
* last("hello"); // "o"
|
|
46
46
|
* last([1, 2, 3]); // 3
|
|
47
|
+
* last([]); // undefined
|
|
47
48
|
* ```
|
|
48
49
|
*/
|
|
49
|
-
export declare function last
|
|
50
|
-
export declare function last(
|
|
50
|
+
export declare function last(value: string): string | undefined;
|
|
51
|
+
export declare function last<T>(list: T[]): T | undefined;
|
|
51
52
|
/**
|
|
52
53
|
* Compares two things by turning them into strings,
|
|
53
54
|
* and comparing them by their string value.
|
|
@@ -161,7 +162,6 @@ export declare function reverse<T>(thing: Set<T>): Set<T>;
|
|
|
161
162
|
* isEmpty(new Map()); // true
|
|
162
163
|
* ```
|
|
163
164
|
*/
|
|
164
|
-
export declare function isEmpty(thing: unknown[]): boolean;
|
|
165
165
|
export declare function isEmpty(thing: unknown): boolean;
|
|
166
166
|
/**
|
|
167
167
|
* Determines if the given thing is not empty.
|
|
@@ -179,7 +179,6 @@ export declare function isEmpty(thing: unknown): boolean;
|
|
|
179
179
|
* isNotEmpty(new Map()); // false
|
|
180
180
|
* ```
|
|
181
181
|
*/
|
|
182
|
-
export declare function isNotEmpty(thing: unknown[]): boolean;
|
|
183
182
|
export declare function isNotEmpty(thing: unknown): boolean;
|
|
184
183
|
/**
|
|
185
184
|
* Returns the distinct values from a list.
|
|
@@ -220,7 +219,7 @@ export declare function distinct<T>(list: T[]): T[];
|
|
|
220
219
|
* console.log(sample([])); // undefined
|
|
221
220
|
* ```
|
|
222
221
|
*/
|
|
223
|
-
export declare function sample<T>(list:
|
|
222
|
+
export declare function sample<T>(list: T[]): T | undefined;
|
|
224
223
|
/**
|
|
225
224
|
* Gives a random number in the given range. The first parameter is inclusive
|
|
226
225
|
* and the second one is exclusive. Therefore, it will work with lists out of
|
|
@@ -365,6 +364,9 @@ export declare function intersection<T>(...lists: T[][]): T[];
|
|
|
365
364
|
* If `searchFor` is an empty list, this returns `true` (vacuously, since
|
|
366
365
|
* every item in an empty list is found).
|
|
367
366
|
*
|
|
367
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
368
|
+
* returns `false`.
|
|
369
|
+
*
|
|
368
370
|
* @example
|
|
369
371
|
* ```ts
|
|
370
372
|
* includes("hello world", "hello"); // true
|
|
@@ -374,9 +376,11 @@ export declare function intersection<T>(...lists: T[][]): T[];
|
|
|
374
376
|
* includes(["a", "b", "c"], ["a", "b"]); // true
|
|
375
377
|
* includes(["a", "b", "c"], ["a", "d"]); // false
|
|
376
378
|
* includes("hello world", []); // true
|
|
379
|
+
* includes(null, "hello"); // false
|
|
380
|
+
* includes("hello world", undefined); // false
|
|
377
381
|
* ```
|
|
378
382
|
*/
|
|
379
|
-
export declare function includes(searchIn: string | string[], searchFor: string | string[]): boolean;
|
|
383
|
+
export declare function includes(searchIn: string | string[] | null | undefined, searchFor: string | string[] | null | undefined): boolean;
|
|
380
384
|
/**
|
|
381
385
|
* Determines if `searchIn` contains any of the given `searchFor` term(s).
|
|
382
386
|
*
|
|
@@ -388,6 +392,9 @@ export declare function includes(searchIn: string | string[], searchFor: string
|
|
|
388
392
|
* If `searchFor` is an empty list, this returns `false` (there is no term
|
|
389
393
|
* to match).
|
|
390
394
|
*
|
|
395
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
396
|
+
* returns `false`.
|
|
397
|
+
*
|
|
391
398
|
* @example
|
|
392
399
|
* ```ts
|
|
393
400
|
* includesAny("hello world", "hello"); // true
|
|
@@ -397,7 +404,9 @@ export declare function includes(searchIn: string | string[], searchFor: string
|
|
|
397
404
|
* includesAny(["a", "b", "c"], ["a", "d"]); // true
|
|
398
405
|
* includesAny(["a", "b", "c"], ["d", "e"]); // false
|
|
399
406
|
* includesAny("hello world", []); // false
|
|
407
|
+
* includesAny(null, "hello"); // false
|
|
408
|
+
* includesAny("hello world", undefined); // false
|
|
400
409
|
* ```
|
|
401
410
|
*/
|
|
402
|
-
export declare function includesAny(searchIn: string | string[], searchFor: string | string[]): boolean;
|
|
411
|
+
export declare function includesAny(searchIn: string | string[] | null | undefined, searchFor: string | string[] | null | undefined): boolean;
|
|
403
412
|
//# sourceMappingURL=core.d.ts.map
|
package/esm/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAElC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACzD,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAKnD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACxD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAKlD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAK3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,OAAO,GACd,OAAO,CAET;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,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AAG,SAAS,GAC9C,OAAO,CAIT"}
|
package/esm/src/core.js
CHANGED
|
@@ -128,6 +128,25 @@ export function reverse(thing) {
|
|
|
128
128
|
return new Set([...thing].reverse());
|
|
129
129
|
return thing.reverse();
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Determines if the given thing is empty.
|
|
133
|
+
*
|
|
134
|
+
* Things are empty when:
|
|
135
|
+
* * They are `None`
|
|
136
|
+
* * They are empty strings
|
|
137
|
+
* * They have no length or size
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* isEmpty([]); // true
|
|
142
|
+
* isEmpty([0]); // false
|
|
143
|
+
* isEmpty(""); // true
|
|
144
|
+
* isEmpty(" "); // false
|
|
145
|
+
* isEmpty(new Set()); // true
|
|
146
|
+
* isEmpty({}); // true
|
|
147
|
+
* isEmpty(new Map()); // true
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
131
150
|
export function isEmpty(thing) {
|
|
132
151
|
if (isNone(thing))
|
|
133
152
|
return true;
|
|
@@ -141,6 +160,22 @@ export function isEmpty(thing) {
|
|
|
141
160
|
return Object.keys(thing).length === 0;
|
|
142
161
|
return false;
|
|
143
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Determines if the given thing is not empty.
|
|
165
|
+
*
|
|
166
|
+
* @remarks this is the inverse of `isEmpty`.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* isNotEmpty([]); // false
|
|
171
|
+
* isNotEmpty([0]); // true
|
|
172
|
+
* isNotEmpty(""); // false
|
|
173
|
+
* isNotEmpty(" "); // true
|
|
174
|
+
* isNotEmpty(new Set()); // false
|
|
175
|
+
* isNotEmpty({}); // false
|
|
176
|
+
* isNotEmpty(new Map()); // false
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
144
179
|
export function isNotEmpty(thing) {
|
|
145
180
|
return !isEmpty(thing);
|
|
146
181
|
}
|
|
@@ -376,6 +411,9 @@ export function intersection(...lists) {
|
|
|
376
411
|
* If `searchFor` is an empty list, this returns `true` (vacuously, since
|
|
377
412
|
* every item in an empty list is found).
|
|
378
413
|
*
|
|
414
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
415
|
+
* returns `false`.
|
|
416
|
+
*
|
|
379
417
|
* @example
|
|
380
418
|
* ```ts
|
|
381
419
|
* includes("hello world", "hello"); // true
|
|
@@ -385,9 +423,13 @@ export function intersection(...lists) {
|
|
|
385
423
|
* includes(["a", "b", "c"], ["a", "b"]); // true
|
|
386
424
|
* includes(["a", "b", "c"], ["a", "d"]); // false
|
|
387
425
|
* includes("hello world", []); // true
|
|
426
|
+
* includes(null, "hello"); // false
|
|
427
|
+
* includes("hello world", undefined); // false
|
|
388
428
|
* ```
|
|
389
429
|
*/
|
|
390
430
|
export function includes(searchIn, searchFor) {
|
|
431
|
+
if (searchIn == null || searchFor == null)
|
|
432
|
+
return false;
|
|
391
433
|
const terms = Array.isArray(searchFor) ? searchFor : [searchFor];
|
|
392
434
|
return terms.every((term) => searchIn.includes(term));
|
|
393
435
|
}
|
|
@@ -402,6 +444,9 @@ export function includes(searchIn, searchFor) {
|
|
|
402
444
|
* If `searchFor` is an empty list, this returns `false` (there is no term
|
|
403
445
|
* to match).
|
|
404
446
|
*
|
|
447
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
448
|
+
* returns `false`.
|
|
449
|
+
*
|
|
405
450
|
* @example
|
|
406
451
|
* ```ts
|
|
407
452
|
* includesAny("hello world", "hello"); // true
|
|
@@ -411,9 +456,13 @@ export function includes(searchIn, searchFor) {
|
|
|
411
456
|
* includesAny(["a", "b", "c"], ["a", "d"]); // true
|
|
412
457
|
* includesAny(["a", "b", "c"], ["d", "e"]); // false
|
|
413
458
|
* includesAny("hello world", []); // false
|
|
459
|
+
* includesAny(null, "hello"); // false
|
|
460
|
+
* includesAny("hello world", undefined); // false
|
|
414
461
|
* ```
|
|
415
462
|
*/
|
|
416
463
|
export function includesAny(searchIn, searchFor) {
|
|
464
|
+
if (searchIn == null || searchFor == null)
|
|
465
|
+
return false;
|
|
417
466
|
const terms = Array.isArray(searchFor) ? searchFor : [searchFor];
|
|
418
467
|
return terms.some((term) => searchIn.includes(term));
|
|
419
468
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytebury/toolkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "TypeScript utility library to help energize your projects with useful functions for any size project. Save yourself some time and focus on shipping features.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
package/script/src/core.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { NonEmptyList } from "./utility_types.js";
|
|
2
1
|
/**
|
|
3
2
|
* Clone an object using structuredClone.
|
|
4
3
|
*/
|
|
@@ -23,31 +22,33 @@ export declare function isEqual(thing1: unknown, thing2: unknown): boolean;
|
|
|
23
22
|
* is a string, then it will return the first character.
|
|
24
23
|
*
|
|
25
24
|
* @remarks
|
|
26
|
-
* If an empty list is passed then this will return undefined.
|
|
25
|
+
* If an empty list or string is passed then this will return undefined.
|
|
27
26
|
*
|
|
28
27
|
* @example
|
|
29
28
|
* ```ts
|
|
30
29
|
* first("hello"); // "h"
|
|
31
30
|
* first([1, 2, 3]); // 1
|
|
31
|
+
* first([]); // undefined
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export declare function first
|
|
35
|
-
export declare function first(
|
|
34
|
+
export declare function first(value: string): string | undefined;
|
|
35
|
+
export declare function first<T>(list: T[]): T | undefined;
|
|
36
36
|
/**
|
|
37
37
|
* Returns the last thing in a list. If the value
|
|
38
38
|
* is a string, then it will return the last character.
|
|
39
39
|
*
|
|
40
40
|
* @remarks
|
|
41
|
-
* If an empty list is passed then this will return undefined.
|
|
41
|
+
* If an empty list or string is passed then this will return undefined.
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
45
45
|
* last("hello"); // "o"
|
|
46
46
|
* last([1, 2, 3]); // 3
|
|
47
|
+
* last([]); // undefined
|
|
47
48
|
* ```
|
|
48
49
|
*/
|
|
49
|
-
export declare function last
|
|
50
|
-
export declare function last(
|
|
50
|
+
export declare function last(value: string): string | undefined;
|
|
51
|
+
export declare function last<T>(list: T[]): T | undefined;
|
|
51
52
|
/**
|
|
52
53
|
* Compares two things by turning them into strings,
|
|
53
54
|
* and comparing them by their string value.
|
|
@@ -161,7 +162,6 @@ export declare function reverse<T>(thing: Set<T>): Set<T>;
|
|
|
161
162
|
* isEmpty(new Map()); // true
|
|
162
163
|
* ```
|
|
163
164
|
*/
|
|
164
|
-
export declare function isEmpty(thing: unknown[]): boolean;
|
|
165
165
|
export declare function isEmpty(thing: unknown): boolean;
|
|
166
166
|
/**
|
|
167
167
|
* Determines if the given thing is not empty.
|
|
@@ -179,7 +179,6 @@ export declare function isEmpty(thing: unknown): boolean;
|
|
|
179
179
|
* isNotEmpty(new Map()); // false
|
|
180
180
|
* ```
|
|
181
181
|
*/
|
|
182
|
-
export declare function isNotEmpty(thing: unknown[]): boolean;
|
|
183
182
|
export declare function isNotEmpty(thing: unknown): boolean;
|
|
184
183
|
/**
|
|
185
184
|
* Returns the distinct values from a list.
|
|
@@ -220,7 +219,7 @@ export declare function distinct<T>(list: T[]): T[];
|
|
|
220
219
|
* console.log(sample([])); // undefined
|
|
221
220
|
* ```
|
|
222
221
|
*/
|
|
223
|
-
export declare function sample<T>(list:
|
|
222
|
+
export declare function sample<T>(list: T[]): T | undefined;
|
|
224
223
|
/**
|
|
225
224
|
* Gives a random number in the given range. The first parameter is inclusive
|
|
226
225
|
* and the second one is exclusive. Therefore, it will work with lists out of
|
|
@@ -365,6 +364,9 @@ export declare function intersection<T>(...lists: T[][]): T[];
|
|
|
365
364
|
* If `searchFor` is an empty list, this returns `true` (vacuously, since
|
|
366
365
|
* every item in an empty list is found).
|
|
367
366
|
*
|
|
367
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
368
|
+
* returns `false`.
|
|
369
|
+
*
|
|
368
370
|
* @example
|
|
369
371
|
* ```ts
|
|
370
372
|
* includes("hello world", "hello"); // true
|
|
@@ -374,9 +376,11 @@ export declare function intersection<T>(...lists: T[][]): T[];
|
|
|
374
376
|
* includes(["a", "b", "c"], ["a", "b"]); // true
|
|
375
377
|
* includes(["a", "b", "c"], ["a", "d"]); // false
|
|
376
378
|
* includes("hello world", []); // true
|
|
379
|
+
* includes(null, "hello"); // false
|
|
380
|
+
* includes("hello world", undefined); // false
|
|
377
381
|
* ```
|
|
378
382
|
*/
|
|
379
|
-
export declare function includes(searchIn: string | string[], searchFor: string | string[]): boolean;
|
|
383
|
+
export declare function includes(searchIn: string | string[] | null | undefined, searchFor: string | string[] | null | undefined): boolean;
|
|
380
384
|
/**
|
|
381
385
|
* Determines if `searchIn` contains any of the given `searchFor` term(s).
|
|
382
386
|
*
|
|
@@ -388,6 +392,9 @@ export declare function includes(searchIn: string | string[], searchFor: string
|
|
|
388
392
|
* If `searchFor` is an empty list, this returns `false` (there is no term
|
|
389
393
|
* to match).
|
|
390
394
|
*
|
|
395
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
396
|
+
* returns `false`.
|
|
397
|
+
*
|
|
391
398
|
* @example
|
|
392
399
|
* ```ts
|
|
393
400
|
* includesAny("hello world", "hello"); // true
|
|
@@ -397,7 +404,9 @@ export declare function includes(searchIn: string | string[], searchFor: string
|
|
|
397
404
|
* includesAny(["a", "b", "c"], ["a", "d"]); // true
|
|
398
405
|
* includesAny(["a", "b", "c"], ["d", "e"]); // false
|
|
399
406
|
* includesAny("hello world", []); // false
|
|
407
|
+
* includesAny(null, "hello"); // false
|
|
408
|
+
* includesAny("hello world", undefined); // false
|
|
400
409
|
* ```
|
|
401
410
|
*/
|
|
402
|
-
export declare function includesAny(searchIn: string | string[], searchFor: string | string[]): boolean;
|
|
411
|
+
export declare function includesAny(searchIn: string | string[] | null | undefined, searchFor: string | string[] | null | undefined): boolean;
|
|
403
412
|
//# sourceMappingURL=core.d.ts.map
|
package/script/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAElC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACzD,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAKnD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACxD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAKlD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAK3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,OAAO,GACd,OA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;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,EAC9C,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,GAC9C,OAAO,CAIT"}
|
package/script/src/core.js
CHANGED
|
@@ -159,6 +159,25 @@ function reverse(thing) {
|
|
|
159
159
|
return new Set([...thing].reverse());
|
|
160
160
|
return thing.reverse();
|
|
161
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Determines if the given thing is empty.
|
|
164
|
+
*
|
|
165
|
+
* Things are empty when:
|
|
166
|
+
* * They are `None`
|
|
167
|
+
* * They are empty strings
|
|
168
|
+
* * They have no length or size
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* isEmpty([]); // true
|
|
173
|
+
* isEmpty([0]); // false
|
|
174
|
+
* isEmpty(""); // true
|
|
175
|
+
* isEmpty(" "); // false
|
|
176
|
+
* isEmpty(new Set()); // true
|
|
177
|
+
* isEmpty({}); // true
|
|
178
|
+
* isEmpty(new Map()); // true
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
162
181
|
function isEmpty(thing) {
|
|
163
182
|
if (isNone(thing))
|
|
164
183
|
return true;
|
|
@@ -172,6 +191,22 @@ function isEmpty(thing) {
|
|
|
172
191
|
return Object.keys(thing).length === 0;
|
|
173
192
|
return false;
|
|
174
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Determines if the given thing is not empty.
|
|
196
|
+
*
|
|
197
|
+
* @remarks this is the inverse of `isEmpty`.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* isNotEmpty([]); // false
|
|
202
|
+
* isNotEmpty([0]); // true
|
|
203
|
+
* isNotEmpty(""); // false
|
|
204
|
+
* isNotEmpty(" "); // true
|
|
205
|
+
* isNotEmpty(new Set()); // false
|
|
206
|
+
* isNotEmpty({}); // false
|
|
207
|
+
* isNotEmpty(new Map()); // false
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
175
210
|
function isNotEmpty(thing) {
|
|
176
211
|
return !isEmpty(thing);
|
|
177
212
|
}
|
|
@@ -407,6 +442,9 @@ function intersection(...lists) {
|
|
|
407
442
|
* If `searchFor` is an empty list, this returns `true` (vacuously, since
|
|
408
443
|
* every item in an empty list is found).
|
|
409
444
|
*
|
|
445
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
446
|
+
* returns `false`.
|
|
447
|
+
*
|
|
410
448
|
* @example
|
|
411
449
|
* ```ts
|
|
412
450
|
* includes("hello world", "hello"); // true
|
|
@@ -416,9 +454,13 @@ function intersection(...lists) {
|
|
|
416
454
|
* includes(["a", "b", "c"], ["a", "b"]); // true
|
|
417
455
|
* includes(["a", "b", "c"], ["a", "d"]); // false
|
|
418
456
|
* includes("hello world", []); // true
|
|
457
|
+
* includes(null, "hello"); // false
|
|
458
|
+
* includes("hello world", undefined); // false
|
|
419
459
|
* ```
|
|
420
460
|
*/
|
|
421
461
|
function includes(searchIn, searchFor) {
|
|
462
|
+
if (searchIn == null || searchFor == null)
|
|
463
|
+
return false;
|
|
422
464
|
const terms = Array.isArray(searchFor) ? searchFor : [searchFor];
|
|
423
465
|
return terms.every((term) => searchIn.includes(term));
|
|
424
466
|
}
|
|
@@ -433,6 +475,9 @@ function includes(searchIn, searchFor) {
|
|
|
433
475
|
* If `searchFor` is an empty list, this returns `false` (there is no term
|
|
434
476
|
* to match).
|
|
435
477
|
*
|
|
478
|
+
* If either `searchIn` or `searchFor` is `null` or `undefined`, this
|
|
479
|
+
* returns `false`.
|
|
480
|
+
*
|
|
436
481
|
* @example
|
|
437
482
|
* ```ts
|
|
438
483
|
* includesAny("hello world", "hello"); // true
|
|
@@ -442,9 +487,13 @@ function includes(searchIn, searchFor) {
|
|
|
442
487
|
* includesAny(["a", "b", "c"], ["a", "d"]); // true
|
|
443
488
|
* includesAny(["a", "b", "c"], ["d", "e"]); // false
|
|
444
489
|
* includesAny("hello world", []); // false
|
|
490
|
+
* includesAny(null, "hello"); // false
|
|
491
|
+
* includesAny("hello world", undefined); // false
|
|
445
492
|
* ```
|
|
446
493
|
*/
|
|
447
494
|
function includesAny(searchIn, searchFor) {
|
|
495
|
+
if (searchIn == null || searchFor == null)
|
|
496
|
+
return false;
|
|
448
497
|
const terms = Array.isArray(searchFor) ? searchFor : [searchFor];
|
|
449
498
|
return terms.some((term) => searchIn.includes(term));
|
|
450
499
|
}
|