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.
Files changed (151) 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 +22 -0
  12. package/dist/functions/assert.d.mts +22 -0
  13. package/dist/functions/assert.d.ts +22 -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 +52 -0
  20. package/dist/functions/map.d.mts +52 -0
  21. package/dist/functions/map.d.ts +52 -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 +14 -0
  28. package/dist/functions/object.d.mts +14 -0
  29. package/dist/functions/object.d.ts +14 -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/tuple.d.cts +27 -0
  52. package/dist/functions/tuple.d.mts +27 -0
  53. package/dist/functions/tuple.d.ts +27 -0
  54. package/dist/functions/tuple.d.ts.map +1 -0
  55. package/dist/functions/types.d.cts +13 -0
  56. package/dist/functions/types.d.mts +13 -0
  57. package/dist/functions/types.d.ts +13 -0
  58. package/dist/functions/types.d.ts.map +1 -0
  59. package/dist/functions/utils.d.cts +131 -0
  60. package/dist/functions/utils.d.mts +131 -0
  61. package/dist/functions/utils.d.ts +131 -0
  62. package/dist/functions/utils.d.ts.map +1 -0
  63. package/dist/functions/utils.test.d.cts +2 -0
  64. package/dist/functions/utils.test.d.mts +2 -0
  65. package/dist/functions/utils.test.d.ts +2 -0
  66. package/dist/functions/utils.test.d.ts.map +1 -0
  67. package/dist/index.cjs +66 -65
  68. package/dist/index.d.cts +29 -705
  69. package/dist/index.d.mts +29 -705
  70. package/dist/index.d.ts +29 -705
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.mjs +66 -65
  73. package/dist/types/AddSubtract.d.cts +23 -0
  74. package/dist/types/AddSubtract.d.mts +23 -0
  75. package/dist/types/AddSubtract.d.ts +23 -0
  76. package/dist/types/AddSubtract.d.ts.map +1 -0
  77. package/dist/types/CompositionTypeSatisfiesEnum.d.cts +35 -0
  78. package/dist/types/CompositionTypeSatisfiesEnum.d.mts +35 -0
  79. package/dist/types/CompositionTypeSatisfiesEnum.d.ts +35 -0
  80. package/dist/types/CompositionTypeSatisfiesEnum.d.ts.map +1 -0
  81. package/dist/types/ERange.d.cts +12 -0
  82. package/dist/types/ERange.d.mts +12 -0
  83. package/dist/types/ERange.d.ts +12 -0
  84. package/dist/types/ERange.d.ts.map +1 -0
  85. package/dist/types/IRange.d.cts +13 -0
  86. package/dist/types/IRange.d.mts +13 -0
  87. package/dist/types/IRange.d.ts +13 -0
  88. package/dist/types/IRange.d.ts.map +1 -0
  89. package/dist/types/Immutable.d.cts +17 -0
  90. package/dist/types/Immutable.d.mts +17 -0
  91. package/dist/types/Immutable.d.ts +17 -0
  92. package/dist/types/Immutable.d.ts.map +1 -0
  93. package/dist/types/NaturalNumbersLessThan.d.cts +8 -0
  94. package/dist/types/NaturalNumbersLessThan.d.mts +8 -0
  95. package/dist/types/NaturalNumbersLessThan.d.ts +8 -0
  96. package/dist/types/NaturalNumbersLessThan.d.ts.map +1 -0
  97. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.cts +8 -0
  98. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.mts +8 -0
  99. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.ts +8 -0
  100. package/dist/types/NaturalNumbersLessThanOrEqualTo.d.ts.map +1 -0
  101. package/dist/types/ObjectValues.d.cts +3 -0
  102. package/dist/types/ObjectValues.d.mts +3 -0
  103. package/dist/types/ObjectValues.d.ts +3 -0
  104. package/dist/types/ObjectValues.d.ts.map +1 -0
  105. package/dist/types/ReadonlyMap.d.cts +9 -0
  106. package/dist/types/ReadonlyMap.d.mts +9 -0
  107. package/dist/types/ReadonlyMap.d.ts +9 -0
  108. package/dist/types/ReadonlyMap.d.ts.map +1 -0
  109. package/dist/types/ReadonlyRecord.d.cts +7 -0
  110. package/dist/types/ReadonlyRecord.d.mts +7 -0
  111. package/dist/types/ReadonlyRecord.d.ts +7 -0
  112. package/dist/types/ReadonlyRecord.d.ts.map +1 -0
  113. package/dist/types/ReadonlySet.d.cts +8 -0
  114. package/dist/types/ReadonlySet.d.mts +8 -0
  115. package/dist/types/ReadonlySet.d.ts +8 -0
  116. package/dist/types/ReadonlySet.d.ts.map +1 -0
  117. package/dist/types/Tuple.d.cts +10 -0
  118. package/dist/types/Tuple.d.mts +10 -0
  119. package/dist/types/Tuple.d.ts +10 -0
  120. package/dist/types/Tuple.d.ts.map +1 -0
  121. package/dist/types/WidenLiteral.d.cts +3 -0
  122. package/dist/types/WidenLiteral.d.mts +3 -0
  123. package/dist/types/WidenLiteral.d.ts +3 -0
  124. package/dist/types/WidenLiteral.d.ts.map +1 -0
  125. package/dist/types/Writeable.d.cts +9 -0
  126. package/dist/types/Writeable.d.mts +9 -0
  127. package/dist/types/Writeable.d.ts +9 -0
  128. package/dist/types/Writeable.d.ts.map +1 -0
  129. package/package.json +12 -2
  130. package/src/constants.ts +5 -0
  131. package/src/functions/array.ts +8 -2
  132. package/src/functions/assert.ts +41 -0
  133. package/src/functions/enums.ts +6 -0
  134. package/src/functions/map.ts +7 -0
  135. package/src/functions/math.ts +6 -0
  136. package/src/functions/object.ts +8 -3
  137. package/src/functions/random.ts +6 -0
  138. package/src/functions/set.ts +7 -0
  139. package/src/functions/sort.ts +6 -0
  140. package/src/functions/string.ts +25 -0
  141. package/src/functions/tuple.ts +6 -0
  142. package/src/functions/types.ts +6 -0
  143. package/src/functions/utils.test.ts +2 -8
  144. package/src/functions/utils.ts +7 -37
  145. package/src/index.ts +13 -12
  146. package/src/types/AddSubtract.ts +10 -2
  147. package/src/types/CompositionTypeSatisfiesEnum.ts +5 -3
  148. package/src/types/ObjectValues.ts +1 -0
  149. package/src/types/ReadonlyRecord.ts +5 -0
  150. package/src/types/Tuple.ts +1 -0
  151. package/src/types/WidenLiteral.ts +1 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Helper functions that have to do with strings.
