@augment-vir/common 30.0.0 → 30.0.2

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 (174) hide show
  1. package/README.md +11 -0
  2. package/dist/augments/array/array-map.d.ts +29 -1
  3. package/dist/augments/array/array-map.js +29 -1
  4. package/dist/augments/array/array-to-object.d.ts +27 -9
  5. package/dist/augments/array/array-to-object.js +96 -12
  6. package/dist/augments/array/awaited/awaited-filter.d.ts +29 -0
  7. package/dist/augments/array/awaited/awaited-filter.js +29 -0
  8. package/dist/augments/array/awaited/awaited-for-each.d.ts +28 -3
  9. package/dist/augments/array/awaited/awaited-for-each.js +28 -3
  10. package/dist/augments/array/awaited/awaited-map.d.ts +32 -0
  11. package/dist/augments/array/awaited/awaited-map.js +32 -0
  12. package/dist/augments/array/filter.d.ts +29 -0
  13. package/dist/augments/array/filter.js +61 -0
  14. package/dist/augments/array/remove-duplicates.d.ts +60 -1
  15. package/dist/augments/array/remove-duplicates.js +61 -2
  16. package/dist/augments/array/repeat-array.d.ts +22 -0
  17. package/dist/augments/array/repeat-array.js +22 -0
  18. package/dist/augments/array/shuffle-array.d.ts +8 -1
  19. package/dist/augments/array/shuffle-array.js +8 -1
  20. package/dist/augments/array/string-array.d.ts +8 -0
  21. package/dist/augments/array/string-array.js +8 -0
  22. package/dist/augments/enum/enum-value-check.d.ts +30 -0
  23. package/dist/augments/enum/enum-value-check.js +30 -0
  24. package/dist/augments/error/combine-errors.d.ts +24 -3
  25. package/dist/augments/error/combine-errors.js +26 -4
  26. package/dist/augments/function/call-asynchronously.d.ts +19 -0
  27. package/dist/augments/function/call-asynchronously.js +19 -0
  28. package/dist/augments/function/call-with-retries.d.ts +23 -3
  29. package/dist/augments/function/call-with-retries.js +23 -0
  30. package/dist/augments/function/debounce.d.ts +71 -4
  31. package/dist/augments/function/debounce.js +66 -4
  32. package/dist/augments/function/execution-duration.d.ts +17 -5
  33. package/dist/augments/function/execution-duration.js +16 -3
  34. package/dist/augments/function/if-truthy.d.ts +28 -0
  35. package/dist/augments/function/if-truthy.js +35 -0
  36. package/dist/augments/function/wrap-in-try.d.ts +12 -4
  37. package/dist/augments/function/wrap-in-try.js +64 -0
  38. package/dist/augments/json/append-json.d.ts +3 -3
  39. package/dist/augments/json/append-json.js +33 -0
  40. package/dist/augments/json/copy-through-json.d.ts +32 -1
  41. package/dist/augments/json/copy-through-json.js +32 -1
  42. package/dist/augments/json/json-compatible.d.ts +37 -9
  43. package/dist/augments/json/jsonify.d.ts +30 -1
  44. package/dist/augments/json/jsonify.js +31 -2
  45. package/dist/augments/log/log-colors.d.ts +41 -0
  46. package/dist/augments/log/log-colors.js +43 -2
  47. package/dist/augments/log/log-string.d.ts +21 -0
  48. package/dist/augments/log/log-string.js +9 -2
  49. package/dist/augments/log/log-writer.d.ts +22 -0
  50. package/dist/augments/log/log.d.ts +44 -1
  51. package/dist/augments/log/log.js +46 -3
  52. package/dist/augments/log/logger.d.ts +49 -0
  53. package/dist/augments/log/logger.js +21 -0
  54. package/dist/augments/number/clamp.d.ts +13 -2
  55. package/dist/augments/number/clamp.js +12 -1
  56. package/dist/augments/number/coords.d.ts +6 -2
  57. package/dist/augments/number/digit.d.ts +7 -0
  58. package/dist/augments/number/dimensions.d.ts +6 -2
  59. package/dist/augments/number/min-max.d.ts +9 -2
  60. package/dist/augments/number/min-max.js +4 -2
  61. package/dist/augments/number/number-conversion.d.ts +9 -3
  62. package/dist/augments/number/number-conversion.js +10 -4
  63. package/dist/augments/number/round.d.ts +19 -0
  64. package/dist/augments/number/round.js +19 -0
  65. package/dist/augments/number/scientific.d.ts +18 -1
  66. package/dist/augments/number/scientific.js +18 -1
  67. package/dist/augments/number/truncate-number.d.ts +24 -3
  68. package/dist/augments/number/truncate-number.js +28 -8
  69. package/dist/augments/number/wrap-number.d.ts +9 -3
  70. package/dist/augments/number/wrap-number.js +8 -2
  71. package/dist/augments/object/diff.d.ts +27 -5
  72. package/dist/augments/object/diff.js +20 -4
  73. package/dist/augments/object/empty.d.ts +7 -1
  74. package/dist/augments/object/get-or-set.d.ts +6 -27
  75. package/dist/augments/object/get-or-set.js +66 -4
  76. package/dist/augments/object/key-count.d.ts +4 -0
  77. package/dist/augments/object/map-entries.js +23 -0
  78. package/dist/augments/object/map-enum.d.ts +7 -0
  79. package/dist/augments/object/map-enum.js +24 -0
  80. package/dist/augments/object/map-values.d.ts +25 -13
  81. package/dist/augments/object/map-values.js +29 -21
  82. package/dist/augments/object/merge-deep.d.ts +4 -0
  83. package/dist/augments/object/merge-deep.js +4 -0
  84. package/dist/augments/object/merge-defined-properties.d.ts +13 -0
  85. package/dist/augments/object/merge-defined-properties.js +13 -0
  86. package/dist/augments/object/merge-property-arrays.d.ts +28 -0
  87. package/dist/augments/object/merge-property-arrays.js +28 -0
  88. package/dist/augments/object/object-entries.d.ts +27 -0
  89. package/dist/augments/object/object-entries.js +27 -0
  90. package/dist/augments/object/object-filter.d.ts +20 -0
  91. package/dist/augments/object/object-filter.js +20 -0
  92. package/dist/augments/object/object-keys.d.ts +32 -0
  93. package/dist/augments/object/object-keys.js +32 -0
  94. package/dist/augments/object/object-values.d.ts +9 -0
  95. package/dist/augments/object/object-values.js +9 -0
  96. package/dist/augments/path/esm-path.d.ts +26 -0
  97. package/dist/augments/path/esm-path.js +31 -0
  98. package/dist/augments/prisma/base-prisma-types.d.ts +38 -0
  99. package/dist/augments/prisma/prisma-basic-model.d.ts +29 -0
  100. package/dist/augments/prisma/prisma-basic-model.js +1 -0
  101. package/dist/augments/prisma/prisma-full-model.d.ts +37 -0
  102. package/dist/augments/prisma/prisma-full-model.js +1 -0
  103. package/dist/augments/prisma/prisma-model-create.d.ts +159 -0
  104. package/dist/augments/prisma/prisma-model-create.js +58 -0
  105. package/dist/augments/prisma/prisma-model-name.d.ts +18 -0
  106. package/dist/augments/prisma/prisma-model-name.js +1 -0
  107. package/dist/augments/promise/timed-promise.d.ts +15 -0
  108. package/dist/augments/promise/timed-promise.js +15 -0
  109. package/dist/augments/random/random-boolean.d.ts +6 -0
  110. package/dist/augments/random/random-boolean.js +6 -0
  111. package/dist/augments/random/random-integer.d.ts +3 -1
  112. package/dist/augments/random/random-integer.js +3 -1
  113. package/dist/augments/random/random-string.d.ts +6 -2
  114. package/dist/augments/random/random-string.js +6 -2
  115. package/dist/augments/regexp/match.d.ts +10 -0
  116. package/dist/augments/regexp/match.js +13 -0
  117. package/dist/augments/regexp/regexp-flags.d.ts +56 -3
  118. package/dist/augments/regexp/regexp-flags.js +71 -14
  119. package/dist/augments/regexp/regexp-string.d.ts +4 -0
  120. package/dist/augments/regexp/regexp-string.js +5 -1
  121. package/dist/augments/selection-set/select-collapsed.d.ts +46 -3
  122. package/dist/augments/selection-set/select-collapsed.js +40 -2
  123. package/dist/augments/selection-set/select-from.d.ts +47 -2
  124. package/dist/augments/selection-set/select-from.js +48 -1
  125. package/dist/augments/selection-set/selection-set.d.ts +26 -7
  126. package/dist/augments/selection-set/selection-set.js +1 -4
  127. package/dist/augments/string/casing/capitalization.d.ts +15 -1
  128. package/dist/augments/string/casing/capitalization.js +14 -0
  129. package/dist/augments/string/casing/casing.d.ts +53 -7
  130. package/dist/augments/string/casing/casing.js +36 -11
  131. package/dist/augments/string/casing/kebab-and-camel.d.ts +14 -0
  132. package/dist/augments/string/casing/kebab-and-camel.js +20 -5
  133. package/dist/augments/string/comma.d.ts +26 -0
  134. package/dist/augments/string/{commas.js → comma.js} +21 -2
  135. package/dist/augments/string/join.d.ts +15 -4
  136. package/dist/augments/string/join.js +15 -4
  137. package/dist/augments/string/prefix.d.ts +6 -0
  138. package/dist/augments/string/prefix.js +4 -0
  139. package/dist/augments/string/remove-duplicate-characters.d.ts +17 -0
  140. package/dist/augments/string/remove-duplicate-characters.js +22 -0
  141. package/dist/augments/string/replace.d.ts +17 -0
  142. package/dist/augments/string/replace.js +17 -0
  143. package/dist/augments/string/split.d.ts +29 -2
  144. package/dist/augments/string/split.js +32 -7
  145. package/dist/augments/string/substring-index.d.ts +11 -5
  146. package/dist/augments/string/substring-index.js +12 -3
  147. package/dist/augments/string/suffix.d.ts +22 -0
  148. package/dist/augments/string/suffix.js +16 -0
  149. package/dist/augments/string/white-space.d.ts +8 -1
  150. package/dist/augments/string/white-space.js +8 -1
  151. package/dist/augments/string/wrap-string.d.ts +15 -0
  152. package/dist/augments/string/wrap-string.js +15 -0
  153. package/dist/augments/type/ensure-type.d.ts +4 -0
  154. package/dist/augments/type/ensure-type.js +4 -0
  155. package/dist/augments/type/readonly.d.ts +7 -0
  156. package/dist/augments/type/readonly.js +7 -0
  157. package/dist/augments/type/type-recursion.d.ts +93 -1
  158. package/dist/augments/type/union.d.ts +1 -0
  159. package/dist/augments/type/union.js +1 -0
  160. package/dist/augments/type/void-type.d.ts +6 -2
  161. package/dist/augments/type/writable.d.ts +7 -0
  162. package/dist/augments/type/writable.js +7 -0
  163. package/dist/index.d.ts +11 -5
  164. package/dist/index.js +11 -5
  165. package/package.json +19 -9
  166. package/dist/augments/boolean/if-truthy.d.ts +0 -2
  167. package/dist/augments/boolean/if-truthy.js +0 -9
  168. package/dist/augments/file/esm-path.d.ts +0 -4
  169. package/dist/augments/file/esm-path.js +0 -8
  170. package/dist/augments/prisma/prisma-models.d.ts +0 -106
  171. package/dist/augments/regexp/safe-match.d.ts +0 -1
  172. package/dist/augments/regexp/safe-match.js +0 -4
  173. package/dist/augments/string/commas.d.ts +0 -7
  174. /package/dist/augments/prisma/{prisma-models.js → base-prisma-types.js} +0 -0
