complete-common 2.9.0 → 2.11.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 +7 -0
- package/dist/functions/assert.d.mts +7 -0
- package/dist/functions/assert.d.ts +7 -0
- package/dist/functions/assert.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 -0
- package/dist/index.mjs +13 -1
- package/package.json +4 -4
- package/src/functions/assert.ts +27 -0
- 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.
|
|
@@ -16,6 +16,11 @@ export declare function assertArrayBoolean(value: unknown, msg: string): asserts
|
|
|
16
16
|
* a number.
|
|
17
17
|
*/
|
|
18
18
|
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is unknown[];
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
|
+
* an object (i.e. a TypeScript record).
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertArrayObject(value: unknown, msg: string): asserts value is Array<Record<string, unknown>>;
|
|
19
24
|
/**
|
|
20
25
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
26
|
* a string.
|
|
@@ -72,4 +77,6 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
72
77
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
73
78
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
74
79
|
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
80
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
81
|
+
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
75
82
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -16,6 +16,11 @@ export declare function assertArrayBoolean(value: unknown, msg: string): asserts
|
|
|
16
16
|
* a number.
|
|
17
17
|
*/
|
|
18
18
|
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is unknown[];
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
|
+
* an object (i.e. a TypeScript record).
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertArrayObject(value: unknown, msg: string): asserts value is Array<Record<string, unknown>>;
|
|
19
24
|
/**
|
|
20
25
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
26
|
* a string.
|
|
@@ -72,4 +77,6 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
72
77
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
73
78
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
74
79
|
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
80
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
81
|
+
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
75
82
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -16,6 +16,11 @@ export declare function assertArrayBoolean(value: unknown, msg: string): asserts
|
|
|
16
16
|
* a number.
|
|
17
17
|
*/
|
|
18
18
|
export declare function assertArrayNumber(value: unknown, msg: string): asserts value is unknown[];
|
|
19
|
+
/**
|
|
20
|
+
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
|
+
* an object (i.e. a TypeScript record).
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertArrayObject(value: unknown, msg: string): asserts value is Array<Record<string, unknown>>;
|
|
19
24
|
/**
|
|
20
25
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
21
26
|
* a string.
|
|
@@ -72,4 +77,6 @@ export declare function assertNumber(value: unknown, msg: string): asserts value
|
|
|
72
77
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
73
78
|
/** Helper function to throw an error if the provided value is not a string. */
|
|
74
79
|
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
80
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
81
|
+
export declare function assertStringNotEmpty(value: unknown, msg: string): asserts value is string;
|
|
75
82
|
//# 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;;;;GAIG;AACH,w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AE,IAAI,CAAC,CAInC;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI1C;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,kGAAkG;AAClG,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAMzB"}
|
|
@@ -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
|
@@ -53,6 +53,12 @@ function assertArrayNumber(value, msg) {
|
|
|
53
53
|
throw new TypeError(msg);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
function assertArrayObject(value, msg) {
|
|
57
|
+
assertArray(value, msg);
|
|
58
|
+
if (value.some((element) => !isObject(element))) {
|
|
59
|
+
throw new TypeError(msg);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
56
62
|
function assertArrayString(value, msg) {
|
|
57
63
|
assertArray(value, msg);
|
|
58
64
|
if (value.some((element) => typeof element !== "string")) {
|
|
@@ -104,6 +110,12 @@ function assertString(value, msg) {
|
|
|
104
110
|
throw new TypeError(msg);
|
|
105
111
|
}
|
|
106
112
|
}
|
|
113
|
+
function assertStringNotEmpty(value, msg) {
|
|
114
|
+
assertString(value, msg);
|
|
115
|
+
if (value === "") {
|
|
116
|
+
throw new TypeError(msg);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
107
119
|
|
|
108
120
|
function getRandomInt(min, max, exceptions = []) {
|
|
109
121
|
min = Math.ceil(min);
|
|
@@ -590,6 +602,7 @@ exports.arrayRemoveInPlace = arrayRemoveInPlace;
|
|
|
590
602
|
exports.assertArray = assertArray;
|
|
591
603
|
exports.assertArrayBoolean = assertArrayBoolean;
|
|
592
604
|
exports.assertArrayNumber = assertArrayNumber;
|
|
605
|
+
exports.assertArrayObject = assertArrayObject;
|
|
593
606
|
exports.assertArrayString = assertArrayString;
|
|
594
607
|
exports.assertBoolean = assertBoolean;
|
|
595
608
|
exports.assertDefined = assertDefined;
|
|
@@ -600,6 +613,7 @@ exports.assertNotNull = assertNotNull;
|
|
|
600
613
|
exports.assertNumber = assertNumber;
|
|
601
614
|
exports.assertObject = assertObject;
|
|
602
615
|
exports.assertString = assertString;
|
|
616
|
+
exports.assertStringNotEmpty = assertStringNotEmpty;
|
|
603
617
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
604
618
|
exports.clamp = clamp;
|
|
605
619
|
exports.combineSets = combineSets;
|
package/dist/index.mjs
CHANGED
|
@@ -51,6 +51,12 @@ function assertArrayNumber(value, msg) {
|
|
|
51
51
|
throw new TypeError(msg);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
function assertArrayObject(value, msg) {
|
|
55
|
+
assertArray(value, msg);
|
|
56
|
+
if (value.some((element) => !isObject(element))) {
|
|
57
|
+
throw new TypeError(msg);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
54
60
|
function assertArrayString(value, msg) {
|
|
55
61
|
assertArray(value, msg);
|
|
56
62
|
if (value.some((element) => typeof element !== "string")) {
|
|
@@ -102,6 +108,12 @@ function assertString(value, msg) {
|
|
|
102
108
|
throw new TypeError(msg);
|
|
103
109
|
}
|
|
104
110
|
}
|
|
111
|
+
function assertStringNotEmpty(value, msg) {
|
|
112
|
+
assertString(value, msg);
|
|
113
|
+
if (value === "") {
|
|
114
|
+
throw new TypeError(msg);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
105
117
|
|
|
106
118
|
function getRandomInt(min, max, exceptions = []) {
|
|
107
119
|
min = Math.ceil(min);
|
|
@@ -574,4 +586,4 @@ function* tupleKeys(tuple) {
|
|
|
574
586
|
|
|
575
587
|
const ReadonlyMap = Map;
|
|
576
588
|
|
|
577
|
-
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, 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 };
|
|
589
|
+
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, 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.11.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": "
|
|
34
|
+
"@types/node": "24.10.2",
|
|
35
|
+
"complete-node": "13.0.0",
|
|
36
36
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
37
37
|
"typescript": "5.9.3",
|
|
38
|
-
"typescript-eslint": "8.
|
|
38
|
+
"typescript-eslint": "8.49.0",
|
|
39
39
|
"unbuild": "3.6.1"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/functions/assert.ts
CHANGED
|
@@ -48,6 +48,21 @@ export function assertArrayNumber(
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Helper function to throw an error if the provided value is not an array with every element being
|
|
53
|
+
* an object (i.e. a TypeScript record).
|
|
54
|
+
*/
|
|
55
|
+
export function assertArrayObject(
|
|
56
|
+
value: unknown,
|
|
57
|
+
msg: string,
|
|
58
|
+
): asserts value is Array<Record<string, unknown>> {
|
|
59
|
+
assertArray(value, msg);
|
|
60
|
+
|
|
61
|
+
if (value.some((element) => !isObject(element))) {
|
|
62
|
+
throw new TypeError(msg);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
51
66
|
/**
|
|
52
67
|
* Helper function to throw an error if the provided value is not an array with every element being
|
|
53
68
|
* a string.
|
|
@@ -196,3 +211,15 @@ export function assertString(
|
|
|
196
211
|
throw new TypeError(msg);
|
|
197
212
|
}
|
|
198
213
|
}
|
|
214
|
+
|
|
215
|
+
/** Helper function to throw an error if the provided value is not a string or an empty string. */
|
|
216
|
+
export function assertStringNotEmpty(
|
|
217
|
+
value: unknown,
|
|
218
|
+
msg: string,
|
|
219
|
+
): asserts value is string {
|
|
220
|
+
assertString(value, msg);
|
|
221
|
+
|
|
222
|
+
if (value === "") {
|
|
223
|
+
throw new TypeError(msg);
|
|
224
|
+
}
|
|
225
|
+
}
|
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
|
*
|