complete-common 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -3
  3. package/dist/constants.d.cts +7 -0
  4. package/dist/constants.d.mts +7 -0
  5. package/dist/constants.d.ts +7 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/functions/array.d.cts +83 -0
  8. package/dist/functions/array.d.mts +83 -0
  9. package/dist/functions/array.d.ts +83 -0
  10. package/dist/functions/array.d.ts.map +1 -0
  11. package/dist/functions/assert.d.cts +45 -0
  12. package/dist/functions/assert.d.mts +45 -0
  13. package/dist/functions/assert.d.ts +45 -0
  14. package/dist/functions/assert.d.ts.map +1 -0
  15. package/dist/functions/enums.d.cts +73 -0
  16. package/dist/functions/enums.d.mts +73 -0
  17. package/dist/functions/enums.d.ts +73 -0
  18. package/dist/functions/enums.d.ts.map +1 -0
  19. package/dist/functions/map.d.cts +24 -0
  20. package/dist/functions/map.d.mts +24 -0
  21. package/dist/functions/map.d.ts +24 -0
  22. package/dist/functions/map.d.ts.map +1 -0
  23. package/dist/functions/math.d.cts +13 -0
  24. package/dist/functions/math.d.mts +13 -0
  25. package/dist/functions/math.d.ts +13 -0
  26. package/dist/functions/math.d.ts.map +1 -0
  27. package/dist/functions/object.d.cts +60 -0
  28. package/dist/functions/object.d.mts +60 -0
  29. package/dist/functions/object.d.ts +60 -0
  30. package/dist/functions/object.d.ts.map +1 -0
  31. package/dist/functions/random.d.cts +23 -0
  32. package/dist/functions/random.d.mts +23 -0
  33. package/dist/functions/random.d.ts +23 -0
  34. package/dist/functions/random.d.ts.map +1 -0
  35. package/dist/functions/set.d.cts +61 -0
  36. package/dist/functions/set.d.mts +61 -0
  37. package/dist/functions/set.d.ts +61 -0
  38. package/dist/functions/set.d.ts.map +1 -0
  39. package/dist/functions/sort.d.cts +14 -0
  40. package/dist/functions/sort.d.mts +14 -0
  41. package/dist/functions/sort.d.ts +14 -0
  42. package/dist/functions/sort.d.ts.map +1 -0
  43. package/dist/functions/string.d.cts +122 -0
  44. package/dist/functions/string.d.mts +122 -0
  45. package/dist/functions/string.d.ts +122 -0
  46. package/dist/functions/string.d.ts.map +1 -0
  47. package/dist/functions/string.test.d.cts +2 -0
  48. package/dist/functions/string.test.d.mts +2 -0
  49. package/dist/functions/string.test.d.ts +2 -0
  50. package/dist/functions/string.test.d.ts.map +1 -0
  51. package/dist/functions/time.d.cts +20 -0
  52. package/dist/functions/time.d.mts +20 -0
  53. package/dist/functions/time.d.ts +20 -0
  54. package/dist/functions/time.d.ts.map +1 -0
  55. package/dist/functions/tuple.d.cts +27 -0
  56. package/dist/functions/tuple.d.mts +27 -0
  57. package/dist/functions/tuple.d.ts +27 -0
  58. package/dist/functions/tuple.d.ts.map +1 -0
  59. package/dist/functions/types.d.cts +13 -0
  60. package/dist/functions/types.d.mts +13 -0
  61. package/dist/functions/types.d.ts +13 -0
  62. package/dist/functions/types.d.ts.map +1 -0
  63. package/dist/functions/utils.d.cts +131 -0
  64. package/dist/functions/utils.d.mts +131 -0
  65. package/dist/functions/utils.d.ts +131 -0
  66. package/dist/functions/utils.d.ts.map +1 -0
  67. package/dist/functions/utils.test.d.cts +2 -0
  68. package/dist/functions/utils.test.d.mts +2 -0
  69. package/dist/functions/utils.test.d.ts +2 -0
  70. package/dist/functions/utils.test.d.ts.map +1 -0
  71. package/dist/index.cjs +122 -77
  72. package/dist/index.d.cts +30 -705
  73. package/dist/index.d.mts +30 -705
  74. package/dist/index.d.ts +30 -705
  75. package/dist/index.d.ts.map +1 -0
  76. package/dist/index.mjs +118 -78
  77. package/dist/types/AddSubtract.d.cts +23 -0
  78. package/dist/types/AddSubtract.d.mts +23 -0
  79. package/dist/types/AddSubtract.d.ts +23 -0
  80. package/dist/types/AddSubtract.d.ts.map +1 -0
  81. package/dist/types/CompositionTypeSatisfiesEnum.d.cts +35 -0
  82. package/dist/types/CompositionTypeSatisfiesEnum.d.mts +35 -0
  83. package/dist/types/CompositionTypeSatisfiesEnum.d.ts +35 -0
  84. package/dist/types/CompositionTypeSatisfiesEnum.d.ts.map +1 -0
  85. package/dist/types/ERange.d.cts +12 -0
  86. package/dist/types/ERange.d.mts +12 -0
  87. package/dist/types/ERange.d.ts +12 -0
  88. package/dist/types/ERange.d.ts.map +1 -0
  89. package/dist/types/IRange.d.cts +13 -0
  90. package/dist/types/IRange.d.mts +13 -0
  91. package/dist/types/IRange.d.ts +13 -0
  92. package/dist/types/IRange.d.ts.map +1 -0
  93. package/dist/types/Immutable.d.cts +17 -0
  94. package/dist/types/Immutable.d.mts +17 -0
  95. package/dist/types/Immutable.d.ts +17 -0
  96. package/dist/types/Immutable.d.ts.map +1 -0
  97. package/dist/types/NaturalNumbersLessThan.d.cts +8 -0
  98. package/dist/types/NaturalNumbersLessThan.d.mts +8 -0
  99. package/dist/types/NaturalNumbersLessThan.d.ts +8 -0
  100. package/dist/types/NaturalNumbersLessThan.d.ts.map +1 -0
  101. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.cts +8 -0
  102. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.mts +8 -0
  103. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.ts +8 -0
  104. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.ts.map +1 -0
  105. package/dist/types/ObjectValues.d.cts +3 -0
  106. package/dist/types/ObjectValues.d.mts +3 -0
  107. package/dist/types/ObjectValues.d.ts +3 -0
  108. package/dist/types/ObjectValues.d.ts.map +1 -0
  109. package/dist/types/ReadonlyMap.d.cts +9 -0
  110. package/dist/types/ReadonlyMap.d.mts +9 -0
  111. package/dist/types/ReadonlyMap.d.ts +9 -0
  112. package/dist/types/ReadonlyMap.d.ts.map +1 -0
  113. package/dist/types/ReadonlyRecord.d.cts +7 -0
  114. package/dist/types/ReadonlyRecord.d.mts +7 -0
  115. package/dist/types/ReadonlyRecord.d.ts +7 -0
  116. package/dist/types/ReadonlyRecord.d.ts.map +1 -0
  117. package/dist/types/ReadonlySet.d.cts +8 -0
  118. package/dist/types/ReadonlySet.d.mts +8 -0
  119. package/dist/types/ReadonlySet.d.ts +8 -0
  120. package/dist/types/ReadonlySet.d.ts.map +1 -0
  121. package/dist/types/Tuple.d.cts +10 -0
  122. package/dist/types/Tuple.d.mts +10 -0
  123. package/dist/types/Tuple.d.ts +10 -0
  124. package/dist/types/Tuple.d.ts.map +1 -0
  125. package/dist/types/WidenLiteral.d.cts +3 -0
  126. package/dist/types/WidenLiteral.d.mts +3 -0
  127. package/dist/types/WidenLiteral.d.ts +3 -0
  128. package/dist/types/WidenLiteral.d.ts.map +1 -0
  129. package/dist/types/Writeable.d.cts +9 -0
  130. package/dist/types/Writeable.d.mts +9 -0
  131. package/dist/types/Writeable.d.ts +9 -0
  132. package/dist/types/Writeable.d.ts.map +1 -0
  133. package/package.json +13 -2
  134. package/src/constants.ts +5 -0
  135. package/src/functions/array.ts +8 -2
  136. package/src/functions/assert.ts +86 -0
  137. package/src/functions/enums.ts +6 -0
  138. package/src/functions/map.ts +7 -45
  139. package/src/functions/math.ts +6 -0
  140. package/src/functions/object.ts +90 -3
  141. package/src/functions/random.ts +6 -0
  142. package/src/functions/set.ts +7 -0
  143. package/src/functions/sort.ts +6 -0
  144. package/src/functions/string.ts +25 -0
  145. package/src/functions/time.ts +26 -0
  146. package/src/functions/tuple.ts +6 -0
  147. package/src/functions/types.ts +6 -0
  148. package/src/functions/utils.test.ts +2 -8
  149. package/src/functions/utils.ts +7 -37
  150. package/src/index.ts +14 -12
  151. package/src/types/AddSubtract.ts +10 -2
  152. package/src/types/CompositionTypeSatisfiesEnum.ts +5 -3
  153. package/src/types/ObjectValues.ts +1 -0
  154. package/src/types/ReadonlyRecord.ts +5 -0
  155. package/src/types/Tuple.ts +1 -0
  156. package/src/types/WidenLiteral.ts +1 -0
