complete-common 2.14.1 → 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/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 +1 -1
- package/src/functions/string.test.ts +35 -0
- package/src/functions/string.ts +9 -0
|
@@ -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
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0BH,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,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MA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AAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMxE"}
|
package/dist/index.cjs
CHANGED
|
@@ -442,6 +442,7 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
|
442
442
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
443
443
|
const SEMANTIC_VERSION_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
|
@@ -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";
|
|
@@ -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
|
*
|