complete-common 2.1.0 → 2.3.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/array.d.cts +8 -2
- package/dist/functions/array.d.mts +8 -2
- package/dist/functions/array.d.ts +8 -2
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/index.cjs +9 -2
- package/dist/index.mjs +9 -3
- package/package.json +6 -6
- package/src/functions/array.ts +15 -3
- package/src/functions/string.test.ts +66 -1
- package/src/functions/string.ts +5 -5
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { WidenLiteral } from "../
|
|
6
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to copy a two-dimensional array. Note that the sub-arrays will only be shallow
|
|
9
9
|
* copied (using the spread operator).
|
|
10
10
|
*/
|
|
11
|
-
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): readonly T[]
|
|
11
|
+
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): ReadonlyArray<readonly T[]>;
|
|
12
12
|
/**
|
|
13
13
|
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
14
14
|
* only performs a shallow comparison.
|
|
@@ -74,6 +74,12 @@ export declare function getRandomArrayIndex(array: readonly unknown[], exception
|
|
|
74
74
|
* `as const` assertion.
|
|
75
75
|
*/
|
|
76
76
|
export declare function includes<T, TupleElement extends WidenLiteral<T>>(array: readonly TupleElement[], searchElement: WidenLiteral<T>): searchElement is TupleElement;
|
|
77
|
+
/**
|
|
78
|
+
* Similar to the `Array.includes` method, but accepts a variadic amount of search elements.
|
|
79
|
+
*
|
|
80
|
+
* @returns True if any of the elements are found, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
export declare function includesAny<T>(array: readonly T[], ...searchElements: readonly T[]): boolean;
|
|
77
83
|
/** A wrapper around `Array.isArray` that narrows to `unknown[]` instead of `any[]`. */
|
|
78
84
|
export declare function isArray(arg: unknown): arg is unknown[];
|
|
79
85
|
/** Initializes an array with all elements containing the specified default value. */
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { WidenLiteral } from "../
|
|
6
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to copy a two-dimensional array. Note that the sub-arrays will only be shallow
|
|
9
9
|
* copied (using the spread operator).
|
|
10
10
|
*/
|
|
11
|
-
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): readonly T[]
|
|
11
|
+
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): ReadonlyArray<readonly T[]>;
|
|
12
12
|
/**
|
|
13
13
|
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
14
14
|
* only performs a shallow comparison.
|
|
@@ -74,6 +74,12 @@ export declare function getRandomArrayIndex(array: readonly unknown[], exception
|
|
|
74
74
|
* `as const` assertion.
|
|
75
75
|
*/
|
|
76
76
|
export declare function includes<T, TupleElement extends WidenLiteral<T>>(array: readonly TupleElement[], searchElement: WidenLiteral<T>): searchElement is TupleElement;
|
|
77
|
+
/**
|
|
78
|
+
* Similar to the `Array.includes` method, but accepts a variadic amount of search elements.
|
|
79
|
+
*
|
|
80
|
+
* @returns True if any of the elements are found, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
export declare function includesAny<T>(array: readonly T[], ...searchElements: readonly T[]): boolean;
|
|
77
83
|
/** A wrapper around `Array.isArray` that narrows to `unknown[]` instead of `any[]`. */
|
|
78
84
|
export declare function isArray(arg: unknown): arg is unknown[];
|
|
79
85
|
/** Initializes an array with all elements containing the specified default value. */
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { WidenLiteral } from "../
|
|
6
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to copy a two-dimensional array. Note that the sub-arrays will only be shallow
|
|
9
9
|
* copied (using the spread operator).
|
|
10
10
|
*/
|
|
11
|
-
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): readonly T[]
|
|
11
|
+
export declare function arrayCopyTwoDimensional<T>(array: ReadonlyArray<readonly T[]>): ReadonlyArray<readonly T[]>;
|
|
12
12
|
/**
|
|
13
13
|
* Helper function for determining if two arrays contain the exact same elements. Note that this
|
|
14
14
|
* only performs a shallow comparison.
|
|
@@ -74,6 +74,12 @@ export declare function getRandomArrayIndex(array: readonly unknown[], exception
|
|
|
74
74
|
* `as const` assertion.
|
|
75
75
|
*/
|
|
76
76
|
export declare function includes<T, TupleElement extends WidenLiteral<T>>(array: readonly TupleElement[], searchElement: WidenLiteral<T>): searchElement is TupleElement;
|
|
77
|
+
/**
|
|
78
|
+
* Similar to the `Array.includes` method, but accepts a variadic amount of search elements.
|
|
79
|
+
*
|
|
80
|
+
* @returns True if any of the elements are found, false otherwise.
|
|
81
|
+
*/
|
|
82
|
+
export declare function includesAny<T>(array: readonly T[], ...searchElements: readonly T[]): boolean;
|
|
77
83
|
/** A wrapper around `Array.isArray` that narrows to `unknown[]` instead of `any[]`. */
|
|
78
84
|
export declare function isArray(arg: unknown): arg is unknown[];
|
|
79
85
|
/** Initializes an array with all elements containing the specified default value. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/functions/array.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
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;;;GAG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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"}
|
|
@@ -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;AAiBH,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,M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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
|
@@ -132,7 +132,7 @@ function arrayRemoveInPlace(array, ...elementsToRemove) {
|
|
|
132
132
|
return removedElements;
|
|
133
133
|
}
|
|
134
134
|
function emptyArray(array) {
|
|
135
|
-
array.splice(0
|
|
135
|
+
array.splice(0);
|
|
136
136
|
}
|
|
137
137
|
function filterMap(array, func) {
|
|
138
138
|
const filteredArray = [];
|
|
@@ -171,6 +171,9 @@ function includes(array, searchElement) {
|
|
|
171
171
|
const widenedArray = array;
|
|
172
172
|
return widenedArray.includes(searchElement);
|
|
173
173
|
}
|
|
174
|
+
function includesAny(array, ...searchElements) {
|
|
175
|
+
return searchElements.some((element) => array.includes(element));
|
|
176
|
+
}
|
|
174
177
|
function isArray(arg) {
|
|
175
178
|
return Array.isArray(arg);
|
|
176
179
|
}
|
|
@@ -344,7 +347,7 @@ function todo(...args) {
|
|
|
344
347
|
const DIACRITIC_REGEX = /\p{Diacritic}/u;
|
|
345
348
|
const EMOJI_REGEX = /(\p{Extended_Pictographic}|\p{Emoji_Component})/u;
|
|
346
349
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
347
|
-
const KEBAB_CASE_REGEX = /^
|
|
350
|
+
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$|^$/;
|
|
348
351
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
349
352
|
const WHITESPACE_REGEX = /\s/g;
|
|
350
353
|
function capitalizeFirstLetter(string) {
|
|
@@ -389,6 +392,9 @@ function isFirstLetterCapitalized(string) {
|
|
|
389
392
|
return FIRST_LETTER_CAPITALIZED_REGEX.test(string);
|
|
390
393
|
}
|
|
391
394
|
function isKebabCase(string) {
|
|
395
|
+
if (string === "") {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
392
398
|
return KEBAB_CASE_REGEX.test(string);
|
|
393
399
|
}
|
|
394
400
|
function isSemanticVersion(versionString) {
|
|
@@ -541,6 +547,7 @@ exports.hasEmoji = hasEmoji;
|
|
|
541
547
|
exports.hasWhitespace = hasWhitespace;
|
|
542
548
|
exports.iRange = iRange;
|
|
543
549
|
exports.includes = includes;
|
|
550
|
+
exports.includesAny = includesAny;
|
|
544
551
|
exports.interfaceSatisfiesEnum = interfaceSatisfiesEnum;
|
|
545
552
|
exports.isArray = isArray;
|
|
546
553
|
exports.isEnumValue = isEnumValue;
|
package/dist/index.mjs
CHANGED
|
@@ -130,7 +130,7 @@ function arrayRemoveInPlace(array, ...elementsToRemove) {
|
|
|
130
130
|
return removedElements;
|
|
131
131
|
}
|
|
132
132
|
function emptyArray(array) {
|
|
133
|
-
array.splice(0
|
|
133
|
+
array.splice(0);
|
|
134
134
|
}
|
|
135
135
|
function filterMap(array, func) {
|
|
136
136
|
const filteredArray = [];
|
|
@@ -169,6 +169,9 @@ function includes(array, searchElement) {
|
|
|
169
169
|
const widenedArray = array;
|
|
170
170
|
return widenedArray.includes(searchElement);
|
|
171
171
|
}
|
|
172
|
+
function includesAny(array, ...searchElements) {
|
|
173
|
+
return searchElements.some((element) => array.includes(element));
|
|
174
|
+
}
|
|
172
175
|
function isArray(arg) {
|
|
173
176
|
return Array.isArray(arg);
|
|
174
177
|
}
|
|
@@ -342,7 +345,7 @@ function todo(...args) {
|
|
|
342
345
|
const DIACRITIC_REGEX = /\p{Diacritic}/u;
|
|
343
346
|
const EMOJI_REGEX = /(\p{Extended_Pictographic}|\p{Emoji_Component})/u;
|
|
344
347
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
345
|
-
const KEBAB_CASE_REGEX = /^
|
|
348
|
+
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$|^$/;
|
|
346
349
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
347
350
|
const WHITESPACE_REGEX = /\s/g;
|
|
348
351
|
function capitalizeFirstLetter(string) {
|
|
@@ -387,6 +390,9 @@ function isFirstLetterCapitalized(string) {
|
|
|
387
390
|
return FIRST_LETTER_CAPITALIZED_REGEX.test(string);
|
|
388
391
|
}
|
|
389
392
|
function isKebabCase(string) {
|
|
393
|
+
if (string === "") {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
390
396
|
return KEBAB_CASE_REGEX.test(string);
|
|
391
397
|
}
|
|
392
398
|
function isSemanticVersion(versionString) {
|
|
@@ -500,4 +506,4 @@ function* tupleKeys(tuple) {
|
|
|
500
506
|
|
|
501
507
|
const ReadonlyMap = Map;
|
|
502
508
|
|
|
503
|
-
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, 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 };
|
|
509
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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": "
|
|
39
|
-
"complete-node": "
|
|
38
|
+
"@types/node": "24.0.3",
|
|
39
|
+
"complete-node": "7.0.2",
|
|
40
40
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
41
|
-
"glob": "11.0.
|
|
42
|
-
"typescript": "5.8.
|
|
43
|
-
"typescript-eslint": "8.
|
|
41
|
+
"glob": "11.0.3",
|
|
42
|
+
"typescript": "5.8.3",
|
|
43
|
+
"typescript-eslint": "8.34.1",
|
|
44
44
|
"unbuild": "3.5.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/functions/array.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { WidenLiteral } from "../index.js";
|
|
8
7
|
import { ReadonlySet } from "../types/ReadonlySet.js";
|
|
8
|
+
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
9
9
|
import { assertDefined } from "./assert.js";
|
|
10
10
|
import { getRandomInt } from "./random.js";
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ import { getRandomInt } from "./random.js";
|
|
|
15
15
|
*/
|
|
16
16
|
export function arrayCopyTwoDimensional<T>(
|
|
17
17
|
array: ReadonlyArray<readonly T[]>,
|
|
18
|
-
): readonly T[]
|
|
18
|
+
): ReadonlyArray<readonly T[]> {
|
|
19
19
|
const copiedArray: T[][] = [];
|
|
20
20
|
|
|
21
21
|
for (const subArray of array) {
|
|
@@ -99,7 +99,7 @@ export function arrayRemoveInPlace<T>(
|
|
|
99
99
|
/** Helper function to remove all of the elements in an array in-place. */
|
|
100
100
|
// eslint-disable-next-line complete/prefer-readonly-parameter-types
|
|
101
101
|
export function emptyArray(array: unknown[]): void {
|
|
102
|
-
array.splice(0
|
|
102
|
+
array.splice(0);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/**
|
|
@@ -194,6 +194,18 @@ export function includes<T, TupleElement extends WidenLiteral<T>>(
|
|
|
194
194
|
return widenedArray.includes(searchElement);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Similar to the `Array.includes` method, but accepts a variadic amount of search elements.
|
|
199
|
+
*
|
|
200
|
+
* @returns True if any of the elements are found, false otherwise.
|
|
201
|
+
*/
|
|
202
|
+
export function includesAny<T>(
|
|
203
|
+
array: readonly T[],
|
|
204
|
+
...searchElements: readonly T[]
|
|
205
|
+
): boolean {
|
|
206
|
+
return searchElements.some((element) => array.includes(element));
|
|
207
|
+
}
|
|
208
|
+
|
|
197
209
|
/** A wrapper around `Array.isArray` that narrows to `unknown[]` instead of `any[]`. */
|
|
198
210
|
export function isArray(arg: unknown): arg is unknown[] {
|
|
199
211
|
return Array.isArray(arg);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { equal } from "node:assert";
|
|
2
2
|
import test, { describe } from "node:test";
|
|
3
|
-
import { hasDiacritic, hasEmoji } from "./string.js";
|
|
3
|
+
import { hasDiacritic, hasEmoji, isKebabCase } from "./string.js";
|
|
4
4
|
|
|
5
5
|
describe("hasEmoji", () => {
|
|
6
6
|
test("should return true for string with emoji", () => {
|
|
@@ -40,3 +40,68 @@ describe("hasDiacritic", () => {
|
|
|
40
40
|
equal(hasDiacritic(""), false);
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
|
+
|
|
44
|
+
describe("isKebabCase", () => {
|
|
45
|
+
test("should return true for valid kebab-case strings", () => {
|
|
46
|
+
equal(isKebabCase("hello-world"), true);
|
|
47
|
+
equal(isKebabCase("lowercase"), true);
|
|
48
|
+
equal(isKebabCase("item-123-abc"), true);
|
|
49
|
+
equal(isKebabCase("section-1a"), true);
|
|
50
|
+
equal(isKebabCase("segment-1-2-3"), true);
|
|
51
|
+
equal(isKebabCase("1-2-3"), true);
|
|
52
|
+
equal(isKebabCase("12345"), true);
|
|
53
|
+
equal(isKebabCase("fix-k8s"), true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("should return false for strings with uppercase letters", () => {
|
|
57
|
+
equal(isKebabCase("HelloWorld"), false);
|
|
58
|
+
equal(isKebabCase("helloWorld"), false);
|
|
59
|
+
equal(isKebabCase("Hello-World"), false);
|
|
60
|
+
equal(isKebabCase("kebab-Case"), false);
|
|
61
|
+
equal(isKebabCase("HELLO-WORLD"), false);
|
|
62
|
+
equal(isKebabCase("UPPERCASE"), false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("should return false for strings with spaces", () => {
|
|
66
|
+
equal(isKebabCase("hello world"), false);
|
|
67
|
+
equal(isKebabCase(" hello-world"), false);
|
|
68
|
+
equal(isKebabCase("hello-world "), false);
|
|
69
|
+
equal(isKebabCase("hello - world"), false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("should return false for strings with underscores", () => {
|
|
73
|
+
equal(isKebabCase("hello_world"), false);
|
|
74
|
+
equal(isKebabCase("snake_case_example"), false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("should return false for strings with consecutive hyphens", () => {
|
|
78
|
+
equal(isKebabCase("hello--world"), false);
|
|
79
|
+
equal(isKebabCase("a--b--c"), false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("should return false for strings starting or ending with a hyphen", () => {
|
|
83
|
+
equal(isKebabCase("-hello-world"), false);
|
|
84
|
+
equal(isKebabCase("hello-world-"), false);
|
|
85
|
+
equal(isKebabCase("-start"), false);
|
|
86
|
+
equal(isKebabCase("end-"), false);
|
|
87
|
+
equal(isKebabCase("-"), false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("should return false for strings with special characters other than hyphens", () => {
|
|
91
|
+
equal(isKebabCase("hello-world!"), false);
|
|
92
|
+
equal(isKebabCase("test@example"), false);
|
|
93
|
+
equal(isKebabCase("kebab$case"), false);
|
|
94
|
+
equal(isKebabCase("has-#-symbol"), false);
|
|
95
|
+
equal(isKebabCase("dot.case"), false);
|
|
96
|
+
equal(isKebabCase("slash/case"), false);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("should return false for mixed separators", () => {
|
|
100
|
+
equal(isKebabCase("hello_world-foo"), false);
|
|
101
|
+
equal(isKebabCase("hello-world_bar"), false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("should return false for an empty string", () => {
|
|
105
|
+
equal(isKebabCase(""), false);
|
|
106
|
+
});
|
|
107
|
+
});
|
package/src/functions/string.ts
CHANGED
|
@@ -15,11 +15,7 @@ const DIACRITIC_REGEX = /\p{Diacritic}/u;
|
|
|
15
15
|
const EMOJI_REGEX = /(\p{Extended_Pictographic}|\p{Emoji_Component})/u;
|
|
16
16
|
|
|
17
17
|
const FIRST_LETTER_CAPITALIZED_REGEX = /^\p{Lu}/u;
|
|
18
|
-
|
|
19
|
-
/** From: https://github.com/expandjs/expandjs/blob/master/lib/kebabCaseRegex.js */
|
|
20
|
-
const KEBAB_CASE_REGEX =
|
|
21
|
-
/^([a-z](?!\d)|\d(?![a-z]))+(-?([a-z](?!\d)|\d(?![a-z])))*$|^$/;
|
|
22
|
-
|
|
18
|
+
const KEBAB_CASE_REGEX = /^[\da-z]+(?:-[\da-z]+)*$|^$/;
|
|
23
19
|
const SEMANTIC_VERSION_REGEX = /^v*(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/;
|
|
24
20
|
const WHITESPACE_REGEX = /\s/g;
|
|
25
21
|
|
|
@@ -113,6 +109,10 @@ export function isFirstLetterCapitalized(string: string): boolean {
|
|
|
113
109
|
|
|
114
110
|
/** Kebab case is the naming style of using all lowercase and hyphens, like "foo-bar". */
|
|
115
111
|
export function isKebabCase(string: string): boolean {
|
|
112
|
+
if (string === "") {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
116
|
return KEBAB_CASE_REGEX.test(string);
|
|
117
117
|
}
|
|
118
118
|
|