@@ -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,24 @@
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
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1,24 @@
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
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1,24 @@
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
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/functions/map.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;GAQG;AAEH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAC/B,CAAC,EAAE,CAWL;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAC1B,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAC/B,CAAC,GAAG,SAAS,CASf"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Helper functions that have to do with math.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to normalize a number, ensuring that it is within a certain range.
8
+ *
9
+ * - If `num` is less than `min`, then it will be clamped to `min`.
10
+ * - If `num` is greater than `max`, then it will be clamped to `max`.
11
+ */
12
+ export declare function clamp(num: number, min: number, max: number): number;
13
+ //# sourceMappingURL=math.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Helper functions that have to do with math.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to normalize a number, ensuring that it is within a certain range.
8
+ *
9
+ * - If `num` is less than `min`, then it will be clamped to `min`.
10
+ * - If `num` is greater than `max`, then it will be clamped to `max`.
11
+ */
12
+ export declare function clamp(num: number, min: number, max: number): number;
13
+ //# sourceMappingURL=math.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Helper functions that have to do with math.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to normalize a number, ensuring that it is within a certain range.
8
+ *
9
+ * - If `num` is less than `min`, then it will be clamped to `min`.
10
+ * - If `num` is greater than `max`, then it will be clamped to `max`.
11
+ */
12
+ export declare function clamp(num: number, min: number, max: number): number;
13
+ //# sourceMappingURL=math.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/functions/math.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnE"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Helper functions that have to do with objects.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
7
+ /**
8
+ * Helper function to get the values in an object that match an arbitrary condition. Similar to the
9
+ * `Array.map` method, but works for objects.
10
+ *
11
+ * This is efficient such that it avoids converting the object values into an array.
12
+ */
13
+ export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): V[];
14
+ /**
15
+ * Helper function to convert an object to a map.
16
+ *
17
+ * This is useful when you need to construct a type safe object with the `satisfies` operator, but
18
+ * then later on you need to query it in a way where you expect the return value to be T or
19
+ * undefined. In this situation, by converting the object to a map, you can avoid unsafe type
20
+ * assertions.
21
+ *
22
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
23
+ * only having string keys under the hood.
24
+ *
25
+ * Also see the `objectToReadonlyMap` function.
26
+ */
27
+ export declare function objectToMap<K extends string | number | symbol, V>(object: Record<K, V>): Map<K, V>;
28
+ /**
29
+ * Helper function to convert an object to a read-only map.
30
+ *
31
+ * This is useful when you need to construct a type safe object with the `satisfies` operator, but
32
+ * then later on you need to query it in a way where you expect the return value to be T or
33
+ * undefined. In this situation, by converting the object to a map, you can avoid unsafe type
34
+ * assertions.
35
+ *
36
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
37
+ * only having string keys under the hood.
38
+ *
39
+ * Also see the `objectToMap` function.
40
+ */
41
+ export declare function objectToReadonlyMap<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlyMap<K, V>;
42
+ /**
43
+ * Helper function to convert an object to a reverse map.
44
+ *
45
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
46
+ * only having string keys under the hood.
47
+ *
48
+ * Also see the `objectToReverseReadonlyMap` function.
49
+ */
50
+ export declare function objectToReverseMap<K extends string | number | symbol, V extends string | number | symbol>(object: Record<K, V>): Map<V, K>;
51
+ /**
52
+ * Helper function to convert an object to a reverse read-only map.
53
+ *
54
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
55
+ * only having string keys under the hood.
56
+ *
57
+ * Also see the `objectToReverseMap` function.
58
+ */
59
+ export declare function objectToReverseReadonlyMap<K extends string | number | symbol, V extends string | number | symbol>(object: Record<K, V>): ReadonlyMap<V, K>;
60
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Helper functions that have to do with objects.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
7
+ /**
8
+ * Helper function to get the values in an object that match an arbitrary condition. Similar to the
9
+ * `Array.map` method, but works for objects.
10
+ *
11
+ * This is efficient such that it avoids converting the object values into an array.
12
+ */
13
+ export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): V[];
14
+ /**
15
+ * Helper function to convert an object to a map.
16
+ *
17
+ * This is useful when you need to construct a type safe object with the `satisfies` operator, but
18
+ * then later on you need to query it in a way where you expect the return value to be T or
19
+ * undefined. In this situation, by converting the object to a map, you can avoid unsafe type
20
+ * assertions.
21
+ *
22
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
23
+ * only having string keys under the hood.
24
+ *
25
+ * Also see the `objectToReadonlyMap` function.
26
+ */
27
+ export declare function objectToMap<K extends string | number | symbol, V>(object: Record<K, V>): Map<K, V>;
28
+ /**
29
+ * Helper function to convert an object to a read-only map.
30
+ *
31
+ * This is useful when you need to construct a type safe object with the `satisfies` operator, but
32
+ * then later on you need to query it in a way where you expect the return value to be T or
33
+ * undefined. In this situation, by converting the object to a map, you can avoid unsafe type
34
+ * assertions.
35
+ *
36
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
37
+ * only having string keys under the hood.
38
+ *
39
+ * Also see the `objectToMap` function.
40
+ */
41
+ export declare function objectToReadonlyMap<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlyMap<K, V>;
42
+ /**
43
+ * Helper function to convert an object to a reverse map.
44
+ *
45
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
46
+ * only having string keys under the hood.
47
+ *
48
+ * Also see the `objectToReverseReadonlyMap` function.
49
+ */
50
+ export declare function objectToReverseMap<K extends string | number | symbol, V extends string | number | symbol>(object: Record<K, V>): Map<V, K>;
51
+ /**
52
+ * Helper function to convert an object to a reverse read-only map.
53
+ *
54
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
55
+ * only having string keys under the hood.
56
+ *
57
+ * Also see the `objectToReverseMap` function.
58
+ */
59
+ export declare function objectToReverseReadonlyMap<K extends string | number | symbol, V extends string | number | symbol>(object: Record<K, V>): ReadonlyMap<V, K>;
60
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Helper functions that have to do with objects.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
7
+ /**
8
+ * Helper function to get the values in an object that match an arbitrary condition. Similar to the
9
+ * `Array.map` method, but works for objects.
10
+ *
11
+ * This is efficient such that it avoids converting the object values into an array.
12
+ */
13
+ export declare function objectFilter<K extends string | number | symbol, V>(object: ReadonlyRecord<K, V>, predicate: (value: V) => boolean): V[];
14
+ /**
15
+ * Helper function to convert an object to a map.
16
+ *
17
+ * This is useful when you need to construct a type safe object with the `satisfies` operator, but
18
+ * then later on you need to query it in a way where you expect the return value to be T or
19
+ * undefined. In this situation, by converting the object to a map, you can avoid unsafe type
20
+ * assertions.
21
+ *
22
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
23
+ * only having string keys under the hood.
24
+ *
25
+ * Also see the `objectToReadonlyMap` function.
26
+ */
27
+ export declare function objectToMap<K extends string | number | symbol, V>(object: Record<K, V>): Map<K, V>;
28
+ /**
29
+ * Helper function to convert an object to a read-only map.
30
+ *
31
+ * This is useful when you need to construct a type safe object with the `satisfies` operator, but
32
+ * then later on you need to query it in a way where you expect the return value to be T or
33
+ * undefined. In this situation, by converting the object to a map, you can avoid unsafe type
34
+ * assertions.
35
+ *
36
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
37
+ * only having string keys under the hood.
38
+ *
39
+ * Also see the `objectToMap` function.
40
+ */
41
+ export declare function objectToReadonlyMap<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlyMap<K, V>;
42
+ /**
43
+ * Helper function to convert an object to a reverse map.
44
+ *
45
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
46
+ * only having string keys under the hood.
47
+ *
48
+ * Also see the `objectToReverseReadonlyMap` function.
49
+ */
50
+ export declare function objectToReverseMap<K extends string | number | symbol, V extends string | number | symbol>(object: Record<K, V>): Map<V, K>;
51
+ /**
52
+ * Helper function to convert an object to a reverse read-only map.
53
+ *
54
+ * Note that the converted map will only have string keys, due to the nature of JavaScript objects
55
+ * only having string keys under the hood.
56
+ *
57
+ * Also see the `objectToReverseMap` function.
58
+ */
59
+ export declare function objectToReverseReadonlyMap<K extends string | number | symbol, V extends string | number | symbol>(object: Record<K, V>): ReadonlyMap<V, K>;
60
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/functions/object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;GAKG;AAEH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAChE,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAC/B,CAAC,EAAE,CAaL;AAED;;;;;;;;;;;;GAYG;AAEH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAC/D,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAQX;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EACvE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAEnB;AAED;;;;;;;GAOG;AAEH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAQjC;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAEzC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Helper functions that have to do with getting random values.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * This returns a random integer between min and max. It is inclusive on both ends.
8
+ *
9
+ * For example:
10
+ *
11
+ * ```ts
12
+ * const oneTwoOrThree = getRandomInt(1, 3);
13
+ * ```
14
+ *
15
+ * @param min The lower bound for the random number (inclusive).
16
+ * @param max The upper bound for the random number (inclusive).
17
+ * @param exceptions Optional. An array of elements that will be skipped over when getting the
18
+ * random integer. For example, a min of 1, a max of 4, and an exceptions array of
19
+ * `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
20
+ * array.
21
+ */
22
+ export declare function getRandomInt(min: number, max: number, exceptions?: readonly number[]): number;
23
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Helper functions that have to do with getting random values.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * This returns a random integer between min and max. It is inclusive on both ends.
8
+ *
9
+ * For example:
10
+ *
11
+ * ```ts
12
+ * const oneTwoOrThree = getRandomInt(1, 3);
13
+ * ```
14
+ *
15
+ * @param min The lower bound for the random number (inclusive).
16
+ * @param max The upper bound for the random number (inclusive).
17
+ * @param exceptions Optional. An array of elements that will be skipped over when getting the
18
+ * random integer. For example, a min of 1, a max of 4, and an exceptions array of
19
+ * `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
20
+ * array.
21
+ */
22
+ export declare function getRandomInt(min: number, max: number, exceptions?: readonly number[]): number;
23
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Helper functions that have to do with getting random values.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * This returns a random integer between min and max. It is inclusive on both ends.
8
+ *
9
+ * For example:
10
+ *
11
+ * ```ts
12
+ * const oneTwoOrThree = getRandomInt(1, 3);
13
+ * ```
14
+ *
15
+ * @param min The lower bound for the random number (inclusive).
16
+ * @param max The upper bound for the random number (inclusive).
17
+ * @param exceptions Optional. An array of elements that will be skipped over when getting the
18
+ * random integer. For example, a min of 1, a max of 4, and an exceptions array of
19
+ * `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
20
+ * array.
21
+ */
22
+ export declare function getRandomInt(min: number, max: number, exceptions?: readonly number[]): number;
23
+ //# sourceMappingURL=random.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/functions/random.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,SAAS,MAAM,EAAO,GACjC,MAAM,CAoBR"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Helper functions that have to do with
3
+ * [sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * Helper function to add all of the values in one set to another set. The first set passed will be
9
+ * modified in place.
10
+ *
11
+ * This function is variadic, meaning that you can specify N sets to add to the first set.
12
+ */
13
+ export declare function addSetsToSet<T>(mainSet: Set<T>, ...setsToAdd: ReadonlyArray<ReadonlySet<T>>): void;
14
+ /**
15
+ * Helper function to create a new set that is the composition of two or more sets.
16
+ *
17
+ * This function is variadic, meaning that you can specify N sets.
18
+ */
19
+ export declare function combineSets<T>(...sets: ReadonlyArray<ReadonlySet<T>>): Set<T>;
20
+ /** Helper function to copy a set. (You can also use a Set constructor to accomplish this task.) */
21
+ export declare function copySet<T>(oldSet: ReadonlySet<T>): Set<T>;
22
+ /**
23
+ * Helper function to convert the keys of an object to a read-only set.
24
+ *
25
+ * Also see the `objectKeysToSet` function.
26
+ */
27
+ export declare function objectKeysToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<K>;
28
+ /**
29
+ * Helper function to convert the keys of an object to a set.
30
+ *
31
+ * Also see the `objectKeysToReadonlySet` function.
32
+ */
33
+ export declare function objectKeysToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<K>;
34
+ /**
35
+ * Helper function to convert the values of an object to a read-only set.
36
+ *
37
+ * Also see the `objectValuesToSet` function.
38
+ */
39
+ export declare function objectValuesToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<V>;
40
+ /**
41
+ * Helper function to convert the values of an object to a set.
42
+ *
43
+ * Also see the `objectValuesToReadonlySet` function.
44
+ */
45
+ export declare function objectValuesToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<V>;
46
+ /**
47
+ * Helper function to add one or more elements to a set at once without having to repeatedly call
48
+ * the `Set.add` method.
49
+ *
50
+ * This function is variadic, meaning that you can pass as many things as you want to add.
51
+ */
52
+ export declare function setAdd<T>(set: Set<T>, ...elements: readonly T[]): void;
53
+ /**
54
+ * Helper function to check for one or more elements in a set at once without having to repeatedly
55
+ * call the `Set.has` method.
56
+ *
57
+ * This function is variadic, meaning that you can pass as many things as you want to check for. It
58
+ * will return true if one or more elements are found.
59
+ */
60
+ export declare function setHas<T>(set: ReadonlySet<T>, ...elements: readonly T[]): boolean;
61
+ //# sourceMappingURL=set.d.ts.map
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Helper functions that have to do with
3
+ * [sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * Helper function to add all of the values in one set to another set. The first set passed will be
9
+ * modified in place.
10
+ *
11
+ * This function is variadic, meaning that you can specify N sets to add to the first set.
12
+ */
13
+ export declare function addSetsToSet<T>(mainSet: Set<T>, ...setsToAdd: ReadonlyArray<ReadonlySet<T>>): void;
14
+ /**
15
+ * Helper function to create a new set that is the composition of two or more sets.
16
+ *
17
+ * This function is variadic, meaning that you can specify N sets.
18
+ */
19
+ export declare function combineSets<T>(...sets: ReadonlyArray<ReadonlySet<T>>): Set<T>;
20
+ /** Helper function to copy a set. (You can also use a Set constructor to accomplish this task.) */
21
+ export declare function copySet<T>(oldSet: ReadonlySet<T>): Set<T>;
22
+ /**
23
+ * Helper function to convert the keys of an object to a read-only set.
24
+ *
25
+ * Also see the `objectKeysToSet` function.
26
+ */
27
+ export declare function objectKeysToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<K>;
28
+ /**
29
+ * Helper function to convert the keys of an object to a set.
30
+ *
31
+ * Also see the `objectKeysToReadonlySet` function.
32
+ */
33
+ export declare function objectKeysToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<K>;
34
+ /**
35
+ * Helper function to convert the values of an object to a read-only set.
36
+ *
37
+ * Also see the `objectValuesToSet` function.
38
+ */
39
+ export declare function objectValuesToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<V>;
40
+ /**
41
+ * Helper function to convert the values of an object to a set.
42
+ *
43
+ * Also see the `objectValuesToReadonlySet` function.
44
+ */
45
+ export declare function objectValuesToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<V>;
46
+ /**
47
+ * Helper function to add one or more elements to a set at once without having to repeatedly call
48
+ * the `Set.add` method.
49
+ *
50
+ * This function is variadic, meaning that you can pass as many things as you want to add.
51
+ */
52
+ export declare function setAdd<T>(set: Set<T>, ...elements: readonly T[]): void;
53
+ /**
54
+ * Helper function to check for one or more elements in a set at once without having to repeatedly
55
+ * call the `Set.has` method.
56
+ *
57
+ * This function is variadic, meaning that you can pass as many things as you want to check for. It
58
+ * will return true if one or more elements are found.
59
+ */
60
+ export declare function setHas<T>(set: ReadonlySet<T>, ...elements: readonly T[]): boolean;
61
+ //# sourceMappingURL=set.d.ts.map
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Helper functions that have to do with
3
+ * [sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * Helper function to add all of the values in one set to another set. The first set passed will be
9
+ * modified in place.
10
+ *
11
+ * This function is variadic, meaning that you can specify N sets to add to the first set.
12
+ */
13
+ export declare function addSetsToSet<T>(mainSet: Set<T>, ...setsToAdd: ReadonlyArray<ReadonlySet<T>>): void;
14
+ /**
15
+ * Helper function to create a new set that is the composition of two or more sets.
16
+ *
17
+ * This function is variadic, meaning that you can specify N sets.
18
+ */
19
+ export declare function combineSets<T>(...sets: ReadonlyArray<ReadonlySet<T>>): Set<T>;
20
+ /** Helper function to copy a set. (You can also use a Set constructor to accomplish this task.) */
21
+ export declare function copySet<T>(oldSet: ReadonlySet<T>): Set<T>;
22
+ /**
23
+ * Helper function to convert the keys of an object to a read-only set.
24
+ *
25
+ * Also see the `objectKeysToSet` function.
26
+ */
27
+ export declare function objectKeysToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<K>;
28
+ /**
29
+ * Helper function to convert the keys of an object to a set.
30
+ *
31
+ * Also see the `objectKeysToReadonlySet` function.
32
+ */
33
+ export declare function objectKeysToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<K>;
34
+ /**
35
+ * Helper function to convert the values of an object to a read-only set.
36
+ *
37
+ * Also see the `objectValuesToSet` function.
38
+ */
39
+ export declare function objectValuesToReadonlySet<K extends string | number | symbol, V>(object: Record<K, V>): ReadonlySet<V>;
40
+ /**
41
+ * Helper function to convert the values of an object to a set.
42
+ *
43
+ * Also see the `objectValuesToReadonlySet` function.
44
+ */
45
+ export declare function objectValuesToSet<K extends string | number | symbol, V>(object: Record<K, V>): Set<V>;
46
+ /**
47
+ * Helper function to add one or more elements to a set at once without having to repeatedly call
48
+ * the `Set.add` method.
49
+ *
50
+ * This function is variadic, meaning that you can pass as many things as you want to add.
51
+ */
52
+ export declare function setAdd<T>(set: Set<T>, ...elements: readonly T[]): void;
53
+ /**
54
+ * Helper function to check for one or more elements in a set at once without having to repeatedly
55
+ * call the `Set.has` method.
56
+ *
57
+ * This function is variadic, meaning that you can pass as many things as you want to check for. It
58
+ * will return true if one or more elements are found.
59
+ */
60
+ export declare function setHas<T>(set: ReadonlySet<T>, ...elements: readonly T[]): boolean;
61
+ //# sourceMappingURL=set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../src/functions/set.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAE5B,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EACf,GAAG,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAC1C,IAAI,CAMN;AAED;;;;GAIG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAS7E;AAED,mGAAmG;AAEnG,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAOzD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAC3E,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,WAAW,CAAC,CAAC,CAAC,CAEhB;AAED;;;;GAIG;AAEH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EACnE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,GAAG,CAAC,CAAC,CAAC,CAQR;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,CAAC,EACD,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAEtC;AAED;;;;GAIG;AAEH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EACrE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,GAAG,CAAC,CAAC,CAAC,CAQR;AAED;;;;;GAKG;AAEH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,SAAS,CAAC,EAAE,GAAG,IAAI,CAItE;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,GAAG,QAAQ,EAAE,SAAS,CAAC,EAAE,GACxB,OAAO,CAET"}