complete-common 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +3 -3
- package/dist/constants.d.cts +7 -0
- package/dist/constants.d.mts +7 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/functions/array.d.cts +83 -0
- package/dist/functions/array.d.mts +83 -0
- package/dist/functions/array.d.ts +83 -0
- package/dist/functions/array.d.ts.map +1 -0
- package/dist/functions/assert.d.cts +22 -0
- package/dist/functions/assert.d.mts +22 -0
- package/dist/functions/assert.d.ts +22 -0
- package/dist/functions/assert.d.ts.map +1 -0
- package/dist/functions/enums.d.cts +73 -0
- package/dist/functions/enums.d.mts +73 -0
- package/dist/functions/enums.d.ts +73 -0
- package/dist/functions/enums.d.ts.map +1 -0
- package/dist/functions/map.d.cts +52 -0
- package/dist/functions/map.d.mts +52 -0
- package/dist/functions/map.d.ts +52 -0
- package/dist/functions/map.d.ts.map +1 -0
- package/dist/functions/math.d.cts +13 -0
- package/dist/functions/math.d.mts +13 -0
- package/dist/functions/math.d.ts +13 -0
- package/dist/functions/math.d.ts.map +1 -0
- package/dist/functions/object.d.cts +14 -0
- package/dist/functions/object.d.mts +14 -0
- package/dist/functions/object.d.ts +14 -0
- package/dist/functions/object.d.ts.map +1 -0
- package/dist/functions/random.d.cts +23 -0
- package/dist/functions/random.d.mts +23 -0
- package/dist/functions/random.d.ts +23 -0
- package/dist/functions/random.d.ts.map +1 -0
- package/dist/functions/set.d.cts +61 -0
- package/dist/functions/set.d.mts +61 -0
- package/dist/functions/set.d.ts +61 -0
- package/dist/functions/set.d.ts.map +1 -0
- package/dist/functions/sort.d.cts +14 -0
- package/dist/functions/sort.d.mts +14 -0
- package/dist/functions/sort.d.ts +14 -0
- package/dist/functions/sort.d.ts.map +1 -0
- package/dist/functions/string.d.cts +122 -0
- package/dist/functions/string.d.mts +122 -0
- package/dist/functions/string.d.ts +122 -0
- package/dist/functions/string.d.ts.map +1 -0
- package/dist/functions/string.test.d.cts +2 -0
- package/dist/functions/string.test.d.mts +2 -0
- package/dist/functions/string.test.d.ts +2 -0
- package/dist/functions/string.test.d.ts.map +1 -0
- package/dist/functions/tuple.d.cts +27 -0
- package/dist/functions/tuple.d.mts +27 -0
- package/dist/functions/tuple.d.ts +27 -0
- package/dist/functions/tuple.d.ts.map +1 -0
- package/dist/functions/types.d.cts +13 -0
- package/dist/functions/types.d.mts +13 -0
- package/dist/functions/types.d.ts +13 -0
- package/dist/functions/types.d.ts.map +1 -0
- package/dist/functions/utils.d.cts +131 -0
- package/dist/functions/utils.d.mts +131 -0
- package/dist/functions/utils.d.ts +131 -0
- package/dist/functions/utils.d.ts.map +1 -0
- package/dist/functions/utils.test.d.cts +2 -0
- package/dist/functions/utils.test.d.mts +2 -0
- package/dist/functions/utils.test.d.ts +2 -0
- package/dist/functions/utils.test.d.ts.map +1 -0
- package/dist/index.cjs +66 -65
- package/dist/index.d.cts +29 -705
- package/dist/index.d.mts +29 -705
- package/dist/index.d.ts +29 -705
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +66 -65
- package/dist/types/AddSubtract.d.cts +23 -0
- package/dist/types/AddSubtract.d.mts +23 -0
- package/dist/types/AddSubtract.d.ts +23 -0
- package/dist/types/AddSubtract.d.ts.map +1 -0
- package/dist/types/CompositionTypeSatisfiesEnum.d.cts +35 -0
- package/dist/types/CompositionTypeSatisfiesEnum.d.mts +35 -0
- package/dist/types/CompositionTypeSatisfiesEnum.d.ts +35 -0
- package/dist/types/CompositionTypeSatisfiesEnum.d.ts.map +1 -0
- package/dist/types/ERange.d.cts +12 -0
- package/dist/types/ERange.d.mts +12 -0
- package/dist/types/ERange.d.ts +12 -0
- package/dist/types/ERange.d.ts.map +1 -0
- package/dist/types/IRange.d.cts +13 -0
- package/dist/types/IRange.d.mts +13 -0
- package/dist/types/IRange.d.ts +13 -0
- package/dist/types/IRange.d.ts.map +1 -0
- package/dist/types/Immutable.d.cts +17 -0
- package/dist/types/Immutable.d.mts +17 -0
- package/dist/types/Immutable.d.ts +17 -0
- package/dist/types/Immutable.d.ts.map +1 -0
- package/dist/types/NaturalNumbersLessThan.d.cts +8 -0
- package/dist/types/NaturalNumbersLessThan.d.mts +8 -0
- package/dist/types/NaturalNumbersLessThan.d.ts +8 -0
- package/dist/types/NaturalNumbersLessThan.d.ts.map +1 -0
- package/dist/types/NaturalNumbersLessThanOrEqualTo.d.cts +8 -0
- package/dist/types/NaturalNumbersLessThanOrEqualTo.d.mts +8 -0
- package/dist/types/NaturalNumbersLessThanOrEqualTo.d.ts +8 -0
- package/dist/types/NaturalNumbersLessThanOrEqualTo.d.ts.map +1 -0
- package/dist/types/ObjectValues.d.cts +3 -0
- package/dist/types/ObjectValues.d.mts +3 -0
- package/dist/types/ObjectValues.d.ts +3 -0
- package/dist/types/ObjectValues.d.ts.map +1 -0
- package/dist/types/ReadonlyMap.d.cts +9 -0
- package/dist/types/ReadonlyMap.d.mts +9 -0
- package/dist/types/ReadonlyMap.d.ts +9 -0
- package/dist/types/ReadonlyMap.d.ts.map +1 -0
- package/dist/types/ReadonlyRecord.d.cts +7 -0
- package/dist/types/ReadonlyRecord.d.mts +7 -0
- package/dist/types/ReadonlyRecord.d.ts +7 -0
- package/dist/types/ReadonlyRecord.d.ts.map +1 -0
- package/dist/types/ReadonlySet.d.cts +8 -0
- package/dist/types/ReadonlySet.d.mts +8 -0
- package/dist/types/ReadonlySet.d.ts +8 -0
- package/dist/types/ReadonlySet.d.ts.map +1 -0
- package/dist/types/Tuple.d.cts +10 -0
- package/dist/types/Tuple.d.mts +10 -0
- package/dist/types/Tuple.d.ts +10 -0
- package/dist/types/Tuple.d.ts.map +1 -0
- package/dist/types/WidenLiteral.d.cts +3 -0
- package/dist/types/WidenLiteral.d.mts +3 -0
- package/dist/types/WidenLiteral.d.ts +3 -0
- package/dist/types/WidenLiteral.d.ts.map +1 -0
- package/dist/types/Writeable.d.cts +9 -0
- package/dist/types/Writeable.d.mts +9 -0
- package/dist/types/Writeable.d.ts +9 -0
- package/dist/types/Writeable.d.ts.map +1 -0
- package/package.json +12 -2
- package/src/constants.ts +5 -0
- package/src/functions/array.ts +8 -2
- package/src/functions/assert.ts +41 -0
- package/src/functions/enums.ts +6 -0
- package/src/functions/map.ts +7 -0
- package/src/functions/math.ts +6 -0
- package/src/functions/object.ts +8 -3
- package/src/functions/random.ts +6 -0
- package/src/functions/set.ts +7 -0
- package/src/functions/sort.ts +6 -0
- package/src/functions/string.ts +25 -0
- package/src/functions/tuple.ts +6 -0
- package/src/functions/types.ts +6 -0
- package/src/functions/utils.test.ts +2 -8
- package/src/functions/utils.ts +7 -37
- package/src/index.ts +13 -12
- package/src/types/AddSubtract.ts +10 -2
- package/src/types/CompositionTypeSatisfiesEnum.ts +5 -3
- package/src/types/ObjectValues.ts +1 -0
- package/src/types/ReadonlyRecord.ts +5 -0
- package/src/types/Tuple.ts +1 -0
- package/src/types/WidenLiteral.ts +1 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright The Complete Contributors
|
|
3
|
+
Copyright (c) 2024 The Complete Contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# complete-common
|
|
1
|
+
# `complete-common`
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/complete-common)
|
|
4
4
|
|
|
5
|
-
This package contains helper functions for a typical TypeScript project, such as [`iRange`](
|
|
5
|
+
This package contains helper functions for a typical [TypeScript](https://www.typescriptlang.org/) project, such as [`iRange`](/complete-common/functions/utils#irange).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Please see the [docs](https://complete-ts.github.io/complete-common) for more information.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Equal to 1000. */
|
|
2
|
+
export declare const SECOND_IN_MILLISECONDS = 1000;
|
|
3
|
+
/** Equal to 60,000. */
|
|
4
|
+
export declare const MINUTE_IN_MILLISECONDS: number;
|
|
5
|
+
/** Equal to 3,600,000. */
|
|
6
|
+
export declare const HOUR_IN_MILLISECONDS: number;
|
|
7
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Equal to 1000. */
|
|
2
|
+
export declare const SECOND_IN_MILLISECONDS = 1000;
|
|
3
|
+
/** Equal to 60,000. */
|
|
4
|
+
export declare const MINUTE_IN_MILLISECONDS: number;
|
|
5
|
+
/** Equal to 3,600,000. */
|
|
6
|
+
export declare const HOUR_IN_MILLISECONDS: number;
|
|
7
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Equal to 1000. */
|
|
2
|
+
export declare const SECOND_IN_MILLISECONDS = 1000;
|
|
3
|
+
/** Equal to 60,000. */
|
|
4
|
+
export declare const MINUTE_IN_MILLISECONDS: number;
|
|
5
|
+
/** Equal to 3,600,000. */
|
|
6
|
+
export declare const HOUR_IN_MILLISECONDS: number;
|
|
7
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C,uBAAuB;AACvB,eAAO,MAAM,sBAAsB,QAA8B,CAAC;AAElE,0BAA0B;AAC1B,eAAO,MAAM,oBAAoB,QAA8B,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with arrays.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { WidenLiteral } from "../index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to copy a two-dimensional array. Note that the sub-arrays will only be shallow
|
|
9
|
+
* copied (using the spread operator).
|
|
10
|
+
*/
|
|
11
|
+
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): T[][];
|
|
12
|
+
/**
|
|
13
|
+
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
14
|
+
* only performs a shallow comparison.
|
|
15
|
+
*/
|
|
16
|
+
export declare function arrayEquals<T>(array1: readonly T[], array2: readonly T[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Builds a new array based on the original array without the specified element(s). Returns the new
|
|
19
|
+
* array. If the specified element(s) are not found in the array, it will simply return a shallow
|
|
20
|
+
* copy of the array.
|
|
21
|
+
*
|
|
22
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
23
|
+
*/
|
|
24
|
+
export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsToRemove: readonly T[]): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Removes the specified element(s) from the array. If the specified element(s) are not found in the
|
|
27
|
+
* array, this function will do nothing.
|
|
28
|
+
*
|
|
29
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
30
|
+
*
|
|
31
|
+
* If there is more than one matching element in the array, this function will only remove the first
|
|
32
|
+
* matching element. If you want to remove all of the elements, use the `arrayRemoveAllInPlace`
|
|
33
|
+
* function instead.
|
|
34
|
+
*
|
|
35
|
+
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
36
|
+
*/
|
|
37
|
+
export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): T[];
|
|
38
|
+
/** Helper function to remove all of the elements in an array in-place. */
|
|
39
|
+
export declare function emptyArray<T>(array: T[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
42
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
43
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
44
|
+
*
|
|
45
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
46
|
+
* amount of elements as the original array.
|
|
47
|
+
*
|
|
48
|
+
* This is named `filterMap` after the Rust function:
|
|
49
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
50
|
+
*/
|
|
51
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => NewT | undefined): NewT[];
|
|
52
|
+
/**
|
|
53
|
+
* Helper function to get a random element from the provided array.
|
|
54
|
+
*
|
|
55
|
+
* Note that this will only work with arrays that do not contain values of `undefined`, since the
|
|
56
|
+
* function uses `undefined` as an indication that the corresponding element does not exist.
|
|
57
|
+
*
|
|
58
|
+
* @param array The array to get an element from.
|
|
59
|
+
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getRandomArrayElement<T>(array: readonly T[], exceptions?: readonly T[]): T;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to get a random index from the provided array.
|
|
64
|
+
*
|
|
65
|
+
* @param array The array to get the index from.
|
|
66
|
+
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
67
|
+
* index. Default is an empty array.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getRandomArrayIndex<T>(array: readonly T[], exceptions?: readonly number[]): number;
|
|
70
|
+
/**
|
|
71
|
+
* Similar to the `Array.includes` method, but works on a widened version of the array.
|
|
72
|
+
*
|
|
73
|
+
* This is useful when the normal `Array.includes` produces a type error from an array that uses an
|
|
74
|
+
* `as const` assertion.
|
|
75
|
+
*/
|
|
76
|
+
export declare function includes<T, TupleElement extends WidenLiteral<T>>(array: readonly TupleElement[], searchElement: WidenLiteral<T>): searchElement is TupleElement;
|
|
77
|
+
/** A wrapper around `Array.isArray` that narrows to `unknown[]` instead of `any[]`. */
|
|
78
|
+
export declare function isArray(arg: unknown): arg is unknown[];
|
|
79
|
+
/** Initializes an array with all elements containing the specified default value. */
|
|
80
|
+
export declare function newArray<T>(length: number, value: T): T[];
|
|
81
|
+
/** Helper function to sum every value in an array together. */
|
|
82
|
+
export declare function sumArray(array: readonly number[]): number;
|
|
83
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with arrays.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { WidenLiteral } from "../index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to copy a two-dimensional array. Note that the sub-arrays will only be shallow
|
|
9
|
+
* copied (using the spread operator).
|
|
10
|
+
*/
|
|
11
|
+
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): T[][];
|
|
12
|
+
/**
|
|
13
|
+
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
14
|
+
* only performs a shallow comparison.
|
|
15
|
+
*/
|
|
16
|
+
export declare function arrayEquals<T>(array1: readonly T[], array2: readonly T[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Builds a new array based on the original array without the specified element(s). Returns the new
|
|
19
|
+
* array. If the specified element(s) are not found in the array, it will simply return a shallow
|
|
20
|
+
* copy of the array.
|
|
21
|
+
*
|
|
22
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
23
|
+
*/
|
|
24
|
+
export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsToRemove: readonly T[]): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Removes the specified element(s) from the array. If the specified element(s) are not found in the
|
|
27
|
+
* array, this function will do nothing.
|
|
28
|
+
*
|
|
29
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
30
|
+
*
|
|
31
|
+
* If there is more than one matching element in the array, this function will only remove the first
|
|
32
|
+
* matching element. If you want to remove all of the elements, use the `arrayRemoveAllInPlace`
|
|
33
|
+
* function instead.
|
|
34
|
+
*
|
|
35
|
+
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
36
|
+
*/
|
|
37
|
+
export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): T[];
|
|
38
|
+
/** Helper function to remove all of the elements in an array in-place. */
|
|
39
|
+
export declare function emptyArray<T>(array: T[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
42
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
43
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
44
|
+
*
|
|
45
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
46
|
+
* amount of elements as the original array.
|
|
47
|
+
*
|
|
48
|
+
* This is named `filterMap` after the Rust function:
|
|
49
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
50
|
+
*/
|
|
51
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => NewT | undefined): NewT[];
|
|
52
|
+
/**
|
|
53
|
+
* Helper function to get a random element from the provided array.
|
|
54
|
+
*
|
|
55
|
+
* Note that this will only work with arrays that do not contain values of `undefined`, since the
|
|
56
|
+
* function uses `undefined` as an indication that the corresponding element does not exist.
|
|
57
|
+
*
|
|
58
|
+
* @param array The array to get an element from.
|
|
59
|
+
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getRandomArrayElement<T>(array: readonly T[], exceptions?: readonly T[]): T;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to get a random index from the provided array.
|
|
64
|
+
*
|
|
65
|
+
* @param array The array to get the index from.
|
|
66
|
+
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
67
|
+
* index. Default is an empty array.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getRandomArrayIndex<T>(array: readonly T[], exceptions?: readonly number[]): number;
|
|
70
|
+
/**
|
|
71
|
+
* Similar to the `Array.includes` method, but works on a widened version of the array.
|
|
72
|
+
*
|
|
73
|
+
* This is useful when the normal `Array.includes` produces a type error from an array that uses an
|
|
74
|
+
* `as const` assertion.
|
|
75
|
+
*/
|
|
76
|
+
export declare function includes<T, TupleElement extends WidenLiteral<T>>(array: readonly TupleElement[], searchElement: WidenLiteral<T>): searchElement is TupleElement;
|
|
77
|
+
/** A wrapper around `Array.isArray` that narrows to `unknown[]` instead of `any[]`. */
|
|
78
|
+
export declare function isArray(arg: unknown): arg is unknown[];
|
|
79
|
+
/** Initializes an array with all elements containing the specified default value. */
|
|
80
|
+
export declare function newArray<T>(length: number, value: T): T[];
|
|
81
|
+
/** Helper function to sum every value in an array together. */
|
|
82
|
+
export declare function sumArray(array: readonly number[]): number;
|
|
83
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with arrays.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { WidenLiteral } from "../index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to copy a two-dimensional array. Note that the sub-arrays will only be shallow
|
|
9
|
+
* copied (using the spread operator).
|
|
10
|
+
*/
|
|
11
|
+
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): T[][];
|
|
12
|
+
/**
|
|
13
|
+
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
14
|
+
* only performs a shallow comparison.
|
|
15
|
+
*/
|
|
16
|
+
export declare function arrayEquals<T>(array1: readonly T[], array2: readonly T[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Builds a new array based on the original array without the specified element(s). Returns the new
|
|
19
|
+
* array. If the specified element(s) are not found in the array, it will simply return a shallow
|
|
20
|
+
* copy of the array.
|
|
21
|
+
*
|
|
22
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
23
|
+
*/
|
|
24
|
+
export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsToRemove: readonly T[]): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Removes the specified element(s) from the array. If the specified element(s) are not found in the
|
|
27
|
+
* array, this function will do nothing.
|
|
28
|
+
*
|
|
29
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
30
|
+
*
|
|
31
|
+
* If there is more than one matching element in the array, this function will only remove the first
|
|
32
|
+
* matching element. If you want to remove all of the elements, use the `arrayRemoveAllInPlace`
|
|
33
|
+
* function instead.
|
|
34
|
+
*
|
|
35
|
+
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
36
|
+
*/
|
|
37
|
+
export declare function arrayRemoveInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): T[];
|
|
38
|
+
/** Helper function to remove all of the elements in an array in-place. */
|
|
39
|
+
export declare function emptyArray<T>(array: T[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Helper function to perform a filter and a map at the same time. Similar to `Array.map`, provide a
|
|
42
|
+
* function that transforms a value, but return `undefined` if the value should be skipped. (Thus,
|
|
43
|
+
* this function cannot be used in situations where `undefined` can be a valid array element.)
|
|
44
|
+
*
|
|
45
|
+
* This function is useful because the `Array.map` method will always produce an array with the same
|
|
46
|
+
* amount of elements as the original array.
|
|
47
|
+
*
|
|
48
|
+
* This is named `filterMap` after the Rust function:
|
|
49
|
+
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
50
|
+
*/
|
|
51
|
+
export declare function filterMap<OldT, NewT>(array: readonly OldT[], func: (element: OldT) => NewT | undefined): NewT[];
|
|
52
|
+
/**
|
|
53
|
+
* Helper function to get a random element from the provided array.
|
|
54
|
+
*
|
|
55
|
+
* Note that this will only work with arrays that do not contain values of `undefined`, since the
|
|
56
|
+
* function uses `undefined` as an indication that the corresponding element does not exist.
|
|
57
|
+
*
|
|
58
|
+
* @param array The array to get an element from.
|
|
59
|
+
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getRandomArrayElement<T>(array: readonly T[], exceptions?: readonly T[]): T;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to get a random index from the provided array.
|
|
64
|
+
*
|
|
65
|
+
* @param array The array to get the index from.
|
|
66
|
+
* @param exceptions Optional. An array of indexes that will be skipped over when getting the random
|
|
67
|
+
* index. Default is an empty array.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getRandomArrayIndex<T>(array: readonly T[], exceptions?: readonly number[]): number;
|
|
70
|
+
/**
|
|
71
|
+
* Similar to the `Array.includes` method, but works on a widened version of the array.
|
|
72
|
+
*
|
|
73
|
+
* This is useful when the normal `Array.includes` produces a type error from an array that uses an
|
|
74
|
+
* `as const` assertion.
|
|
75
|
+
*/
|
|
76
|
+
export declare function includes<T, TupleElement extends WidenLiteral<T>>(array: readonly TupleElement[], searchElement: WidenLiteral<T>): searchElement is TupleElement;
|
|
77
|
+
/** A wrapper around `Array.isArray` that narrows to `unknown[]` instead of `any[]`. */
|
|
78
|
+
export declare function isArray(arg: unknown): arg is unknown[];
|
|
79
|
+
/** Initializes an array with all elements containing the specified default value. */
|
|
80
|
+
export declare function newArray<T>(length: number, value: T): T[];
|
|
81
|
+
/** Helper function to sum every value in an array together. */
|
|
82
|
+
export declare function sumArray(array: readonly number[]): number;
|
|
83
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/functions/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD;;;GAGG;AAEH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,GACjC,CAAC,EAAE,EAAE,CAQP;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,MAAM,EAAE,SAAS,CAAC,EAAE,GACnB,OAAO,CAST;AAED;;;;;;GAMG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,SAAS,CAAC,EAAE,EAC3B,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,CAAC,EAAE,CAWL;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,kBAAkB,CAAC,CAAC,EAElC,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,CAAC,EAAE,CAYL;AAED,0EAA0E;AAE1E,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,CAE9C;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAClC,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,IAAI,GAAG,SAAS,GACxC,IAAI,EAAE,CAWR;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,UAAU,GAAE,SAAS,CAAC,EAAO,GAC5B,CAAC,CAiBH;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,UAAU,GAAE,SAAS,MAAM,EAAO,GACjC,MAAM,CAQR;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,SAAS,YAAY,CAAC,CAAC,CAAC,EAC9D,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC,GAC7B,aAAa,IAAI,YAAY,CAG/B;AAED,uFAAuF;AACvF,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,EAAE,CAEtD;AAED,qFAAqF;AAErF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAEzD;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEzD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with asserting.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* This is useful to have TypeScript narrow a `T | undefined` value to `T` in a concise way.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
|
|
12
|
+
"The assertion is useless because the provided value does not contain undefined."
|
|
13
|
+
]): asserts value is Exclude<T, undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Helper function to throw an error if the provided value is equal to `null`.
|
|
16
|
+
*
|
|
17
|
+
* This is useful to have TypeScript narrow a `T | null` value to `T` in a concise way.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
20
|
+
"The assertion is useless because the provided value does not contain null."
|
|
21
|
+
]): asserts value is Exclude<T, null>;
|
|
22
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with asserting.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* This is useful to have TypeScript narrow a `T | undefined` value to `T` in a concise way.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
|
|
12
|
+
"The assertion is useless because the provided value does not contain undefined."
|
|
13
|
+
]): asserts value is Exclude<T, undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Helper function to throw an error if the provided value is equal to `null`.
|
|
16
|
+
*
|
|
17
|
+
* This is useful to have TypeScript narrow a `T | null` value to `T` in a concise way.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
20
|
+
"The assertion is useless because the provided value does not contain null."
|
|
21
|
+
]): asserts value is Exclude<T, null>;
|
|
22
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with asserting.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* This is useful to have TypeScript narrow a `T | undefined` value to `T` in a concise way.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends [T] ? [string] : [
|
|
12
|
+
"The assertion is useless because the provided value does not contain undefined."
|
|
13
|
+
]): asserts value is Exclude<T, undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Helper function to throw an error if the provided value is equal to `null`.
|
|
16
|
+
*
|
|
17
|
+
* This is useful to have TypeScript narrow a `T | null` value to `T` in a concise way.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
20
|
+
"The assertion is useless because the provided value does not contain null."
|
|
21
|
+
]): asserts value is Exclude<T, null>;
|
|
22
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAC7B,CAAC,MAAM,CAAC,GACR;IACE,iFAAiF;CAClF,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,CAIxC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,CAAC,GACR;IACE,4EAA4E;CAC7E,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAInC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with TypeScript enums.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
type TranspiledEnum = Record<string, string | number>;
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to get the entries of an enum.
|
|
9
|
+
*
|
|
10
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
11
|
+
* have to be filtered out.)
|
|
12
|
+
*
|
|
13
|
+
* This function will work properly for both number and string enums.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getEnumEntries<T extends TranspiledEnum>(transpiledEnum: T): ReadonlyArray<[key: string, value: T[keyof T]]>;
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to get the keys of an enum.
|
|
18
|
+
*
|
|
19
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
20
|
+
* have to be filtered out.)
|
|
21
|
+
*
|
|
22
|
+
* This function will work properly for both number and string enums.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEnumKeys(transpiledEnum: TranspiledEnum): readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to get the only the values of an enum.
|
|
27
|
+
*
|
|
28
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
29
|
+
* have to be filtered out.)
|
|
30
|
+
*
|
|
31
|
+
* This function will work properly for both number and string enums.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getEnumValues<T extends TranspiledEnum>(transpiledEnum: T): ReadonlyArray<T[keyof T]>;
|
|
34
|
+
/**
|
|
35
|
+
* Helper function to validate that an interface contains all of the keys of an enum. You must
|
|
36
|
+
* specify both generic parameters in order for this to work properly (i.e. the interface and then
|
|
37
|
+
* the enum).
|
|
38
|
+
*
|
|
39
|
+
* For example:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* enum MyEnum {
|
|
43
|
+
* Value1,
|
|
44
|
+
* Value2,
|
|
45
|
+
* Value3,
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* interface MyEnumToType {
|
|
49
|
+
* [MyEnum.Value1]: boolean;
|
|
50
|
+
* [MyEnum.Value2]: number;
|
|
51
|
+
* [MyEnum.Value3]: string;
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* interfaceSatisfiesEnum<MyEnumToType, MyEnum>();
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* This function is only meant to be used with interfaces (i.e. types that will not exist at
|
|
58
|
+
* run-time). If you are generating an object that will contain all of the keys of an enum, use the
|
|
59
|
+
* `satisfies` operator with the `Record` type instead.
|
|
60
|
+
*/
|
|
61
|
+
export declare function interfaceSatisfiesEnum<T extends Record<Enum, unknown>, Enum extends string | number>(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to validate that a particular value exists inside of an enum.
|
|
64
|
+
*
|
|
65
|
+
* @param value The value to check.
|
|
66
|
+
* @param transpiledEnum The enum to check against.
|
|
67
|
+
* @param set Optional. A set that contains all of the values of an enum. If provided, this function
|
|
68
|
+
* will check for existence using the set (instead of the enum itself). Using a set
|
|
69
|
+
* should be more performant for enums with around 52 or more elements.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, set?: ReadonlySet<string | number>): value is T[keyof T];
|
|
72
|
+
export {};
|
|
73
|
+
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with TypeScript enums.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
type TranspiledEnum = Record<string, string | number>;
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to get the entries of an enum.
|
|
9
|
+
*
|
|
10
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
11
|
+
* have to be filtered out.)
|
|
12
|
+
*
|
|
13
|
+
* This function will work properly for both number and string enums.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getEnumEntries<T extends TranspiledEnum>(transpiledEnum: T): ReadonlyArray<[key: string, value: T[keyof T]]>;
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to get the keys of an enum.
|
|
18
|
+
*
|
|
19
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
20
|
+
* have to be filtered out.)
|
|
21
|
+
*
|
|
22
|
+
* This function will work properly for both number and string enums.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEnumKeys(transpiledEnum: TranspiledEnum): readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to get the only the values of an enum.
|
|
27
|
+
*
|
|
28
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
29
|
+
* have to be filtered out.)
|
|
30
|
+
*
|
|
31
|
+
* This function will work properly for both number and string enums.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getEnumValues<T extends TranspiledEnum>(transpiledEnum: T): ReadonlyArray<T[keyof T]>;
|
|
34
|
+
/**
|
|
35
|
+
* Helper function to validate that an interface contains all of the keys of an enum. You must
|
|
36
|
+
* specify both generic parameters in order for this to work properly (i.e. the interface and then
|
|
37
|
+
* the enum).
|
|
38
|
+
*
|
|
39
|
+
* For example:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* enum MyEnum {
|
|
43
|
+
* Value1,
|
|
44
|
+
* Value2,
|
|
45
|
+
* Value3,
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* interface MyEnumToType {
|
|
49
|
+
* [MyEnum.Value1]: boolean;
|
|
50
|
+
* [MyEnum.Value2]: number;
|
|
51
|
+
* [MyEnum.Value3]: string;
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* interfaceSatisfiesEnum<MyEnumToType, MyEnum>();
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* This function is only meant to be used with interfaces (i.e. types that will not exist at
|
|
58
|
+
* run-time). If you are generating an object that will contain all of the keys of an enum, use the
|
|
59
|
+
* `satisfies` operator with the `Record` type instead.
|
|
60
|
+
*/
|
|
61
|
+
export declare function interfaceSatisfiesEnum<T extends Record<Enum, unknown>, Enum extends string | number>(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to validate that a particular value exists inside of an enum.
|
|
64
|
+
*
|
|
65
|
+
* @param value The value to check.
|
|
66
|
+
* @param transpiledEnum The enum to check against.
|
|
67
|
+
* @param set Optional. A set that contains all of the values of an enum. If provided, this function
|
|
68
|
+
* will check for existence using the set (instead of the enum itself). Using a set
|
|
69
|
+
* should be more performant for enums with around 52 or more elements.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, set?: ReadonlySet<string | number>): value is T[keyof T];
|
|
72
|
+
export {};
|
|
73
|
+
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with TypeScript enums.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
type TranspiledEnum = Record<string, string | number>;
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to get the entries of an enum.
|
|
9
|
+
*
|
|
10
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
11
|
+
* have to be filtered out.)
|
|
12
|
+
*
|
|
13
|
+
* This function will work properly for both number and string enums.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getEnumEntries<T extends TranspiledEnum>(transpiledEnum: T): ReadonlyArray<[key: string, value: T[keyof T]]>;
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to get the keys of an enum.
|
|
18
|
+
*
|
|
19
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
20
|
+
* have to be filtered out.)
|
|
21
|
+
*
|
|
22
|
+
* This function will work properly for both number and string enums.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEnumKeys(transpiledEnum: TranspiledEnum): readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to get the only the values of an enum.
|
|
27
|
+
*
|
|
28
|
+
* (By default, TypeScript will put the keys inside of the values of a number-based enum, so those
|
|
29
|
+
* have to be filtered out.)
|
|
30
|
+
*
|
|
31
|
+
* This function will work properly for both number and string enums.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getEnumValues<T extends TranspiledEnum>(transpiledEnum: T): ReadonlyArray<T[keyof T]>;
|
|
34
|
+
/**
|
|
35
|
+
* Helper function to validate that an interface contains all of the keys of an enum. You must
|
|
36
|
+
* specify both generic parameters in order for this to work properly (i.e. the interface and then
|
|
37
|
+
* the enum).
|
|
38
|
+
*
|
|
39
|
+
* For example:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* enum MyEnum {
|
|
43
|
+
* Value1,
|
|
44
|
+
* Value2,
|
|
45
|
+
* Value3,
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* interface MyEnumToType {
|
|
49
|
+
* [MyEnum.Value1]: boolean;
|
|
50
|
+
* [MyEnum.Value2]: number;
|
|
51
|
+
* [MyEnum.Value3]: string;
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* interfaceSatisfiesEnum<MyEnumToType, MyEnum>();
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* This function is only meant to be used with interfaces (i.e. types that will not exist at
|
|
58
|
+
* run-time). If you are generating an object that will contain all of the keys of an enum, use the
|
|
59
|
+
* `satisfies` operator with the `Record` type instead.
|
|
60
|
+
*/
|
|
61
|
+
export declare function interfaceSatisfiesEnum<T extends Record<Enum, unknown>, Enum extends string | number>(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to validate that a particular value exists inside of an enum.
|
|
64
|
+
*
|
|
65
|
+
* @param value The value to check.
|
|
66
|
+
* @param transpiledEnum The enum to check against.
|
|
67
|
+
* @param set Optional. A set that contains all of the values of an enum. If provided, this function
|
|
68
|
+
* will check for existence using the set (instead of the enum itself). Using a set
|
|
69
|
+
* should be more performant for enums with around 52 or more elements.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, set?: ReadonlySet<string | number>): value is T[keyof T];
|
|
72
|
+
export {};
|
|
73
|
+
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/functions/enums.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,cAAc,EACrD,cAAc,EAAE,CAAC,GAChB,aAAa,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CASjD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,MAAM,EAAE,CAG7E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,cAAc,EACpD,cAAc,EAAE,CAAC,GAChB,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAG3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAEpC,CAAC,SAAS,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAC/B,IAAI,SAAS,MAAM,GAAG,MAAM,KACzB,IAAI,CAAG;AAEZ;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,cAAc,EAClD,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,cAAc,EAAE,CAAC,EACjB,GAAG,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,GACjC,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAOrB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper functions that have to do with
|
|
3
|
+
* [maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to get the values in a `Map` that match an arbitrary condition. Similar to the
|
|
9
|
+
* `Array.map` method, but works for maps.
|
|
10
|
+
*
|
|
11
|
+
* This is efficient such that it avoids converting the map values into an array.
|
|
12
|
+
*
|
|
13
|
+
* If you want to perform a filter and a map at the same time on an array, use the `filterMap`
|
|
14
|
+
* helper function instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mapFilter<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V) => boolean): V[];
|
|
17
|
+
/**
|
|
18
|
+
* Helper function to find a value in a `Map`. Similar to the `Array.find` method, but works for
|
|
19
|
+
* maps.
|
|
20
|
+
*
|
|
21
|
+
* This is efficient such that it avoids converting the map values into an array.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mapFind<K, V>(map: ReadonlyMap<K, V>, predicate: (value: V) => boolean): V | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to convert an object to a map.
|
|
26
|
+
*
|
|
27
|
+
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
28
|
+
* then later on you need to query it in a way where you expect the return value to be T or
|
|
29
|
+
* undefined. In this situation, by converting the object to a map, you can avoid unsafe type
|
|
30
|
+
* assertions.
|
|
31
|
+
*
|
|
32
|
+
* Note that the map values will be inserted in a random order, due to how `pairs` works under the
|
|
33
|
+
* hood.
|
|
34
|
+
*
|
|
35
|
+
* Also see the `objectToReadonlyMap` function.
|
|
36
|
+
*/
|
|
37
|
+
export declare function objectToMap<K extends string | number | symbol, V>(object: Record<K, V>): Map<K, V>;
|
|
38
|
+
/**
|
|
39
|
+
* Helper function to convert an object to a read-only map.
|
|
40
|
+
*
|
|
41
|
+
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
42
|
+
* then later on you need to query it in a way where you expect the return value to be T or
|
|
43
|
+
* undefined. In this situation, by converting the object to a map, you can avoid unsafe type
|
|
44
|
+
* assertions.
|
|
45
|
+
*
|
|
46
|
+
* Note that the map values will be inserted in a random order, due to how `pairs` works under the
|
|
47
|
+
* hood.
|
|
48
|
+
*
|
|
49
|
+
* Also see the `objectToMap` function.
|
|
50
|
+
*/
|
|
51
|
+
export declare function objectToReadonlyMap<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlyMap<K, V>;
|
|
52
|
+
//# sourceMappingURL=map.d.ts.map
|