complete-common 2.8.0 → 2.10.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/README.md +1 -1
- package/dist/functions/assert.d.cts +4 -0
- package/dist/functions/assert.d.mts +4 -0
- package/dist/functions/assert.d.ts +4 -0
- package/dist/functions/assert.d.ts.map +1 -1
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/functions/utils.d.cts +2 -2
- package/dist/functions/utils.d.mts +2 -2
- package/dist/functions/utils.d.ts +2 -2
- package/dist/index.cjs +14 -2
- package/dist/index.mjs +13 -3
- package/package.json +4 -4
- package/src/functions/assert.ts +24 -0
- package/src/functions/string.ts +1 -2
- package/src/functions/utils.ts +2 -2
package/README.md
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/complete-common)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`complete-common` is a library that contains basic helper functions for a typical [TypeScript](https://www.typescriptlang.org/) project, such as [`iRange`](/complete-common/functions/utils#irange).
|
|
6
6
|
|
|
7
7
|
Please see the [docs](https://complete-ts.github.io/complete-common) for more information.
|
|
@@ -42,6 +42,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
42
42
|
* should be more performant for enums with around 52 or more elements.
|
|
43
43
|
*/
|
|
44
44
|
export declare function assertEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, msg: string, set?: ReadonlySet<string | number>): asserts value is T[keyof T];
|
|
45
|
+
/** Helper function to throw an error if the provided value is not an integer. */
|
|
46
|
+
export declare function assertInteger(value: unknown, msg: string): asserts value is number;
|
|
45
47
|
/**
|
|
46
48
|
* Helper function to throw an error if the provided value is not an instance of the expected class.
|
|
47
49
|
*
|
|
@@ -70,4 +72,6 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
70
72
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
71
73
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
72
74
|
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
75
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
76
|
+
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
73
77
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -42,6 +42,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
42
42
|
* should be more performant for enums with around 52 or more elements.
|
|
43
43
|
*/
|
|
44
44
|
export declare function assertEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, msg: string, set?: ReadonlySet<string | number>): asserts value is T[keyof T];
|
|
45
|
+
/** Helper function to throw an error if the provided value is not an integer. */
|
|
46
|
+
export declare function assertInteger(value: unknown, msg: string): asserts value is number;
|
|
45
47
|
/**
|
|
46
48
|
* Helper function to throw an error if the provided value is not an instance of the expected class.
|
|
47
49
|
*
|
|
@@ -70,4 +72,6 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
70
72
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
71
73
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
72
74
|
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
75
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
76
|
+
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
73
77
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -42,6 +42,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
42
42
|
* should be more performant for enums with around 52 or more elements.
|
|
43
43
|
*/
|
|
44
44
|
export declare function assertEnumValue<T extends TranspiledEnum>(value: number | string, transpiledEnum: T, msg: string, set?: ReadonlySet<string | number>): asserts value is T[keyof T];
|
|
45
|
+
/** Helper function to throw an error if the provided value is not an integer. */
|
|
46
|
+
export declare function assertInteger(value: unknown, msg: string): asserts value is number;
|
|
45
47
|
/**
|
|
46
48
|
* Helper function to throw an error if the provided value is not an instance of the expected class.
|
|
47
49
|
*
|
|
@@ -70,4 +72,6 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
70
72
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
71
73
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
72
74
|
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
75
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
76
|
+
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
73
77
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -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,OAAO,EAAE,CAM5B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,EAAE,CAM5B;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,CAI1B;AAED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;;GAUG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBtD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GACtD;IACE,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IAErB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IAErB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACtB,GACD,SAAS,CAwBZ;AAGD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,wBAAgB,yBAAyB,CACvC,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"}
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function eRange(start: number, end?: number, increment?: number): Generator<number>;
|
|
35
35
|
/**
|
|
36
|
-
* Helper function to get an
|
|
37
|
-
* (The "i" in the function name stands for inclusive.)
|
|
36
|
+
* Helper function to get an iterator of of integers with the specified range, inclusive on both
|
|
37
|
+
* ends. (The "i" in the function name stands for inclusive.)
|
|
38
38
|
*
|
|
39
39
|
* If the end is lower than the start, then an empty range will be returned.
|
|
40
40
|
*
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function eRange(start: number, end?: number, increment?: number): Generator<number>;
|
|
35
35
|
/**
|
|
36
|
-
* Helper function to get an
|
|
37
|
-
* (The "i" in the function name stands for inclusive.)
|
|
36
|
+
* Helper function to get an iterator of of integers with the specified range, inclusive on both
|
|
37
|
+
* ends. (The "i" in the function name stands for inclusive.)
|
|
38
38
|
*
|
|
39
39
|
* If the end is lower than the start, then an empty range will be returned.
|
|
40
40
|
*
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function eRange(start: number, end?: number, increment?: number): Generator<number>;
|
|
35
35
|
/**
|
|
36
|
-
* Helper function to get an
|
|
37
|
-
* (The "i" in the function name stands for inclusive.)
|
|
36
|
+
* Helper function to get an iterator of of integers with the specified range, inclusive on both
|
|
37
|
+
* ends. (The "i" in the function name stands for inclusive.)
|
|
38
38
|
*
|
|
39
39
|
* If the end is lower than the start, then an empty range will be returned.
|
|
40
40
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -74,6 +74,11 @@ function assertEnumValue(value, transpiledEnum, msg, set) {
|
|
|
74
74
|
throw new TypeError(msg);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
function assertInteger(value, msg) {
|
|
78
|
+
if (!Number.isInteger(value)) {
|
|
79
|
+
throw new TypeError(msg);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
77
82
|
function assertIs(value, constructor, msg) {
|
|
78
83
|
if (!(value instanceof constructor)) {
|
|
79
84
|
throw new TypeError(msg);
|
|
@@ -99,6 +104,12 @@ function assertString(value, msg) {
|
|
|
99
104
|
throw new TypeError(msg);
|
|
100
105
|
}
|
|
101
106
|
}
|
|
107
|
+
function assertStringNotEmpty(value, msg) {
|
|
108
|
+
assertString(value, msg);
|
|
109
|
+
if (value === "") {
|
|
110
|
+
throw new TypeError(msg);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
102
113
|
|
|
103
114
|
function getRandomInt(min, max, exceptions = []) {
|
|
104
115
|
min = Math.ceil(min);
|
|
@@ -459,8 +470,7 @@ function isLowerCase(string) {
|
|
|
459
470
|
return LOWERCASE_REGEX.test(string);
|
|
460
471
|
}
|
|
461
472
|
function isSemanticVersion(versionString) {
|
|
462
|
-
|
|
463
|
-
return match !== null;
|
|
473
|
+
return SEMANTIC_VERSION_REGEX.test(versionString);
|
|
464
474
|
}
|
|
465
475
|
function isUpperCase(string) {
|
|
466
476
|
return UPPERCASE_REGEX.test(string);
|
|
@@ -590,11 +600,13 @@ exports.assertArrayString = assertArrayString;
|
|
|
590
600
|
exports.assertBoolean = assertBoolean;
|
|
591
601
|
exports.assertDefined = assertDefined;
|
|
592
602
|
exports.assertEnumValue = assertEnumValue;
|
|
603
|
+
exports.assertInteger = assertInteger;
|
|
593
604
|
exports.assertIs = assertIs;
|
|
594
605
|
exports.assertNotNull = assertNotNull;
|
|
595
606
|
exports.assertNumber = assertNumber;
|
|
596
607
|
exports.assertObject = assertObject;
|
|
597
608
|
exports.assertString = assertString;
|
|
609
|
+
exports.assertStringNotEmpty = assertStringNotEmpty;
|
|
598
610
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
599
611
|
exports.clamp = clamp;
|
|
600
612
|
exports.combineSets = combineSets;
|
package/dist/index.mjs
CHANGED
|
@@ -72,6 +72,11 @@ function assertEnumValue(value, transpiledEnum, msg, set) {
|
|
|
72
72
|
throw new TypeError(msg);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
function assertInteger(value, msg) {
|
|
76
|
+
if (!Number.isInteger(value)) {
|
|
77
|
+
throw new TypeError(msg);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
75
80
|
function assertIs(value, constructor, msg) {
|
|
76
81
|
if (!(value instanceof constructor)) {
|
|
77
82
|
throw new TypeError(msg);
|
|
@@ -97,6 +102,12 @@ function assertString(value, msg) {
|
|
|
97
102
|
throw new TypeError(msg);
|
|
98
103
|
}
|
|
99
104
|
}
|
|
105
|
+
function assertStringNotEmpty(value, msg) {
|
|
106
|
+
assertString(value, msg);
|
|
107
|
+
if (value === "") {
|
|
108
|
+
throw new TypeError(msg);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
100
111
|
|
|
101
112
|
function getRandomInt(min, max, exceptions = []) {
|
|
102
113
|
min = Math.ceil(min);
|
|
@@ -457,8 +468,7 @@ function isLowerCase(string) {
|
|
|
457
468
|
return LOWERCASE_REGEX.test(string);
|
|
458
469
|
}
|
|
459
470
|
function isSemanticVersion(versionString) {
|
|
460
|
-
|
|
461
|
-
return match !== null;
|
|
471
|
+
return SEMANTIC_VERSION_REGEX.test(versionString);
|
|
462
472
|
}
|
|
463
473
|
function isUpperCase(string) {
|
|
464
474
|
return UPPERCASE_REGEX.test(string);
|
|
@@ -570,4 +580,4 @@ function* tupleKeys(tuple) {
|
|
|
570
580
|
|
|
571
581
|
const ReadonlyMap = Map;
|
|
572
582
|
|
|
573
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertIs, 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, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, 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 };
|
|
583
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, 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, 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.10.0",
|
|
4
4
|
"description": "Helper functions for TypeScript projects.",
|
|
5
5
|
"homepage": "https://complete-ts.github.io/",
|
|
6
6
|
"bugs": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"test": "tsx --test"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/node": "24.
|
|
35
|
-
"complete-node": "12.
|
|
34
|
+
"@types/node": "24.10.1",
|
|
35
|
+
"complete-node": "12.3.0",
|
|
36
36
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
37
37
|
"typescript": "5.9.3",
|
|
38
|
-
"typescript-eslint": "8.
|
|
38
|
+
"typescript-eslint": "8.48.0",
|
|
39
39
|
"unbuild": "3.6.1"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/functions/assert.ts
CHANGED
|
@@ -112,6 +112,18 @@ export function assertEnumValue<T extends TranspiledEnum>(
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/** Helper function to throw an error if the provided value is not an integer. */
|
|
116
|
+
export function assertInteger(
|
|
117
|
+
value: unknown,
|
|
118
|
+
msg: string,
|
|
119
|
+
): asserts value is number {
|
|
120
|
+
// `Number.isInteger` will correctly return false for non-number variables such as strings,
|
|
121
|
+
// booleans, and so on.
|
|
122
|
+
if (!Number.isInteger(value)) {
|
|
123
|
+
throw new TypeError(msg);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
115
127
|
/**
|
|
116
128
|
* Helper function to throw an error if the provided value is not an instance of the expected class.
|
|
117
129
|
*
|
|
@@ -184,3 +196,15 @@ export function assertString(
|
|
|
184
196
|
throw new TypeError(msg);
|
|
185
197
|
}
|
|
186
198
|
}
|
|
199
|
+
|
|
200
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
201
|
+
export function assertStringNotEmpty(
|
|
202
|
+
value: unknown,
|
|
203
|
+
msg: string,
|
|
204
|
+
): asserts value is string {
|
|
205
|
+
assertString(value, msg);
|
|
206
|
+
|
|
207
|
+
if (value === "") {
|
|
208
|
+
throw new TypeError(msg);
|
|
209
|
+
}
|
|
210
|
+
}
|
package/src/functions/string.ts
CHANGED
|
@@ -140,8 +140,7 @@ export function isLowerCase(string: string): boolean {
|
|
|
140
140
|
* @see https://semver.org/
|
|
141
141
|
*/
|
|
142
142
|
export function isSemanticVersion(versionString: string): boolean {
|
|
143
|
-
|
|
144
|
-
return match !== null;
|
|
143
|
+
return SEMANTIC_VERSION_REGEX.test(versionString);
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
/** Helper function to test if a string contains only uppercase ASCII letters (A through Z). */
|
package/src/functions/utils.ts
CHANGED
|
@@ -54,8 +54,8 @@ export function* eRange(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Helper function to get an
|
|
58
|
-
* (The "i" in the function name stands for inclusive.)
|
|
57
|
+
* Helper function to get an iterator of of integers with the specified range, inclusive on both
|
|
58
|
+
* ends. (The "i" in the function name stands for inclusive.)
|
|
59
59
|
*
|
|
60
60
|
* If the end is lower than the start, then an empty range will be returned.
|
|
61
61
|
*
|