complete-common 2.3.1 → 2.5.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.
@@ -22,6 +22,19 @@ export declare function arrayEquals<T>(array1: readonly T[], array2: readonly T[
22
22
  * This function is variadic, meaning that you can specify N arguments to remove N elements.
23
23
  */
24
24
  export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsToRemove: readonly T[]): readonly T[];
25
+ /**
26
+ * Removes all of the specified element(s) from the array. If the specified element(s) are not found
27
+ * in the array, this function will do nothing.
28
+ *
29
+ * This function is variadic, meaning that you can specify N arguments to remove N elements.
30
+ *
31
+ * If there is more than one matching element in the array, this function will remove every matching
32
+ * element. If you want to only remove the first matching element, use the `arrayRemoveInPlace`
33
+ * function instead.
34
+ *
35
+ * @returns True if one or more elements were removed, false otherwise.
36
+ */
37
+ export declare function arrayRemoveAllInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): boolean;
25
38
  /**
26
39
  * Removes the specified element(s) from the array. If the specified element(s) are not found in the
27
40
  * array, this function will do nothing.
@@ -22,6 +22,19 @@ export declare function arrayEquals<T>(array1: readonly T[], array2: readonly T[
22
22
  * This function is variadic, meaning that you can specify N arguments to remove N elements.
23
23
  */
24
24
  export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsToRemove: readonly T[]): readonly T[];
25
+ /**
26
+ * Removes all of the specified element(s) from the array. If the specified element(s) are not found
27
+ * in the array, this function will do nothing.
28
+ *
29
+ * This function is variadic, meaning that you can specify N arguments to remove N elements.
30
+ *
31
+ * If there is more than one matching element in the array, this function will remove every matching
32
+ * element. If you want to only remove the first matching element, use the `arrayRemoveInPlace`
33
+ * function instead.
34
+ *
35
+ * @returns True if one or more elements were removed, false otherwise.
36
+ */
37
+ export declare function arrayRemoveAllInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): boolean;
25
38
  /**
26
39
  * Removes the specified element(s) from the array. If the specified element(s) are not found in the
27
40
  * array, this function will do nothing.
@@ -22,6 +22,19 @@ export declare function arrayEquals<T>(array1: readonly T[], array2: readonly T[
22
22
  * This function is variadic, meaning that you can specify N arguments to remove N elements.
23
23
  */
24
24
  export declare function arrayRemove<T>(originalArray: readonly T[], ...elementsToRemove: readonly T[]): readonly T[];
25
+ /**
26
+ * Removes all of the specified element(s) from the array. If the specified element(s) are not found
27
+ * in the array, this function will do nothing.
28
+ *
29
+ * This function is variadic, meaning that you can specify N arguments to remove N elements.
30
+ *
31
+ * If there is more than one matching element in the array, this function will remove every matching
32
+ * element. If you want to only remove the first matching element, use the `arrayRemoveInPlace`
33
+ * function instead.
34
+ *
35
+ * @returns True if one or more elements were removed, false otherwise.
36
+ */
37
+ export declare function arrayRemoveAllInPlace<T>(array: T[], ...elementsToRemove: readonly T[]): boolean;
25
38
  /**
26
39
  * Removes the specified element(s) from the array. If the specified element(s) are not found in the
27
40
  * array, this function will do nothing.
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/functions/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI7D;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,GACjC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,CAQ7B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,MAAM,EAAE,SAAS,CAAC,EAAE,GACnB,OAAO,CAST;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,SAAS,CAAC,EAAE,EAC3B,GAAG,gBAAgB,EAAE,SAAS,CAAC,EAAE,GAChC,SAAS,CAAC,EAAE,CAWd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAElC,KAAK,EA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SAAS,IAAI,EAAE,CAWjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,UAAU,GAAE,SAAS,CAAC,EAAO,GAC5B,CAAC,CAiBH;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,UAAU,GAAE,SAAS,MAAM,EAAO,GACjC,MAAM,CAQR;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,SAAS,YAAY,CAAC,CAAC,CAAC,EAC9D,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC,GAC7B,aAAa,IAAI,YAAY,CAG/B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,GAAG,cAAc,EAAE,SAAS,CAAC,EAAE,GAC9B,OAAO,CAET;AAED,uFAAuF;AACvF,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,EAAE,CAEtD;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAElE;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEzD"}
@@ -39,12 +39,16 @@ export declare function isFirstLetterCapitalized(string: string): boolean;
39
39
  * An empty string is not considered to be kebab-case.
40
40
  */
41
41
  export declare function isKebabCase(string: string): boolean;
