complete-common 2.3.1 → 2.4.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 +4 -0
- package/dist/functions/string.d.mts +4 -0
- package/dist/functions/string.d.ts +4 -0
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/index.cjs +10 -0
- package/dist/index.mjs +9 -1
- package/package.json +4 -4
- package/src/functions/string.test.ts +25 -1
- package/src/functions/string.ts +12 -0
|
@@ -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":["../../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;AAmBH,kEAAkE;AAClE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;;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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"}
|
package/dist/index.cjs
CHANGED
|
@@ -350,6 +350,8 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
|
350
350
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
351
351
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
352
352
|
const WHITESPACE_REGEX = /\s/g;
|
|
353
|
+
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
354
|
+
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
353
355
|
function capitalizeFirstLetter(string) {
|
|
354
356
|
if (string === "") {
|
|
355
357
|
return string;
|
|
@@ -394,10 +396,16 @@ function isFirstLetterCapitalized(string) {
|
|
|
394
396
|
function isKebabCase(string) {
|
|
395
397
|
return KEBAB_CASE_REGEX.test(string);
|
|
396
398
|
}
|
|
399
|
+
function isLowerCase(string) {
|
|
400
|
+
return LOWERCASE_REGEX.test(string);
|
|
401
|
+
}
|
|
397
402
|
function isSemanticVersion(versionString) {
|
|
398
403
|
const match = versionString.match(SEMANTIC_VERSION_REGEX);
|
|
399
404
|
return match !== null;
|
|
400
405
|
}
|
|
406
|
+
function isUpperCase(string) {
|
|
407
|
+
return UPPERCASE_REGEX.test(string);
|
|
408
|
+
}
|
|
401
409
|
function kebabCaseToCamelCase(string) {
|
|
402
410
|
return string.replaceAll(/-./g, (match) => {
|
|
403
411
|
const firstLetterOfWord = match[1];
|
|
@@ -551,8 +559,10 @@ exports.isEnumValue = isEnumValue;
|
|
|
551
559
|
exports.isFirstLetterCapitalized = isFirstLetterCapitalized;
|
|
552
560
|
exports.isKebabCase = isKebabCase;
|
|
553
561
|
exports.isKeyOf = isKeyOf;
|
|
562
|
+
exports.isLowerCase = isLowerCase;
|
|
554
563
|
exports.isObject = isObject;
|
|
555
564
|
exports.isSemanticVersion = isSemanticVersion;
|
|
565
|
+
exports.isUpperCase = isUpperCase;
|
|
556
566
|
exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
|
|
557
567
|
exports.kebabCaseToPascalCase = kebabCaseToPascalCase;
|
|
558
568
|
exports.mapFilter = mapFilter;
|
package/dist/index.mjs
CHANGED
|
@@ -348,6 +348,8 @@ const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
|
348
348
|
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$/;
|
|
349
349
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
350
350
|
const WHITESPACE_REGEX = /\s/g;
|
|
351
|
+
const UPPERCASE_REGEX = /^[A-Z]*$/;
|
|
352
|
+
const LOWERCASE_REGEX = /^[a-z]*$/;
|
|
351
353
|
function capitalizeFirstLetter(string) {
|
|
352
354
|
if (string === "") {
|
|
353
355
|
return string;
|
|
@@ -392,10 +394,16 @@ function isFirstLetterCapitalized(string) {
|
|
|
392
394
|
function isKebabCase(string) {
|
|
393
395
|
return KEBAB_CASE_REGEX.test(string);
|
|
394
396
|
}
|
|
397
|
+
function isLowerCase(string) {
|
|
398
|
+
return LOWERCASE_REGEX.test(string);
|
|
399
|
+
}
|
|
395
400
|
function isSemanticVersion(versionString) {
|
|
396
401
|
const match = versionString.match(SEMANTIC_VERSION_REGEX);
|
|
397
402
|
return match !== null;
|
|
398
403
|
}
|
|
404
|
+
function isUpperCase(string) {
|
|
405
|
+
return UPPERCASE_REGEX.test(string);
|
|
406
|
+
}
|
|
399
407
|
function kebabCaseToCamelCase(string) {
|
|
400
408
|
return string.replaceAll(/-./g, (match) => {
|
|
401
409
|
const firstLetterOfWord = match[1];
|
|
@@ -503,4 +511,4 @@ function* tupleKeys(tuple) {
|
|
|
503
511
|
|
|
504
512
|
const ReadonlyMap = Map;
|
|
505
513
|
|
|
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 };
|
|
514
|
+
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, 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
|
+
"version": "2.4.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.
|
|
39
|
-
"complete-node": "7.
|
|
38
|
+
"@types/node": "24.0.14",
|
|
39
|
+
"complete-node": "7.4.0",
|
|
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.
|
|
43
|
+
"typescript-eslint": "8.37.0",
|
|
44
44
|
"unbuild": "3.5.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { equal } from "node:assert";
|
|
2
2
|
import test, { describe } from "node:test";
|
|
3
|
-
import {
|
|
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
|
+
});
|
package/src/functions/string.ts
CHANGED
|
@@ -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) => {
|