@@ -1,12 +1,33 @@
1
+ /**
2
+ * Default options for {@link CasingOptions}.
3
+ *
4
+ * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
1
8
  export const defaultCasingOptions = {
2
9
  capitalizeFirstLetter: false,
3
10
  };
4
- export var StringCaseEnum;
5
- (function (StringCaseEnum) {
6
- StringCaseEnum["Upper"] = "upper";
7
- StringCaseEnum["Lower"] = "lower";
8
- })(StringCaseEnum || (StringCaseEnum = {}));
9
- /** Indicates whether the given string has different lower and upper case variants. */
11
+ /**
12
+ * The different string cases.
13
+ *
14
+ * @category String
15
+ * @category Package : @augment-vir/common
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export var StringCase;
19
+ (function (StringCase) {
20
+ StringCase["Upper"] = "upper";
21
+ StringCase["Lower"] = "lower";
22
+ })(StringCase || (StringCase = {}));
23
+ /**
24
+ * Indicates whether the given string has different lower and upper case variants. (Some strings
25
+ * don't, such as all numbers or `'√'`.)
26
+ *
27
+ * @category String
28
+ * @category Package : @augment-vir/common
29
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
30
+ */
10
31
  export function hasCase(input) {
11
32
  return input.toLowerCase() !== input.toUpperCase();
12
33
  }