42
+ /** Helper function to test if a string contains only lowercase ASCII letters (a through z). */
43
+ export declare function isLowerCase(string: string): boolean;
42
44
  /**
43
45
  * Helper function to check if a given string is a valid Semantic Version.
44
46
  *
45
47
  * @see https://semver.org/
46
48
  */
47
49
  export declare function isSemanticVersion(versionString: string): boolean;
50
+ /** Helper function to test if a string contains only uppercase ASCII letters (A through Z). */
51
+ export declare function isUpperCase(string: string): boolean;
48
52
  /** Helper function to convert a string from kebab-case to camelCase. */
49
53
  export declare function kebabCaseToCamelCase(string: string): string;
50
54
  /** Helper function to convert a string from kebab-case to PascalCase. */
@@ -39,12 +39,16 @@ export declare function isFirstLetterCapitalized(string: string): boolean;
39
39
  * An empty string is not considered to be kebab-case.
40
40
  */
41
41
  export declare function isKebabCase(string: string): boolean;
42
+ /** Helper function to test if a string contains only lowercase ASCII letters (a through z). */
43
+ export declare function isLowerCase(string: string): boolean;
42
44
  /**
43
45
  * Helper function to check if a given string is a valid Semantic Version.
44
46
  *
45
47
  * @see https://semver.org/
46
48
  */
47
49
  export declare function isSemanticVersion(versionString: string): boolean;
50
+ /** Helper function to test if a string contains only uppercase ASCII letters (A through Z). */
51
+ export declare function isUpperCase(string: string): boolean;
48
52
  /** Helper function to convert a string from kebab-case to camelCase. */
49
53
  export declare function kebabCaseToCamelCase(string: string): string;
50
54
  /** Helper function to convert a string from kebab-case to PascalCase. */
@@ -39,12 +39,16 @@ export declare function isFirstLetterCapitalized(string: string): boolean;
39
39
  * An empty string is not considered to be kebab-case.
40
40
  */
41
41
  export declare function isKebabCase(string: string): boolean;
42
+ /** Helper function to test if a string contains only lowercase ASCII letters (a through z). */
43
+ export declare function isLowerCase(string: string): boolean;
42
44
  /**
43
45
  * Helper function to check if a given string is a valid Semantic Version.
44
46
  *
45
47
  * @see https://semver.org/
46
48
  */
47
49
  export declare function isSemanticVersion(versionString: string): boolean;
50
+ /** Helper function to test if a string contains only uppercase ASCII letters (A through Z). */
51
+ export declare function isUpperCase(string: string): boolean;
48
52
  /** Helper function to convert a string from kebab-case to camelCase. */
49
53
  export declare function kebabCaseToCamelCase(string: string): string;
50
54
  /** Helper function to convert a string from kebab-case to PascalCase. */
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../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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"}
package/dist/index.cjs CHANGED
@@ -120,6 +120,20 @@ function arrayRemove(originalArray, ...elementsToRemove) {
120
120
  }
121
121
  return array;
122
122
  }
