complete-common 2.14.0 → 2.15.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.
- package/dist/functions/assert.d.cts +3 -3
- package/dist/functions/assert.d.mts +3 -3
- package/dist/functions/assert.d.ts +3 -3
- package/dist/functions/assert.d.ts.map +1 -1
- package/dist/functions/string.d.cts +2 -0
- package/dist/functions/string.d.mts +2 -0
- package/dist/functions/string.d.ts +2 -0
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/index.cjs +5 -0
- package/dist/index.mjs +5 -1
- package/package.json +8 -6
- package/src/functions/assert.ts +3 -3
- package/src/functions/string.test.ts +37 -2
- package/src/functions/string.ts +9 -0
|
@@ -10,12 +10,12 @@ export declare function assertArray(value: unknown, msg: string): asserts value
|
|
|
10
10
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
11
11
|
* a boolean.
|
|
12
12
|
*/
|
|
13
|
-
export declare function assertArrayBoolean(value: unknown, msg: string): asserts value is
|
|
13
|
+
export declare function assertArrayBoolean(value: unknown, msg: string): asserts value is boolean[];
|
|
14
14
|
/**
|
|
15
15
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
16
16
|
* a number.
|
|
17
17
|
*/
|
|
18
|
-
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is
|
|
18
|
+
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is number[];
|
|
19
19
|
/**
|
|
20
20
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
21
|
* an object (i.e. a TypeScript record).
|
|
@@ -25,7 +25,7 @@ export declare function assertArrayObject(value: unknown, msg: string): asserts
|
|
|
25
25
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
26
26
|
* a string.
|
|
27
27
|
*/
|
|
28
|
-
export declare function assertArrayString(value: unknown, msg: string): asserts value is
|
|
28
|
+
export declare function assertArrayString(value: unknown, msg: string): asserts value is string[];
|
|
29
29
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
30
30
|
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
31
31
|
/**
|
|
@@ -10,12 +10,12 @@ export declare function assertArray(value: unknown, msg: string): asserts value
|
|
|
10
10
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
11
11
|
* a boolean.
|
|
12
12
|
*/
|
|
13
|
-
export declare function assertArrayBoolean(value: unknown, msg: string): asserts value is
|
|
13
|
+
export declare function assertArrayBoolean(value: unknown, msg: string): asserts value is boolean[];
|
|
14
14
|
/**
|
|
15
15
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
16
16
|
* a number.
|
|
17
17
|
*/
|
|
18
|
-
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is
|
|
18
|
+
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is number[];
|
|
19
19
|
/**
|
|
20
20
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
21
|
* an object (i.e. a TypeScript record).
|
|
@@ -25,7 +25,7 @@ export declare function assertArrayObject(value: unknown, msg: string): asserts
|
|
|
25
25
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
26
26
|
* a string.
|
|
27
27
|
*/
|
|
28
|
-
export declare function assertArrayString(value: unknown, msg: string): asserts value is
|
|
28
|
+
export declare function assertArrayString(value: unknown, msg: string): asserts value is string[];
|
|
29
29
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
30
30
|
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
31
31
|
/**
|
|
@@ -10,12 +10,12 @@ export declare function assertArray(value: unknown, msg: string): asserts value
|
|
|
10
10
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
11
11
|
* a boolean.
|
|
12
12
|
*/
|
|
13
|
-
export declare function assertArrayBoolean(value: unknown, msg: string): asserts value is
|
|
13
|
+
export declare function assertArrayBoolean(value: unknown, msg: string): asserts value is boolean[];
|
|
14
14
|
/**
|
|
15
15
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
16
16
|
* a number.
|
|
17
17
|
*/
|
|
18
|
-
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is
|
|
18
|
+
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is number[];
|
|
19
19
|
/**
|
|
20
20
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
21
|
* an object (i.e. a TypeScript record).
|
|
@@ -25,7 +25,7 @@ export declare function assertArrayObject(value: unknown, msg: string): asserts
|
|
|
25
25
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
26
26
|
* a string.
|
|
27
27
|
*/
|
|
28
|
-
export declare function assertArrayString(value: unknown, msg: string): asserts value is
|
|
28
|
+
export declare function assertArrayString(value: unknown, msg: string): asserts value is string[];
|
|
29
29
|
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
30
30
|
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
31
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIjE,+EAA+E;AAC/E,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,EAAE,CAI5B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,EAAE,CAM5B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,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AE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAMzB"}
|
|
@@ -115,6 +115,8 @@ export declare function removeLinesMatching(string: string, match: string): stri
|
|
|
115
115
|
export declare function removeNonPrintableCharacters(string: string): string;
|
|
116
116
|
/** Helper function to remove all whitespace characters from a string. */
|
|
117
117
|
export declare function removeWhitespace(string: string): string;
|
|
118
|
+
/** Helper function to convert a string from TitleCase (PascalCase) to kebab-case. */
|
|
119
|
+
export declare function titleCaseToKebabCase(string: string): string;
|
|
118
120
|
/**
|
|
119
121
|
* Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
|
|
120
122
|
*
|
|
@@ -115,6 +115,8 @@ export declare function removeLinesMatching(string: string, match: string): stri
|
|
|
115
115
|
export declare function removeNonPrintableCharacters(string: string): string;
|
|
116
116
|
/** Helper function to remove all whitespace characters from a string. */
|
|
117
117
|
export declare function removeWhitespace(string: string): string;
|
|
118
|
+
/** Helper function to convert a string from TitleCase (PascalCase) to kebab-case. */
|
|
119
|
+
export declare function titleCaseToKebabCase(string: string): string;
|
|
118
120
|
/**
|
|
119
121
|
* Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
|
|
120
122
|
*
|
|
@@ -115,6 +115,8 @@ export declare function removeLinesMatching(string: string, match: string): stri
|
|
|
115
115
|
export declare function removeNonPrintableCharacters(string: string): string;
|
|
116
116
|
/** Helper function to remove all whitespace characters from a string. */
|
|
117
117
|
export declare function removeWhitespace(string: string): string;
|
|
118
|
+
/** Helper function to convert a string from TitleCase (PascalCase) to kebab-case. */
|
|
119
|
+
export declare function titleCaseToKebabCase(string: string): string;
|
|
118
120
|
/**
|
|
119
121
|
* Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
|
|
120
122
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"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SION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
444
444
|
const WHITESPACE_REGEX = /\s/g;
|
|
445
|
+
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
445
446
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
446
447
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
447
448
|
function capitalizeFirstLetter(string) {
|
|
@@ -567,6 +568,9 @@ function removeNonPrintableCharacters(string) {
|
|
|
567
568
|
function removeWhitespace(string) {
|
|
568
569
|
return string.replaceAll(WHITESPACE_REGEX, "");
|
|
569
570
|
}
|
|
571
|
+
function titleCaseToKebabCase(string) {
|
|
572
|
+
return string.replaceAll(TITLE_CASE_BOUNDARY_REGEX, "-").replaceAll(/ +/g, "-").toLowerCase();
|
|
573
|
+
}
|
|
570
574
|
function trimPrefix(string, prefix, trimAll = false) {
|
|
571
575
|
if (trimAll) {
|
|
572
576
|
const regExp = new RegExp(`^${prefix}+`, "g");
|
|
@@ -696,6 +700,7 @@ exports.setAdd = setAdd;
|
|
|
696
700
|
exports.setHas = setHas;
|
|
697
701
|
exports.sortCaseInsensitive = sortCaseInsensitive;
|
|
698
702
|
exports.sumArray = sumArray;
|
|
703
|
+
exports.titleCaseToKebabCase = titleCaseToKebabCase;
|
|
699
704
|
exports.todo = todo;
|
|
700
705
|
exports.trimPrefix = trimPrefix;
|
|
701
706
|
exports.trimSuffix = trimSuffix;
|
package/dist/index.mjs
CHANGED
|
@@ -440,6 +440,7 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
|
440
440
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
441
441
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
442
442
|
const WHITESPACE_REGEX = /\s/g;
|
|
443
|
+
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
443
444
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
444
445
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
445
446
|
function capitalizeFirstLetter(string) {
|
|
@@ -565,6 +566,9 @@ function removeNonPrintableCharacters(string) {
|
|
|
565
566
|
function removeWhitespace(string) {
|
|
566
567
|
return string.replaceAll(WHITESPACE_REGEX, "");
|
|
567
568
|
}
|
|
569
|
+
function titleCaseToKebabCase(string) {
|
|
570
|
+
return string.replaceAll(TITLE_CASE_BOUNDARY_REGEX, "-").replaceAll(/ +/g, "-").toLowerCase();
|
|
571
|
+
}
|
|
568
572
|
function trimPrefix(string, prefix, trimAll = false) {
|
|
569
573
|
if (trimAll) {
|
|
570
574
|
const regExp = new RegExp(`^${prefix}+`, "g");
|
|
@@ -605,4 +609,4 @@ function* tupleKeys(tuple) {
|
|
|
605
609
|
|
|
606
610
|
const ReadonlyMap = Map;
|
|
607
611
|
|
|
608
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, 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 };
|
|
612
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, 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
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "Helper functions for TypeScript projects.",
|
|
5
5
|
"homepage": "https://complete-ts.github.io/",
|
|
6
6
|
"bugs": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
+
"bun": "./src/index.ts",
|
|
18
19
|
"import": "./dist/index.mjs",
|
|
19
20
|
"require": "./dist/index.cjs"
|
|
20
21
|
}
|
|
@@ -25,17 +26,18 @@
|
|
|
25
26
|
"src"
|
|
26
27
|
],
|
|
27
28
|
"scripts": {
|
|
28
|
-
"build": "
|
|
29
|
+
"build": "bun run ./scripts/build.ts",
|
|
29
30
|
"docs": "typedoc",
|
|
30
|
-
"lint": "
|
|
31
|
-
"test": "
|
|
31
|
+
"lint": "bun run ./scripts/lint.ts",
|
|
32
|
+
"test": "bun test"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@types/node": "25.0.
|
|
35
|
+
"@types/node": "25.0.9",
|
|
35
36
|
"complete-node": "16.2.0",
|
|
36
37
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
38
|
+
"typedoc": "0.28.16",
|
|
37
39
|
"typescript": "5.9.3",
|
|
38
|
-
"typescript-eslint": "8.
|
|
40
|
+
"typescript-eslint": "8.53.0",
|
|
39
41
|
"unbuild": "3.6.1"
|
|
40
42
|
}
|
|
41
43
|
}
|
package/src/functions/assert.ts
CHANGED
|
@@ -25,7 +25,7 @@ export function assertArray(
|
|
|
25
25
|
export function assertArrayBoolean(
|
|
26
26
|
value: unknown,
|
|
27
27
|
msg: string,
|
|
28
|
-
): asserts value is
|
|
28
|
+
): asserts value is boolean[] {
|
|
29
29
|
assertArray(value, msg);
|
|
30
30
|
|
|
31
31
|
if (value.some((element) => typeof element !== "boolean")) {
|
|
@@ -40,7 +40,7 @@ export function assertArrayBoolean(
|
|
|
40
40
|
export function assertArrayNumber(
|
|
41
41
|
value: unknown,
|
|
42
42
|
msg: string,
|
|
43
|
-
): asserts value is
|
|
43
|
+
): asserts value is number[] {
|
|
44
44
|
assertArray(value, msg);
|
|
45
45
|
|
|
46
46
|
if (value.some((element) => typeof element !== "number")) {
|
|
@@ -70,7 +70,7 @@ export function assertArrayObject(
|
|
|
70
70
|
export function assertArrayString(
|
|
71
71
|
value: unknown,
|
|
72
72
|
msg: string,
|
|
73
|
-
): asserts value is
|
|
73
|
+
): asserts value is string[] {
|
|
74
74
|
assertArray(value, msg);
|
|
75
75
|
|
|
76
76
|
if (value.some((element) => typeof element !== "string")) {
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
hasDiacritic,
|
|
5
5
|
hasEmoji,
|
|
6
6
|
isKebabCase,
|
|
7
|
+
titleCaseToKebabCase,
|
|
7
8
|
trimPrefix,
|
|
8
9
|
trimSuffix,
|
|
9
10
|
} from "./string.js";
|
|
@@ -25,8 +26,8 @@ describe("hasEmoji", () => {
|
|
|
25
26
|
|
|
26
27
|
This page is for people who like [cake](https://en.wikipedia.org/wiki/Cake).
|
|
27
28
|
|
|
28
|
-
- Run \`
|
|
29
|
-
- Run \`
|
|
29
|
+
- Run \`command cake\` to get cake.
|
|
30
|
+
- Run \`command pie\` to get pie.
|
|
30
31
|
`),
|
|
31
32
|
false,
|
|
32
33
|
);
|
|
@@ -125,6 +126,40 @@ describe("isKebabCase", () => {
|
|
|
125
126
|
});
|
|
126
127
|
});
|
|
127
128
|
|
|
129
|
+
describe("titleCaseToKebabCase", () => {
|
|
130
|
+
test("should convert a single TitleCase word to lowercase", () => {
|
|
131
|
+
equal(titleCaseToKebabCase("Foo"), "foo");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("should convert two TitleCase words to kebab-case", () => {
|
|
135
|
+
equal(titleCaseToKebabCase("FooBar"), "foo-bar");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("should convert multiple TitleCase words to kebab-case", () => {
|
|
139
|
+
equal(titleCaseToKebabCase("FooBarBaz"), "foo-bar-baz");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("should handle an empty string", () => {
|
|
143
|
+
equal(titleCaseToKebabCase(""), "");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("should handle a string that is already lowercase", () => {
|
|
147
|
+
equal(titleCaseToKebabCase("foo"), "foo");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("should handle a string with digits", () => {
|
|
151
|
+
equal(titleCaseToKebabCase("Foo2Bar"), "foo2-bar");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("should handle spaces", () => {
|
|
155
|
+
equal(titleCaseToKebabCase("Foo Bar"), "foo-bar");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("should handle multiple spaces", () => {
|
|
159
|
+
equal(titleCaseToKebabCase("Foo Bar"), "foo-bar");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
128
163
|
describe("trimPrefix", () => {
|
|
129
164
|
test(() => {
|
|
130
165
|
equal(trimPrefix("foo", ""), "foo");
|
package/src/functions/string.ts
CHANGED
|
@@ -24,6 +24,7 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
|
24
24
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
25
25
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
26
26
|
const WHITESPACE_REGEX = /\s/g;
|
|
27
|
+
const TITLE_CASE_BOUNDARY_REGEX = /(?<=[\da-z])(?=[A-Z])/g;
|
|
27
28
|
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
28
29
|
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
29
30
|
|
|
@@ -311,6 +312,14 @@ export function removeWhitespace(string: string): string {
|
|
|
311
312
|
return string.replaceAll(WHITESPACE_REGEX, "");
|
|
312
313
|
}
|
|
313
314
|
|
|
315
|
+
/** Helper function to convert a string from TitleCase (PascalCase) to kebab-case. */
|
|
316
|
+
export function titleCaseToKebabCase(string: string): string {
|
|
317
|
+
return string
|
|
318
|
+
.replaceAll(TITLE_CASE_BOUNDARY_REGEX, "-")
|
|
319
|
+
.replaceAll(/ +/g, "-")
|
|
320
|
+
.toLowerCase();
|
|
321
|
+
}
|
|
322
|
+
|
|
314
323
|
/**
|
|
315
324
|
* Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
|
|
316
325
|
*
|