@@ -16,23 +37,27 @@ export function hasCase(input) {
16
37
  * Note that some characters have no casing, such as punctuation (they have no difference between
17
38
  * upper and lower casings). By default, those letters always return `true` for this function,
18
39
  * regardless of which `caseType` is provided. To instead return `false` for any such characters,
19
- * pass in an options object and set blockNoCaseCharacters to true.
40
+ * pass in an options object and set `rejectNoCaseCharacters` to true.
41
+ *
42
+ * @category String
43
+ * @category Package : @augment-vir/common
44
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
20
45
  */
21
46
  export function isCase(input, caseType, options) {
22
- if (!input && options?.failOnNoCaseCharacters) {
47
+ if (!input && options?.rejectNoCaseCharacters) {
23
48
  return false;
24
49
  }
25
50
  for (const letter of input) {
26
51
  if (!hasCase(letter)) {
27
- if (options?.failOnNoCaseCharacters) {
52
+ if (options?.rejectNoCaseCharacters) {
28
53
  return false;
29
54
  }
30
55
  else {
31
56
  continue;
32
57
  }
33
58
  }
34
- else if ((caseType === StringCaseEnum.Upper && letter !== letter.toUpperCase()) ||
35
- (caseType === StringCaseEnum.Lower && letter !== letter.toLowerCase())) {
59
+ else if ((caseType === StringCase.Upper && letter !== letter.toUpperCase()) ||
60
+ (caseType === StringCase.Lower && letter !== letter.toLowerCase())) {
36
61
  return false;
37
62
  }
38
63
  }
@@ -1,3 +1,17 @@
1
1
  import { CasingOptions } from './casing.js';
2
+ /**
3
+ * Converts a kebab-case string to CamelCase.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
+ */
2
9
  export declare function kebabCaseToCamelCase(rawKebabCase: string, casingOptions?: Partial<CasingOptions> | undefined): string;
10
+ /**
11
+ * Converts a CamelCase string to kebab-case.
12
+ *
13
+ * @category String
14
+ * @category Package : @augment-vir/common
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
3
17
  export declare function camelCaseToKebabCase(rawCamelCase: string): string;
@@ -1,6 +1,14 @@
1
+ import { mergeDefinedProperties } from '../../object/merge-defined-properties.js';
1
2
  import { maybeCapitalize } from './capitalization.js';
2
- import { defaultCasingOptions, isCase, StringCaseEnum } from './casing.js';
3
- export function kebabCaseToCamelCase(rawKebabCase, casingOptions = defaultCasingOptions) {
3
+ import { defaultCasingOptions, isCase, StringCase } from './casing.js';
4
+ /**
5
+ * Converts a kebab-case string to CamelCase.
6
+ *
7
+ * @category String
8
+ * @category Package : @augment-vir/common
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
+ */
11
+ export function kebabCaseToCamelCase(rawKebabCase, casingOptions = {}) {
4
12
  const kebabCase = rawKebabCase.toLowerCase();
5
13
  if (!kebabCase.length) {
6
14
  return '';
@@ -17,16 +25,23 @@ export function kebabCaseToCamelCase(rawKebabCase, casingOptions = defaultCasing
17
25
  return '';
18
26
  }
19
27
  });
20
- return maybeCapitalize(camelCase, casingOptions);
28
+ return maybeCapitalize(camelCase, mergeDefinedProperties(defaultCasingOptions, casingOptions));
21
29
  }
30
+ /**
31
+ * Converts a CamelCase string to kebab-case.
32
+ *
33
+ * @category String
34
+ * @category Package : @augment-vir/common
35
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
36
+ */
22
37
  export function camelCaseToKebabCase(rawCamelCase) {
23
38
  const kebabCase = rawCamelCase
24
39
  .split('')
25
40
  .reduce((accum, currentLetter, index, originalString) => {
26
41
  const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
27
42
  const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
28
- const possibleWordBoundary = isCase(previousLetter, StringCaseEnum.Lower, { failOnNoCaseCharacters: true }) ||
29
- isCase(nextLetter, StringCaseEnum.Lower, { failOnNoCaseCharacters: true });
43
+ const possibleWordBoundary = isCase(previousLetter, StringCase.Lower, { rejectNoCaseCharacters: true }) ||
44
+ isCase(nextLetter, StringCase.Lower, { rejectNoCaseCharacters: true });
30
45
  if (currentLetter === currentLetter.toLowerCase() ||
31
46
  index === 0 ||
32
47
  !possibleWordBoundary) {
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Removes all commas from the given string.
3
+ *
4
+ * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
8
+ export declare function removeCommas(input: string): string;
9
+ /**
10
+ * Convert the given number into a string, then add commas like a normal number would have.
11
+ *
12
+ * @category String
13
+ * @category Number
14
+ * @category Package : @augment-vir/common
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * import {addCommasToNumber} from '@augment-vir/common';
19
+ *
20
+ * addCommasToNumber(1000123.456);
21
+ * // output is `'1,000,123.456'`
22
+ * ```
23
+ *
24
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
25
+ */
26
+ export declare function addCommasToNumber(input: number | string): string;
@@ -1,12 +1,31 @@
1
- import { safeMatch } from '../regexp/safe-match.js';
1
+ import { safeMatch } from '../regexp/match.js';
2
2
  /**
3
3
  * Removes all commas from the given string.
4
4
  *
5
- * @category String:Common
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
6
8
  */
7
9
  export function removeCommas(input) {
8
10
  return input.replace(/,/g, '');
9
11
  }
12
+ /**
13
+ * Convert the given number into a string, then add commas like a normal number would have.
14
+ *
15
+ * @category String
16
+ * @category Number
17
+ * @category Package : @augment-vir/common
18
+ * @example
19
+ *
20
+ * ```ts
21
+ * import {addCommasToNumber} from '@augment-vir/common';
22
+ *
23
+ * addCommasToNumber(1000123.456);
24
+ * // output is `'1,000,123.456'`
25
+ * ```
26
+ *
27
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
28
+ */
10
29
  export function addCommasToNumber(input) {
11
30
  if (typeof input === 'string' && isNaN(Number(input))) {
12
31
  return 'NaN';
@@ -3,8 +3,19 @@
3
3
  * item in the list. If the array has a length < 2, the conjunction is not added. If the list is
4
4
  * only of length 2, then no commas are added.
5
5
  *
6
- * @param list Array of items to be converted into strings. Works best if these are simply strings
7
- * to begin with.
8
- * @param conjunction Defaults to 'and'. The conjunction to be used before the final element.
6
+ * @category String
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
9
  */
10
- export declare function joinWithFinalConjunction(list: ReadonlyArray<any>, conjunction?: string): string;
10
+ export declare function joinWithFinalConjunction(
11
+ /**
12
+ * Array of items to be converted into strings. Works best if these are simply strings to begin
13
+ * with.
14
+ */
15
+ list: ReadonlyArray<any>,
16
+ /**
17
+ * The conjunction to be used before the final element.
18
+ *
19
+ * @default 'and'
20
+ */
21
+ conjunction?: string): string;
@@ -3,11 +3,22 @@
3
3
  * item in the list. If the array has a length < 2, the conjunction is not added. If the list is
4
4
  * only of length 2, then no commas are added.
5
5
  *
6
- * @param list Array of items to be converted into strings. Works best if these are simply strings
7
- * to begin with.
8
- * @param conjunction Defaults to 'and'. The conjunction to be used before the final element.
6
+ * @category String
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
9
  */
10
- export function joinWithFinalConjunction(list, conjunction = 'and') {
10
+ export function joinWithFinalConjunction(
11
+ /**
12
+ * Array of items to be converted into strings. Works best if these are simply strings to begin
13
+ * with.
14
+ */
15
+ list,
16
+ /**
17
+ * The conjunction to be used before the final element.
18
+ *
19
+ * @default 'and'
20
+ */
21
+ conjunction = 'and') {
11
22
  if (list.length < 2) {
12
23
  /**
13
24
  * If there are not multiple things in the list to join, just turn the list into a string
@@ -2,12 +2,16 @@
2
2
  * Generic string type but with the given prefix prepended to it.
3
3
  *
4
4
  * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
5
7
  */
6
8
  export type WithPrefix<Prefix extends string> = `${Prefix}${string}`;
7
9
  /**
8
10
  * Adds a prefix to a string if it does not already exist.
9
11
  *
10
12
  * @category String
13
+ * @category Package : @augment-vir/common
14
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
15
  */
12
16
  export declare function addPrefix<const Prefix extends string>({ value, prefix, }: {
13
17
  value: unknown;
@@ -17,6 +21,8 @@ export declare function addPrefix<const Prefix extends string>({ value, prefix,
17
21
  * Removes a prefix from a string if it exists.
18
22
  *
19
23
  * @category String
24
+ * @category Package : @augment-vir/common
25
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
20
26
  */
21
27
  export declare function removePrefix<const Prefix extends string>({ value, prefix, }: {
22
28
  value: string;
@@ -2,6 +2,8 @@
2
2
  * Adds a prefix to a string if it does not already exist.
3
3
  *
4
4
  * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
5
7
  */
6
8
  export function addPrefix({ value, prefix, }) {
7
9
  if (String(value).startsWith(prefix)) {
@@ -15,6 +17,8 @@ export function addPrefix({ value, prefix, }) {
15
17
  * Removes a prefix from a string if it exists.
16
18
  *
17
19
  * @category String
20
+ * @category Package : @augment-vir/common
21
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
22
  */
19
23
  export function removePrefix({ value, prefix, }) {
20
24
  if (value.startsWith(prefix)) {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Removes duplicate characters from any number of strings.
3
+ *
4
+ * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {removeDuplicateCharacters} from '@augment-vir/common';
10
+ *
11
+ * removeDuplicateCharacters('aAaBc', 'QrsAa');
12
+ * // output is `'aABcQrs'`
13
+ * ```
14
+ *
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
16
+ */
17
+ export declare function removeDuplicateCharacters(...values: ReadonlyArray<string>): string;
@@ -0,0 +1,22 @@
1
+ import { removeDuplicates } from '../array/remove-duplicates.js';
2
+ /**
3
+ * Removes duplicate characters from any number of strings.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {removeDuplicateCharacters} from '@augment-vir/common';
11
+ *
12
+ * removeDuplicateCharacters('aAaBc', 'QrsAa');
13
+ * // output is `'aABcQrs'`
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export function removeDuplicateCharacters(...values) {
19
+ const combined = values.join('');
20
+ const deDuped = removeDuplicates(Array.from(combined));
21
+ return Array.from(deDuped).join('');
22
+ }
@@ -1 +1,18 @@
1
+ /**
2
+ * Replaces whatever substring is at the given index in the original string with the new string.
3
+ * Optionally, provide a length of the substring to get replaced.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {replaceStringAtIndex} from '@augment-vir/common';
11
+ *
12
+ * replaceStringAtIndex('eat the waffles', 4, 'his'); // outputs `'eat his waffles'`
13
+ * replaceStringAtIndex('eat the waffles', 4, 'my', 3); // outputs `'eat my waffles'`
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
1
18
  export declare function replaceStringAtIndex(originalString: string, start: number, newString: string, length?: number): string;
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Replaces whatever substring is at the given index in the original string with the new string.
3
+ * Optionally, provide a length of the substring to get replaced.
4
+ *
5
+ * @category String
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {replaceStringAtIndex} from '@augment-vir/common';
11
+ *
12
+ * replaceStringAtIndex('eat the waffles', 4, 'his'); // outputs `'eat his waffles'`
13
+ * replaceStringAtIndex('eat the waffles', 4, 'my', 3); // outputs `'eat my waffles'`
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
1
18
  export function replaceStringAtIndex(originalString, start, newString, length = newString.length) {
2
19
  const before = originalString.slice(0, Math.max(0, start));
3
20
  const after = originalString.slice(Math.max(0, start + length));
@@ -1,4 +1,31 @@
1
1
  import type { AtLeastTuple } from '@augment-vir/core';
2
- /** Same as String.prototype.split but includes the delimiter to split by in the output array. */
3
- export declare function splitIncludeSplit(original: string, splitterInput: string | RegExp, caseSensitive: boolean): readonly string[];
2
+ /**
3
+ * Same as *
4
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5
+ * but includes the split delimiter in the output array.
6
+ *
7
+ * @category String
8
+ * @category Package : @augment-vir/common
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * import {splitIncludeSplit} from '@augment-vir/common';
13
+ *
14
+ * splitIncludeSplit('1,2,3', ',', {caseSensitive: false}); // outputs `['1', ',', '2', ',', '3']`
15
+ * ```
16
+ *
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
+ */
19
+ export declare function splitIncludeSplit(original: string, splitDelimiter: string | RegExp, { caseSensitive }: {
20
+ caseSensitive: boolean;
21
+ }): readonly string[];
22
+ /**
23
+ * Same as
24
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
25
+ * but typed better: it always returns an array with at least one string.
26
+ *
27
+ * @category String
28
+ * @category Package : @augment-vir/common
29
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
30
+ */
4
31
  export declare function safeSplit(input: string, splitString: string): AtLeastTuple<string, 1>;
@@ -1,14 +1,30 @@
1
- import { makeCaseInsensitiveRegExp } from '../regexp/regexp-flags.js';
2
- import { getSubstringIndexes } from './substring-index.js';
3
- /** Same as String.prototype.split but includes the delimiter to split by in the output array. */
4
- export function splitIncludeSplit(original, splitterInput, caseSensitive) {
5
- const indexLengths = getSubstringIndexes({
1
+ import { setRegExpCaseSensitivity } from '../regexp/regexp-flags.js';
2
+ import { findSubstringIndexes } from './substring-index.js';
3
+ /**
4
+ * Same as *
5
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
6
+ * but includes the split delimiter in the output array.
7
+ *
8
+ * @category String
9
+ * @category Package : @augment-vir/common
10
+ * @example
11
+ *
12
+ * ```ts
13
+ * import {splitIncludeSplit} from '@augment-vir/common';
14
+ *
15
+ * splitIncludeSplit('1,2,3', ',', {caseSensitive: false}); // outputs `['1', ',', '2', ',', '3']`
16
+ * ```
17
+ *
18
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
19
+ */
20
+ export function splitIncludeSplit(original, splitDelimiter, { caseSensitive }) {
21
+ const indexLengths = findSubstringIndexes({
6
22
  searchIn: original,
7
- searchFor: splitterInput,
23
+ searchFor: splitDelimiter,
8
24
  caseSensitive,
9
25
  includeLength: true,
10
26
  });
11
- const splitter = makeCaseInsensitiveRegExp(splitterInput, caseSensitive);
27
+ const splitter = setRegExpCaseSensitivity(splitDelimiter, { caseSensitive });
12
28
  const splits = original.split(splitter);
13
29
  return splits.reduce((accum, current, index) => {
14
30
  // this will be undefined on the last index
@@ -23,6 +39,15 @@ export function splitIncludeSplit(original, splitterInput, caseSensitive) {
23
39
  }
24
40
  }, []);
25
41
  }
42
+ /**
43
+ * Same as
44
+ * [`''.split`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split)
45
+ * but typed better: it always returns an array with at least one string.
46
+ *
47
+ * @category String
48
+ * @category Package : @augment-vir/common
49
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
50
+ */
26
51
  export function safeSplit(input, splitString) {
27
52
  return input.split(splitString);
28
53
  }
@@ -1,11 +1,17 @@
1
- export declare function getSubstringIndexes<IncludeLength extends boolean | undefined>({ searchIn, searchFor, caseSensitive, includeLength, }: {
1
+ /**
2
+ * Finds all indexes of a `searchFor` string or RegExp in `searchIn`. Ths is similar to
3
+ * [`''.indexOf`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
4
+ * except that it finds _all_ indexes of.
5
+ *
6
+ * @category String
7
+ * @category Package : @augment-vir/common
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
9
+ */
10
+ export declare function findSubstringIndexes<IncludeLength extends boolean | undefined>({ searchIn, searchFor, caseSensitive, includeLength, }: {
2
11
  searchIn: string;
3
12
  searchFor: string | RegExp;
4
- /**
5
- * CaseSensitive only applies when the input is a string. Otherwise, the RegExp's "i" flag is
6
- * used to determine case sensitivity.
7
- */
8
13
  caseSensitive: boolean;
14
+ /** Set to true to get an array of objects with the found indexes _and_ their lengths. */
9
15
  includeLength?: IncludeLength;
10
16
  }): IncludeLength extends true ? {
11
17
  index: number;
@@ -1,6 +1,15 @@
1
- import { makeCaseInsensitiveRegExp } from '../regexp/regexp-flags.js';
2
- export function getSubstringIndexes({ searchIn, searchFor, caseSensitive, includeLength, }) {
3
- const searchRegExp = makeCaseInsensitiveRegExp(searchFor, caseSensitive);
1
+ import { addRegExpFlags, setRegExpCaseSensitivity } from '../regexp/regexp-flags.js';
2
+ /**
3
+ * Finds all indexes of a `searchFor` string or RegExp in `searchIn`. Ths is similar to
4
+ * [`''.indexOf`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
5
+ * except that it finds _all_ indexes of.
6
+ *
7
+ * @category String
8
+ * @category Package : @augment-vir/common
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
+ */
11
+ export function findSubstringIndexes({ searchIn, searchFor, caseSensitive, includeLength, }) {
12
+ const searchRegExp = addRegExpFlags(setRegExpCaseSensitivity(searchFor, { caseSensitive }), 'g');
4
13
  const indexes = [];
5
14
  const indexesAndLengths = [];
6
15
  searchIn.replace(searchRegExp, (...matchResults) => {
@@ -2,62 +2,82 @@
2
2
  * Generic string type but with the given suffix appended to it.
3
3
  *
4
4
  * @category String
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
5
7
  */
6
8
  export type WithSuffix<Suffix extends string> = `${string}${Suffix}`;
7
9
  /**
8
10
  * Suffix for {@link addPercent} and {@link removePercent}.
9
11
  *
10
12
  * @category String
13
+ * @category Package : @augment-vir/common
14
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
15
  */
12
16
  export declare const percentSuffix = "%";
13
17
  /**
14
18
  * Suffix for {@link addPx} and {@link removePx}.
15
19
  *
16
20
  * @category String
21
+ * @category Package : @augment-vir/common
22
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
23
  */
18
24
  export declare const pxSuffix = "px";
19
25
  /**
20
26
  * Generic string type but with the `'px'` suffix appended to it.
21
27
  *
22
28
  * @category String
29
+ * @category Package : @augment-vir/common
30
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
23
31
  */
24
32
  export type WithPx = WithSuffix<typeof pxSuffix>;
25
33
  /**
26
34
  * Generic string type but with the `'%'` suffix appended to it.
27
35
  *
28
36
  * @category String
37
+ * @category Package : @augment-vir/common
38
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
29
39
  */
30
40
  export type WithPercent = WithSuffix<typeof percentSuffix>;
31
41
  /**
32
42
  * Adds the `'px'` suffix to a string if it does not already exist.
33
43
  *
34
44
  * @category String
45
+ * @category Package : @augment-vir/common
46
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
35
47
  */
36
48
  export declare function addPx(input: number | string): WithPx;
37
49
  /**
38
50
  * Removes the `'px'` suffix from a string if it exists.
39
51
  *
40
52
  * @category String
53
+ * @category Package : @augment-vir/common
41
54
  * @throws `TypeError` if the input can't be converted into a number.
55
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
42
56
  */
43
57
  export declare function removePx(input: string): number;
44
58
  /**
45
59
  * Adds the `'%'` suffix to a string if it does not already exist.
46
60
  *
47
61
  * @category String
62
+ * @category Package : @augment-vir/common
63
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
48
64
  */
49
65
  export declare function addPercent(input: number | string): WithPercent;
50
66
  /**
51
67
  * Removes the `'%'` suffix from a string if it exists.
52
68
  *
53
69
  * @category String
70
+ * @category Package : @augment-vir/common
54
71
  * @throws `TypeError` if the input can't be converted into a number.
72
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
55
73
  */
56
74
  export declare function removePercent(input: string): number;
57
75
  /**
58
76
  * Adds a suffix to a string if it does not already exist.
59
77
  *
60
78
  * @category String
79
+ * @category Package : @augment-vir/common
80
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
61
81
  */
62
82
  export declare function addSuffix<const Suffix extends string>({ value, suffix, }: {
63
83
  value: unknown;
@@ -67,6 +87,8 @@ export declare function addSuffix<const Suffix extends string>({ value, suffix,
67
87
  * Removes a suffix from a string if it exists.
68
88
  *
69
89
  * @category String
90
+ * @category Package : @augment-vir/common
91
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
70
92
  */
71
93
  export declare function removeSuffix<const Suffix extends string>({ value, suffix, }: {
72
94
  value: string;