123
+ function arrayRemoveAllInPlace(array, ...elementsToRemove) {
124
+ let removedOneOrMoreElements = false;
125
+ for (const element of elementsToRemove) {
126
+ let index;
127
+ do {
128
+ index = array.indexOf(element);
129
+ if (index > -1) {
130
+ removedOneOrMoreElements = true;
131
+ array.splice(index, 1);
132
+ }
133
+ } while (index > -1);
134
+ }
135
+ return removedOneOrMoreElements;
136
+ }
123
137
  function arrayRemoveInPlace(array, ...elementsToRemove) {
124
138
  const removedElements = [];
125
139
  for (const element of elementsToRemove) {
@@ -350,6 +364,8 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
350
364
  const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
351
365
  const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
352
366
  const WHITESPACE_REGEX = /\s/g;
367
+ const UPPERCASE_REGEX = /^[A-Z]*$/;
368
+ const LOWERCASE_REGEX = /^[a-z]*$/;
353
369
  function capitalizeFirstLetter(string) {
354
370
  if (string === "") {
355
371
  return string;
@@ -394,10 +410,16 @@ function isFirstLetterCapitalized(string) {
394
410
  function isKebabCase(string) {
395
411
  return KEBAB_CASE_REGEX.test(string);
396
412
  }
413
+ function isLowerCase(string) {
414
+ return LOWERCASE_REGEX.test(string);
415
+ }
397
416
  function isSemanticVersion(versionString) {
398
417
  const match = versionString.match(SEMANTIC_VERSION_REGEX);
399
418
  return match !== null;
400
419
  }
420
+ function isUpperCase(string) {
421
+ return UPPERCASE_REGEX.test(string);
422
+ }
401
423
  function kebabCaseToCamelCase(string) {
402
424
  return string.replaceAll(/-./g, (match) => {
403
425
  const firstLetterOfWord = match[1];
@@ -514,6 +536,7 @@ exports.addSetsToSet = addSetsToSet;
514
536
  exports.arrayCopyTwoDimensional = arrayCopyTwoDimensional;
515
537
  exports.arrayEquals = arrayEquals;
516
538
  exports.arrayRemove = arrayRemove;
539
+ exports.arrayRemoveAllInPlace = arrayRemoveAllInPlace;
517
540
  exports.arrayRemoveInPlace = arrayRemoveInPlace;
518
541
  exports.assertArray = assertArray;
519
542
  exports.assertBoolean = assertBoolean;
@@ -551,8 +574,10 @@ exports.isEnumValue = isEnumValue;
551
574
  exports.isFirstLetterCapitalized = isFirstLetterCapitalized;
552
575
  exports.isKebabCase = isKebabCase;
553
576
  exports.isKeyOf = isKeyOf;
577
+ exports.isLowerCase = isLowerCase;
554
578
  exports.isObject = isObject;
555
579
  exports.isSemanticVersion = isSemanticVersion;
580
+ exports.isUpperCase = isUpperCase;
556
581
  exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
557
582
  exports.kebabCaseToPascalCase = kebabCaseToPascalCase;
558
583
  exports.mapFilter = mapFilter;
package/dist/index.mjs CHANGED
@@ -118,6 +118,20 @@ function arrayRemove(originalArray, ...elementsToRemove) {
118
118
  }
119
119
  return array;
120
120
  }
121
+ function arrayRemoveAllInPlace(array, ...elementsToRemove) {
122
+ let removedOneOrMoreElements = false;
123
+ for (const element of elementsToRemove) {
124
+ let index;
125
+ do {
126
+ index = array.indexOf(element);
127
+ if (index > -1) {
128
+ removedOneOrMoreElements = true;
129
+ array.splice(index, 1);
130
+ }
131
+ } while (index > -1);
132
+ }
133
+ return removedOneOrMoreElements;
134
+ }
121
135
  function arrayRemoveInPlace(array, ...elementsToRemove) {
122
136
  const removedElements = [];
123
137
  for (const element of elementsToRemove) {
@@ -348,6 +362,8 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
348
362
  const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
349
363
  const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
350
364
  const WHITESPACE_REGEX = /\s/g;
365
+ const UPPERCASE_REGEX = /^[A-Z]*$/;
366
+ const LOWERCASE_REGEX = /^[a-z]*$/;
351
367
  function capitalizeFirstLetter(string) {
352
368
  if (string === "") {
353
369
  return string;
@@ -392,10 +408,16 @@ function isFirstLetterCapitalized(string) {
392
408
  function isKebabCase(string) {
393
409
  return KEBAB_CASE_REGEX.test(string);
394
410
  }
411
+ function isLowerCase(string) {
412
+ return LOWERCASE_REGEX.test(string);
413
+ }
395
414
  function isSemanticVersion(versionString) {
396
415
  const match = versionString.match(SEMANTIC_VERSION_REGEX);
397
416
  return match !== null;
398
417
  }
418
+ function isUpperCase(string) {
419
+ return UPPERCASE_REGEX.test(string);
420
+ }
399
421
  function kebabCaseToCamelCase(string) {
400
422
  return string.replaceAll(/-./g, (match) => {
401
423
  const firstLetterOfWord = match[1];
@@ -503,4 +525,4 @@ function* tupleKeys(tuple) {
503
525
 
504
526
  const ReadonlyMap = Map;
505
527
 
506
- export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertArray, assertBoolean, assertDefined, assertEnumValue, assertNotNull, assertNumber, assertObject, assertString, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isArray, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isObject, isSemanticVersion, kebabCaseToCamelCase, kebabCaseToPascalCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
528
+ export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertBoolean, assertDefined, assertEnumValue, assertNotNull, assertNumber, assertObject, assertString, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isArray, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "complete-common",
3
- "version": "2.3.1",
3
+ "version": "2.5.0",
4
4
  "description": "Helper functions for TypeScript projects.",
5
5
  "keywords": [],
6
6
  "homepage": "https://complete-ts.github.io/",
@@ -35,12 +35,12 @@
35
35
  "test": "glob \"./src/**/*.test.ts\" --cmd=\"node --import tsx --test --test-reporter spec\""
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "24.0.4",
39
- "complete-node": "7.2.0",
38
+ "@types/node": "24.0.15",
39
+ "complete-node": "7.4.3",
40
40
  "eslint-plugin-sort-exports": "0.9.1",
41
41
  "glob": "11.0.3",
42
42
  "typescript": "5.8.3",
43
- "typescript-eslint": "8.35.0",
43
+ "typescript-eslint": "8.37.0",
44
44
  "unbuild": "3.5.0"
45
45
  }
46
46
  }
@@ -66,6 +66,39 @@ export function arrayRemove<T>(
66
66
  return array;
67
67
  }
68
68
 
69
+ /**
70
+ * Removes all of the specified element(s) from the array. If the specified element(s) are not found
71
+ * in the array, this function will do nothing.
72
+ *
73
+ * This function is variadic, meaning that you can specify N arguments to remove N elements.
74
+ *
75
+ * If there is more than one matching element in the array, this function will remove every matching
76
+ * element. If you want to only remove the first matching element, use the `arrayRemoveInPlace`
77
+ * function instead.
78
+ *
79
+ * @returns True if one or more elements were removed, false otherwise.
80
+ */
81
+ export function arrayRemoveAllInPlace<T>(
82
+ // eslint-disable-next-line complete/prefer-readonly-parameter-types
83
+ array: T[],
84
+ ...elementsToRemove: readonly T[]
85
+ ): boolean {
86
+ let removedOneOrMoreElements = false;
87
+
88
+ for (const element of elementsToRemove) {
89
+ let index: number;
90
+ do {
91
+ index = array.indexOf(element);
92
+ if (index > -1) {
93
+ removedOneOrMoreElements = true;
94
+ array.splice(index, 1);
95
+ }
96
+ } while (index > -1);
97
+ }
98
+
99
+ return removedOneOrMoreElements;
100
+ }
101
+
69
102
  /**
70
103
  * Removes the specified element(s) from the array. If the specified element(s) are not found in the
71
104
  * array, this function will do nothing.
@@ -1,6 +1,12 @@
1
1
  import { equal } from "node:assert";
2
2
  import test, { describe } from "node:test";
3
- import { hasDiacritic, hasEmoji, isKebabCase } from "./string.js";
3
+ import {
4
+ hasDiacritic,
5
+ hasEmoji,
6
+ isKebabCase,
7
+ trimPrefix,
8
+ trimSuffix,
9
+ } from "./string.js";
4
10
 
5
11
  describe("hasEmoji", () => {
6
12
  test("should return true for string with emoji", () => {
@@ -105,3 +111,21 @@ describe("isKebabCase", () => {
105
111
  equal(isKebabCase(""), false);
106
112
  });
107
113
  });
114
+
115
+ describe("trimPrefix", () => {
116
+ test(() => {
117
+ equal(trimPrefix("foo", ""), "foo");
118
+ equal(trimPrefix("foo", "f"), "oo");
119
+ equal(trimPrefix("foo", "fo"), "o");
120
+ equal(trimPrefix("foo", "foo"), "");
121
+ equal(trimPrefix("foo", "foo1"), "foo");
122
+ });
123
+ });
124
+
125
+ describe("trimSuffix", () => {
126
+ equal(trimSuffix("foo", ""), "foo");
127
+ equal(trimSuffix("foo", "o"), "fo");
128
+ equal(trimSuffix("foo", "oo"), "f");
129
+ equal(trimSuffix("foo", "foo"), "");
130
+ equal(trimSuffix("foo", "1foo"), "foo");
131
+ });
@@ -18,6 +18,8 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
18
18
  const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
19
19
  const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
20
20
  const WHITESPACE_REGEX = /\s/g;
21
+ const UPPERCASE_REGEX = /^[A-Z]*$/;
22
+ const LOWERCASE_REGEX = /^[a-z]*$/;
21
23
 
22
24
  /** Helper function to capitalize the first letter of a string. */
23
25
  export function capitalizeFirstLetter(string: string): string {
@@ -116,6 +118,11 @@ export function isKebabCase(string: string): boolean {
116
118
  return KEBAB_CASE_REGEX.test(string);
117
119
  }
118
120
 
121
+ /** Helper function to test if a string contains only lowercase ASCII letters (a through z). */
122
+ export function isLowerCase(string: string): boolean {
123
+ return LOWERCASE_REGEX.test(string);
124
+ }
125
+
119
126
  /**
120
127
  * Helper function to check if a given string is a valid Semantic Version.
121
128
  *
@@ -126,6 +133,11 @@ export function isSemanticVersion(versionString: string): boolean {
126
133
  return match !== null;
127
134
  }
128
135
 
136
+ /** Helper function to test if a string contains only uppercase ASCII letters (A through Z). */
137
+ export function isUpperCase(string: string): boolean {
138
+ return UPPERCASE_REGEX.test(string);
139
+ }
140
+
129
141
  /** Helper function to convert a string from kebab-case to camelCase. */
130
142
  export function kebabCaseToCamelCase(string: string): string {
131
143
  return string.replaceAll(/-./g, (match) => {