3
+ *
4
+ * @module
5
+ */
6
+ /** Helper function to capitalize the first letter of a string. */
7
+ export declare function capitalizeFirstLetter(string: string): string;
8
+ /**
9
+ * Helper function to replace all of the ampersands, less than signs, greater than signs, double
10
+ * quotes, and single quotes in a string with the escaped counterparts. For example, "<" will be
11
+ * replaced with "&lt;".
12
+ */
13
+ export declare function escapeHTMLCharacters(string: string): string;
14
+ /**
15
+ * Helper function to get the number of consecutive diacritics in a string.
16
+ *
17
+ * This is useful for sanitization purposes, since many subsequent diacritics can be a sign of a
18
+ * malicious string.
19
+ */
20
+ export declare function getNumConsecutiveDiacritics(string: string): number;
21
+ /** Helper function to check if a string has one or more diacritics in it. */
22
+ export declare function hasDiacritic(string: string): boolean;
23
+ /**
24
+ * Helper function to check if a string has one or more emoji in it.
25
+ *
26
+ * Under the hood, this uses the same regex check as the Zod library.
27
+ */
28
+ export declare function hasEmoji(string: string): boolean;
29
+ /** From: https://stackoverflow.com/questions/1731190/check-if-a-string-has-white-space */
30
+ export declare function hasWhitespace(string: string): boolean;
31
+ /**
32
+ * From:
33
+ * https://stackoverflow.com/questions/8334606/check-if-first-letter-of-word-is-a-capital-letter
34
+ */
35
+ export declare function isFirstLetterCapitalized(string: string): boolean;
36
+ /** Kebab case is the naming style of using all lowercase and hyphens, like "foo-bar". */
37
+ export declare function isKebabCase(string: string): boolean;
38
+ /**
39
+ * Helper function to check if a given string is a valid Semantic Version.
40
+ *
41
+ * @see https://semver.org/
42
+ */
43
+ export declare function isSemanticVersion(versionString: string): boolean;
44
+ /** Helper function to convert a string from kebab-case to camel-case. */
45
+ export declare function kebabCaseToCamelCase(string: string): string;
46
+ /**
47
+ * Helper function to normalize a string. Specifically, this performs the following steps:
48
+ *
49
+ * - Removes any non-printable characters, if any.
50
+ * - Normalizes all newlines to "\n".
51
+ * - Normalizes all spaces to " ".
52
+ * - Removes leading/trailing whitespace.
53
+ *
54
+ * @see
55
+ * https://stackoverflow.com/questions/11598786/how-to-replace-non-printable-unicode-characters-javascript
56
+ */
57
+ export declare function normalizeString(string: string): string;
58
+ /**
59
+ * Helper function to parse a Semantic Versioning string into its individual constituents. Returns
60
+ * undefined if the submitted string was not a proper Semantic Version.
61
+ *
62
+ * @see https://semver.org/
63
+ */
64
+ export declare function parseSemanticVersion(versionString: string): {
65
+ /** The first number inside of the semantic version. */
66
+ majorVersion: number;
67
+ /** The second number inside of the semantic version. */
68
+ minorVersion: number;
69
+ /** The third number inside of the semantic version. */
70
+ patchVersion: number;
71
+ } | undefined;
72
+ /**
73
+ * Helper function to remove lines from a multi-line string. This function looks for a "-start" and
74
+ * a "-end" suffix after the marker. Lines with markets will be completely removed from the output.
75
+ *
76
+ * For example, by using a marker of "@foo":
77
+ *
78
+ * ```text
79
+ * line1
80
+ * # @foo-start
81
+ * line2
82
+ * line3
83
+ * # @foo-end
84
+ * line4
85
+ * ```
86
+ *
87
+ * Would return:
88
+ *
89
+ * ```text
90
+ * line1
91
+ * line4
92
+ * ```
93
+ */
94
+ export declare function removeLinesBetweenMarkers(string: string, marker: string): string;
95
+ /** Helper function to remove lines from a multi-line string matching a certain other string. */
96
+ export declare function removeLinesMatching(string: string, match: string): string;
97
+ /**
98
+ * Helper function to remove all non-printable characters from a string.
99
+ *
100
+ * @see
101
+ * https://stackoverflow.com/questions/11598786/how-to-replace-non-printable-unicode-characters-javascript
102
+ */
103
+ export declare function removeNonPrintableCharacters(string: string): string;
104
+ /** Helper function to remove all whitespace characters from a string. */
105
+ export declare function removeWhitespace(string: string): string;
106
+ /**
107
+ * Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
108
+ *
109
+ * @param string The string to trim.
110
+ * @param prefix The prefix to trim.
111
+ * @param trimAll Whether to remove multiple instances of the prefix, if they exist. If this is set
112
+ * to true, the prefix must only be a single character.
113
+ */
114
+ export declare function trimPrefix(string: string, prefix: string, trimAll?: boolean): string;
115
+ /** Helper function to trim a suffix from a string, if it exists. Returns the trimmed string. */
116
+ export declare function trimSuffix(string: string, prefix: string): string;
117
+ /**
118
+ * Helper function to truncate a string to a maximum length. If the length of the string is less
119
+ * than or equal to the provided maximum length, the string will be returned unmodified.
120
+ */
121
+ export declare function truncateString(string: string, maxLength: number): string;
122
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Helper functions that have to do with strings.
3
+ *
4
+ * @module
5
+ */
6
+ /** Helper function to capitalize the first letter of a string. */
7
+ export declare function capitalizeFirstLetter(string: string): string;
8
+ /**
9
+ * Helper function to replace all of the ampersands, less than signs, greater than signs, double
10
+ * quotes, and single quotes in a string with the escaped counterparts. For example, "<" will be
11
+ * replaced with "&lt;".
12
+ */
13
+ export declare function escapeHTMLCharacters(string: string): string;
14
+ /**
15
+ * Helper function to get the number of consecutive diacritics in a string.
16
+ *
17
+ * This is useful for sanitization purposes, since many subsequent diacritics can be a sign of a
18
+ * malicious string.
19
+ */
20
+ export declare function getNumConsecutiveDiacritics(string: string): number;
21
+ /** Helper function to check if a string has one or more diacritics in it. */
22
+ export declare function hasDiacritic(string: string): boolean;
23
+ /**
24
+ * Helper function to check if a string has one or more emoji in it.
25
+ *
26
+ * Under the hood, this uses the same regex check as the Zod library.
27
+ */
28
+ export declare function hasEmoji(string: string): boolean;
29
+ /** From: https://stackoverflow.com/questions/1731190/check-if-a-string-has-white-space */
30
+ export declare function hasWhitespace(string: string): boolean;
31
+ /**
32
+ * From:
33
+ * https://stackoverflow.com/questions/8334606/check-if-first-letter-of-word-is-a-capital-letter
34
+ */
35
+ export declare function isFirstLetterCapitalized(string: string): boolean;
36
+ /** Kebab case is the naming style of using all lowercase and hyphens, like "foo-bar". */
37
+ export declare function isKebabCase(string: string): boolean;
38
+ /**
39
+ * Helper function to check if a given string is a valid Semantic Version.
40
+ *
41
+ * @see https://semver.org/
42
+ */
43
+ export declare function isSemanticVersion(versionString: string): boolean;
44
+ /** Helper function to convert a string from kebab-case to camel-case. */
45
+ export declare function kebabCaseToCamelCase(string: string): string;
46
+ /**
47
+ * Helper function to normalize a string. Specifically, this performs the following steps:
48
+ *
49
+ * - Removes any non-printable characters, if any.
50
+ * - Normalizes all newlines to "\n".
51
+ * - Normalizes all spaces to " ".
52
+ * - Removes leading/trailing whitespace.
53
+ *
54
+ * @see
55
+ * https://stackoverflow.com/questions/11598786/how-to-replace-non-printable-unicode-characters-javascript
56
+ */
57
+ export declare function normalizeString(string: string): string;
58
+ /**
59
+ * Helper function to parse a Semantic Versioning string into its individual constituents. Returns
60
+ * undefined if the submitted string was not a proper Semantic Version.
61
+ *
62
+ * @see https://semver.org/
63
+ */
64
+ export declare function parseSemanticVersion(versionString: string): {
65
+ /** The first number inside of the semantic version. */
66
+ majorVersion: number;
67
+ /** The second number inside of the semantic version. */
68
+ minorVersion: number;
69
+ /** The third number inside of the semantic version. */
70
+ patchVersion: number;
71
+ } | undefined;
72
+ /**
73
+ * Helper function to remove lines from a multi-line string. This function looks for a "-start" and
74
+ * a "-end" suffix after the marker. Lines with markets will be completely removed from the output.
75
+ *
76
+ * For example, by using a marker of "@foo":
77
+ *
78
+ * ```text
79
+ * line1
80
+ * # @foo-start
81
+ * line2
82
+ * line3
83
+ * # @foo-end
84
+ * line4
85
+ * ```
86
+ *
87
+ * Would return:
88
+ *
89
+ * ```text
90
+ * line1
91
+ * line4
92
+ * ```
93
+ */
94
+ export declare function removeLinesBetweenMarkers(string: string, marker: string): string;
95
+ /** Helper function to remove lines from a multi-line string matching a certain other string. */
96
+ export declare function removeLinesMatching(string: string, match: string): string;
97
+ /**
98
+ * Helper function to remove all non-printable characters from a string.
99
+ *
100
+ * @see
101
+ * https://stackoverflow.com/questions/11598786/how-to-replace-non-printable-unicode-characters-javascript
102
+ */
103
+ export declare function removeNonPrintableCharacters(string: string): string;
104
+ /** Helper function to remove all whitespace characters from a string. */
105
+ export declare function removeWhitespace(string: string): string;
106
+ /**
107
+ * Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
108
+ *
109
+ * @param string The string to trim.
110
+ * @param prefix The prefix to trim.
111
+ * @param trimAll Whether to remove multiple instances of the prefix, if they exist. If this is set
112
+ * to true, the prefix must only be a single character.
113
+ */
114
+ export declare function trimPrefix(string: string, prefix: string, trimAll?: boolean): string;
115
+ /** Helper function to trim a suffix from a string, if it exists. Returns the trimmed string. */
116
+ export declare function trimSuffix(string: string, prefix: string): string;
117
+ /**
118
+ * Helper function to truncate a string to a maximum length. If the length of the string is less
119
+ * than or equal to the provided maximum length, the string will be returned unmodified.
120
+ */
121
+ export declare function truncateString(string: string, maxLength: number): string;
122
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqBH,kEAAkE;AAClE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAqBlE;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAGhE;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBtD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GACtD;IACE,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IAErB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IAErB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACtB,GACD,SAAS,CAwBZ;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,MAAM,CAuBR;AAED,gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIzE;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,UAAQ,GACd,MAAM,CAWR;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMxE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=string.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=string.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=string.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.test.d.ts","sourceRoot":"","sources":["../../src/functions/string.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Helper functions that have to do with TypeScript tuples.
3
+ *
4
+ * @module
5
+ */
6
+ import type { Tuple } from "../types/Tuple.js";
7
+ type TupleKey<T extends readonly unknown[]> = {
8
+ [L in T["length"]]: Exclude<Partial<Tuple<unknown, L>>["length"], L>;
9
+ }[T["length"]];
10
+ type TupleValue<T extends readonly unknown[]> = T[0];
11
+ type TupleEntry<T extends readonly unknown[]> = [TupleKey<T>, TupleValue<T>];
12
+ /**
13
+ * Helper function to get the entries (i.e. indexes and values) of a tuple in a type-safe way.
14
+ *
15
+ * This is useful because the vanilla `Array.entries` method will always have the keys be of type
16
+ * `number`.
17
+ */
18
+ export declare function tupleEntries<T extends readonly unknown[]>(tuple: T): Generator<TupleEntry<T>>;
19
+ /**
20
+ * Helper function to get the keys (i.e. indexes) of a tuple in a type-safe way.
21
+ *
22
+ * This is useful because the vanilla `Array.keys` method will always have the keys be of type
23
+ * `number`.
24
+ */
25
+ export declare function tupleKeys<T extends readonly unknown[]>(tuple: T): Generator<TupleKey<T>>;
26
+ export {};
27
+ //# sourceMappingURL=tuple.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Helper functions that have to do with TypeScript tuples.
3
+ *
4
+ * @module
5
+ */
6
+ import type { Tuple } from "../types/Tuple.js";
7
+ type TupleKey<T extends readonly unknown[]> = {
8
+ [L in T["length"]]: Exclude<Partial<Tuple<unknown, L>>["length"], L>;
9
+ }[T["length"]];
10
+ type TupleValue<T extends readonly unknown[]> = T[0];
11
+ type TupleEntry<T extends readonly unknown[]> = [TupleKey<T>, TupleValue<T>];
12
+ /**
13
+ * Helper function to get the entries (i.e. indexes and values) of a tuple in a type-safe way.
14
+ *
15
+ * This is useful because the vanilla `Array.entries` method will always have the keys be of type
16
+ * `number`.
17
+ */
18
+ export declare function tupleEntries<T extends readonly unknown[]>(tuple: T): Generator<TupleEntry<T>>;
19
+ /**
20
+ * Helper function to get the keys (i.e. indexes) of a tuple in a type-safe way.
21
+ *
22
+ * This is useful because the vanilla `Array.keys` method will always have the keys be of type
23
+ * `number`.
24
+ */
25
+ export declare function tupleKeys<T extends readonly unknown[]>(tuple: T): Generator<TupleKey<T>>;
26
+ export {};
27
+ //# sourceMappingURL=tuple.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Helper functions that have to do with TypeScript tuples.
3
+ *
4
+ * @module
5
+ */
6
+ import type { Tuple } from "../types/Tuple.js";
7
+ type TupleKey<T extends readonly unknown[]> = {
8
+ [L in T["length"]]: Exclude<Partial<Tuple<unknown, L>>["length"], L>;
9
+ }[T["length"]];
10
+ type TupleValue<T extends readonly unknown[]> = T[0];
11
+ type TupleEntry<T extends readonly unknown[]> = [TupleKey<T>, TupleValue<T>];
12
+ /**
13
+ * Helper function to get the entries (i.e. indexes and values) of a tuple in a type-safe way.
14
+ *
15
+ * This is useful because the vanilla `Array.entries` method will always have the keys be of type
16
+ * `number`.
17
+ */
18
+ export declare function tupleEntries<T extends readonly unknown[]>(tuple: T): Generator<TupleEntry<T>>;
19
+ /**
20
+ * Helper function to get the keys (i.e. indexes) of a tuple in a type-safe way.
21
+ *
22
+ * This is useful because the vanilla `Array.keys` method will always have the keys be of type
23
+ * `number`.
24
+ */
25
+ export declare function tupleKeys<T extends readonly unknown[]>(tuple: T): Generator<TupleKey<T>>;
26
+ export {};
27
+ //# sourceMappingURL=tuple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../../src/functions/tuple.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,KAAK,QAAQ,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,IAAI;KAC3C,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;CACrE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AACf,KAAK,UAAU,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,KAAK,UAAU,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E;;;;;GAKG;AACH,wBAAiB,YAAY,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EACxD,KAAK,EAAE,CAAC,GACP,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAE1B;AAED;;;;;GAKG;AACH,wBAAiB,SAAS,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EACrD,KAAK,EAAE,CAAC,GACP,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAExB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Identity functions that help with narrowing.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to narrow an unknown value to an object (i.e. a TypeScript record).
8
+ *
9
+ * Under the hood, this checks for `typeof variable === "object"`, `variable !== null`, and
10
+ * `!Array.isArray(variable)`.
11
+ */
12
+ export declare function isObject(variable: unknown): variable is Record<string, unknown>;
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Identity functions that help with narrowing.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to narrow an unknown value to an object (i.e. a TypeScript record).
8
+ *
9
+ * Under the hood, this checks for `typeof variable === "object"`, `variable !== null`, and
10
+ * `!Array.isArray(variable)`.
11
+ */
12
+ export declare function isObject(variable: unknown): variable is Record<string, unknown>;
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Identity functions that help with narrowing.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to narrow an unknown value to an object (i.e. a TypeScript record).
8
+ *
9
+ * Under the hood, this checks for `typeof variable === "object"`, `variable !== null`, and
10
+ * `!Array.isArray(variable)`.
11
+ */
12
+ export declare function isObject(variable: unknown): variable is Record<string, unknown>;
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMrC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Helper functions that do not belong to any category in particular.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to get an iterator of integers with the specified range, inclusive on the lower
8
+ * end and exclusive on the high end. (The "e" in the function name stands for exclusive.) Thus,
9
+ * this function works in the same way as the built-in `range` function from Python.
10
+ *
11
+ * If the end is lower than the start, then an empty range will be returned.
12
+ *
13
+ * For example:
14
+ *
15
+ * - `eRange(2)` returns `[0, 1]`.
16
+ * - `eRange(3)` returns `[0, 1, 2]`.
17
+ * - `eRange(-3)` returns `[0, -1, -2]`.
18
+ * - `eRange(1, 3)` returns `[1, 2]`.
19
+ * - `eRange(2, 5)` returns `[2, 3, 4]`.
20
+ * - `eRange(5, 2)` returns `[]`.
21
+ * - `eRange(3, 3)` returns `[]`.
22
+ *
23
+ * If you want an array instead of an iterator, use the spread operator like this:
24
+ *
25
+ * ```ts
26
+ * const myArray = [...eRange(1, 3)];
27
+ * ```
28
+ *
29
+ * @param start The integer to start at.
30
+ * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
31
+ * first argument will be the end.
32
+ * @param increment Optional. The increment to use. Default is 1.
33
+ */
34
+ export declare function eRange(start: number, end?: number, increment?: number): Generator<number>;
35
+ /**
36
+ * Helper function to get an array of integers with the specified range, inclusive on both ends.
37
+ * (The "i" in the function name stands for inclusive.)
38
+ *
39
+ * If the end is lower than the start, then an empty range will be returned.
40
+ *
41
+ * For example:
42
+ *
43
+ * - `iRange(2)` returns `[0, 1, 2]`.
44
+ * - `iRange(3)` returns `[0, 1, 2, 3]`.
45
+ * - `iRange(-3)` returns `[0, -1, -2, -3]`.
46
+ * - `iRange(1, 3)` returns `[1, 2, 3]`.
47
+ * - `iRange(2, 5)` returns `[2, 3, 4, 5]`.
48
+ * - `iRange(5, 2)` returns `[]`.
49
+ * - `iRange(3, 3)` returns `[3]`.
50
+ *
51
+ * If you want an array instead of an iterator, use the spread operator like this:
52
+ *
53
+ * ```ts
54
+ * const myArray = [...iRange(1, 3)];
55
+ * ```
56
+ *
57
+ * @param start The integer to start at.
58
+ * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
59
+ * first argument will be the end.
60
+ * @param increment Optional. The increment to use. Default is 1.
61
+ */
62
+ export declare function iRange(start: number, end?: number, increment?: number): Generator<number>;
63
+ /** From: https://stackoverflow.com/questions/61526746 */
64
+ export declare function isKeyOf<T extends object>(key: PropertyKey, target: T): key is keyof T;
65
+ /**
66
+ * Helper function to perform a no-op. This can be useful in order to make a trailing return valid
67
+ * in functions that use the early return pattern.
68
+ */
69
+ export declare function noop(): void;
70
+ /**
71
+ * This is a more reliable version of `Number.parseFloat`:
72
+ *
73
+ * - `undefined` is returned instead of `Number.NaN`, which is helpful in conjunction with
74
+ * TypeScript type narrowing patterns.
75
+ * - Strings that are a mixture of numbers and letters will result in undefined instead of the part
76
+ * of the string that is the number. (e.g. "1a" --> undefined instead of "1a" --> 1)
77
+ * - Non-strings will result in undefined instead of being coerced to a number.
78
+ *
79
+ * @param string A string to convert to an integer.
80
+ */
81
+ export declare function parseFloatSafe(string: string): number | undefined;
82
+ /**
83
+ * This is a more reliable version of `Number.parseInt`:
84
+ *
85
+ * - `undefined` is returned instead of `Number.NaN`, which is helpful in conjunction with
86
+ * TypeScript type narrowing patterns.
87
+ * - Strings that are a mixture of numbers and letters will result in undefined instead of the part
88
+ * of the string that is the number. (e.g. "1a" --> undefined instead of "1a" --> 1)
89
+ * - Non-strings will result in undefined instead of being coerced to a number.
90
+ *
91
+ * If you have to use a radix other than 10, use the vanilla `Number.parseInt` function instead,
92
+ * because this function ensures that the string contains no letters.
93
+ */
94
+ export declare function parseIntSafe(string: string): number | undefined;
95
+ /**
96
+ * Helper function to repeat code N times. This is faster to type and cleaner than using a for loop.
97
+ *
98
+ * For example:
99
+ *
100
+ * ```ts
101
+ * repeat(10, () => {
102
+ * foo();
103
+ * });
104
+ * ```
105
+ *
106
+ * The repeated function is passed the index of the iteration, if needed:
107
+ *
108
+ * ```ts
109
+ * repeat(3, (i) => {
110
+ * console.log(i); // Prints "0", "1", "2"
111
+ * });
112
+ * ```
113
+ */
114
+ export declare function repeat(num: number, func: (i: number) => void): void;
115
+ /**
116
+ * Helper function to signify that the enclosing code block is not yet complete. Using this function
117
+ * is similar to writing a "TODO" comment, but it has the benefit of preventing ESLint errors due to
118
+ * unused variables or early returns.
119
+ *
120
+ * When you see this function, it simply means that the programmer intends to add in more code to
121
+ * this spot later.
122
+ *
123
+ * This function is variadic, meaning that you can pass as many arguments as you want. (This is
124
+ * useful as a means to prevent unused variables.)
125
+ *
126
+ * This function does not actually do anything. (It is an "empty" function.)
127
+ *
128
+ * @allowEmptyVariadic
129
+ */
130
+ export declare function todo(...args: readonly unknown[]): void;
131
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Helper functions that do not belong to any category in particular.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Helper function to get an iterator of integers with the specified range, inclusive on the lower
8
+ * end and exclusive on the high end. (The "e" in the function name stands for exclusive.) Thus,
9
+ * this function works in the same way as the built-in `range` function from Python.
10
+ *
11
+ * If the end is lower than the start, then an empty range will be returned.
12
+ *
13
+ * For example:
14
+ *
15
+ * - `eRange(2)` returns `[0, 1]`.
16
+ * - `eRange(3)` returns `[0, 1, 2]`.
17
+ * - `eRange(-3)` returns `[0, -1, -2]`.
18
+ * - `eRange(1, 3)` returns `[1, 2]`.
19
+ * - `eRange(2, 5)` returns `[2, 3, 4]`.
20
+ * - `eRange(5, 2)` returns `[]`.
21
+ * - `eRange(3, 3)` returns `[]`.
22
+ *
23
+ * If you want an array instead of an iterator, use the spread operator like this:
24
+ *
25
+ * ```ts
26
+ * const myArray = [...eRange(1, 3)];
27
+ * ```
28
+ *
29
+ * @param start The integer to start at.
30
+ * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
31
+ * first argument will be the end.
32
+ * @param increment Optional. The increment to use. Default is 1.
33
+ */
34
+ export declare function eRange(start: number, end?: number, increment?: number): Generator<number>;
35
+ /**
36
+ * Helper function to get an array of integers with the specified range, inclusive on both ends.
37
+ * (The "i" in the function name stands for inclusive.)
38
+ *
39
+ * If the end is lower than the start, then an empty range will be returned.
40
+ *
41
+ * For example:
42
+ *
43
+ * - `iRange(2)` returns `[0, 1, 2]`.
44
+ * - `iRange(3)` returns `[0, 1, 2, 3]`.
45
+ * - `iRange(-3)` returns `[0, -1, -2, -3]`.
46
+ * - `iRange(1, 3)` returns `[1, 2, 3]`.
47
+ * - `iRange(2, 5)` returns `[2, 3, 4, 5]`.
48
+ * - `iRange(5, 2)` returns `[]`.
49
+ * - `iRange(3, 3)` returns `[3]`.
50
+ *
51
+ * If you want an array instead of an iterator, use the spread operator like this:
52
+ *
53
+ * ```ts
54
+ * const myArray = [...iRange(1, 3)];
55
+ * ```
56
+ *
57
+ * @param start The integer to start at.
58
+ * @param end Optional. The integer to end at. If not specified, then the start will be 0 and the
59
+ * first argument will be the end.
60
+ * @param increment Optional. The increment to use. Default is 1.
61
+ */
62
+ export declare function iRange(start: number, end?: number, increment?: number): Generator<number>;
63
+ /** From: https://stackoverflow.com/questions/61526746 */
64
+ export declare function isKeyOf<T extends object>(key: PropertyKey, target: T): key is keyof T;
65
+ /**
66
+ * Helper function to perform a no-op. This can be useful in order to make a trailing return valid
67
+ * in functions that use the early return pattern.
68
+ */
69
+ export declare function noop(): void;
70
+ /**
71
+ * This is a more reliable version of `Number.parseFloat`:
72
+ *
73
+ * - `undefined` is returned instead of `Number.NaN`, which is helpful in conjunction with
74
+ * TypeScript type narrowing patterns.
75
+ * - Strings that are a mixture of numbers and letters will result in undefined instead of the part
76
+ * of the string that is the number. (e.g. "1a" --> undefined instead of "1a" --> 1)
77
+ * - Non-strings will result in undefined instead of being coerced to a number.
78
+ *
79
+ * @param string A string to convert to an integer.
80
+ */
81
+ export declare function parseFloatSafe(string: string): number | undefined;
82
+ /**
83
+ * This is a more reliable version of `Number.parseInt`:
84
+ *
85
+ * - `undefined` is returned instead of `Number.NaN`, which is helpful in conjunction with
86
+ * TypeScript type narrowing patterns.
87
+ * - Strings that are a mixture of numbers and letters will result in undefined instead of the part
88
+ * of the string that is the number. (e.g. "1a" --> undefined instead of "1a" --> 1)
89
+ * - Non-strings will result in undefined instead of being coerced to a number.
90
+ *
91
+ * If you have to use a radix other than 10, use the vanilla `Number.parseInt` function instead,
92
+ * because this function ensures that the string contains no letters.
93
+ */
94
+ export declare function parseIntSafe(string: string): number | undefined;
95
+ /**
96
+ * Helper function to repeat code N times. This is faster to type and cleaner than using a for loop.
97
+ *
98
+ * For example:
99
+ *
100
+ * ```ts
101
+ * repeat(10, () => {
102
+ * foo();
103
+ * });
104
+ * ```
105
+ *
106
+ * The repeated function is passed the index of the iteration, if needed:
107
+ *
108
+ * ```ts
109
+ * repeat(3, (i) => {
110
+ * console.log(i); // Prints "0", "1", "2"
111
+ * });
112
+ * ```
113
+ */
114
+ export declare function repeat(num: number, func: (i: number) => void): void;
115
+ /**
116
+ * Helper function to signify that the enclosing code block is not yet complete. Using this function
117
+ * is similar to writing a "TODO" comment, but it has the benefit of preventing ESLint errors due to
118
+ * unused variables or early returns.
119
+ *
120
+ * When you see this function, it simply means that the programmer intends to add in more code to
121
+ * this spot later.
122
+ *
123
+ * This function is variadic, meaning that you can pass as many arguments as you want. (This is
124
+ * useful as a means to prevent unused variables.)
125
+ *
126
+ * This function does not actually do anything. (It is an "empty" function.)
127
+ *
128
+ * @allowEmptyVariadic
129
+ */
130
+ export declare function todo(...args: readonly unknown[]): void;
131
+ //# sourceMappingURL=utils.d.ts.map