complete-common 1.1.2 → 1.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/assert.d.cts +8 -13
- package/dist/functions/assert.d.mts +8 -13
- package/dist/functions/assert.d.ts +8 -13
- package/dist/functions/assert.d.ts.map +1 -1
- package/dist/index.cjs +21 -15
- package/dist/index.mjs +18 -15
- package/package.json +3 -3
- package/src/functions/assert.ts +33 -18
- package/src/functions/string.ts +3 -3
- package/src/functions/types.ts +3 -3
|
@@ -3,16 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly object: (val: unknown) => val is object;
|
|
11
|
-
readonly array: (val: unknown) => val is unknown[];
|
|
12
|
-
readonly null: (val: unknown) => val is null;
|
|
13
|
-
readonly undefined: (val: unknown) => val is undefined;
|
|
14
|
-
readonly function: (val: unknown) => val is Function;
|
|
15
|
-
};
|
|
6
|
+
/** Helper function to throw an error if the provided value is not an array. */
|
|
7
|
+
export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
|
|
8
|
+
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
9
|
+
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
16
10
|
/**
|
|
17
11
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
18
12
|
*
|
|
@@ -29,6 +23,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
29
23
|
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
30
24
|
"The assertion is useless because the provided value does not contain null."
|
|
31
25
|
]): asserts value is Exclude<T, null>;
|
|
26
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
27
|
+
export declare function assertNumber(value: unknown, msg: string): asserts value is number;
|
|
32
28
|
/**
|
|
33
29
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
34
30
|
* record).
|
|
@@ -39,7 +35,6 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
39
35
|
* Under the hood, this function uses the `isObject` helper function.
|
|
40
36
|
*/
|
|
41
37
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
42
|
-
/** Helper function to throw an error if the provided value is not
|
|
43
|
-
export declare function
|
|
44
|
-
export {};
|
|
38
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
39
|
+
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
45
40
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -3,16 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly object: (val: unknown) => val is object;
|
|
11
|
-
readonly array: (val: unknown) => val is unknown[];
|
|
12
|
-
readonly null: (val: unknown) => val is null;
|
|
13
|
-
readonly undefined: (val: unknown) => val is undefined;
|
|
14
|
-
readonly function: (val: unknown) => val is Function;
|
|
15
|
-
};
|
|
6
|
+
/** Helper function to throw an error if the provided value is not an array. */
|
|
7
|
+
export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
|
|
8
|
+
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
9
|
+
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
16
10
|
/**
|
|
17
11
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
18
12
|
*
|
|
@@ -29,6 +23,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
29
23
|
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
30
24
|
"The assertion is useless because the provided value does not contain null."
|
|
31
25
|
]): asserts value is Exclude<T, null>;
|
|
26
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
27
|
+
export declare function assertNumber(value: unknown, msg: string): asserts value is number;
|
|
32
28
|
/**
|
|
33
29
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
34
30
|
* record).
|
|
@@ -39,7 +35,6 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
39
35
|
* Under the hood, this function uses the `isObject` helper function.
|
|
40
36
|
*/
|
|
41
37
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
42
|
-
/** Helper function to throw an error if the provided value is not
|
|
43
|
-
export declare function
|
|
44
|
-
export {};
|
|
38
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
39
|
+
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
45
40
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -3,16 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly object: (val: unknown) => val is object;
|
|
11
|
-
readonly array: (val: unknown) => val is unknown[];
|
|
12
|
-
readonly null: (val: unknown) => val is null;
|
|
13
|
-
readonly undefined: (val: unknown) => val is undefined;
|
|
14
|
-
readonly function: (val: unknown) => val is Function;
|
|
15
|
-
};
|
|
6
|
+
/** Helper function to throw an error if the provided value is not an array. */
|
|
7
|
+
export declare function assertArray(value: unknown, msg: string): asserts value is unknown[];
|
|
8
|
+
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
9
|
+
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
16
10
|
/**
|
|
17
11
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
18
12
|
*
|
|
@@ -29,6 +23,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
29
23
|
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
30
24
|
"The assertion is useless because the provided value does not contain null."
|
|
31
25
|
]): asserts value is Exclude<T, null>;
|
|
26
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
27
|
+
export declare function assertNumber(value: unknown, msg: string): asserts value is number;
|
|
32
28
|
/**
|
|
33
29
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
34
30
|
* record).
|
|
@@ -39,7 +35,6 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
39
35
|
* Under the hood, this function uses the `isObject` helper function.
|
|
40
36
|
*/
|
|
41
37
|
export declare function assertObject(value: unknown, msg: string): asserts value is Record<string, unknown>;
|
|
42
|
-
/** Helper function to throw an error if the provided value is not
|
|
43
|
-
export declare function
|
|
44
|
-
export {};
|
|
38
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
39
|
+
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
45
40
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,+EAA+E;AAC/E,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,EAAE,CAI5B;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,CAI1B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAC7B,CAAC,MAAM,CAAC,GACR;IACE,iFAAiF;CAClF,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,CAIxC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,CAAC,GACR;IACE,4EAA4E;CAC7E,GACJ,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,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"}
|
package/dist/index.cjs
CHANGED
|
@@ -10,17 +10,16 @@ function isObject(variable) {
|
|
|
10
10
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
13
|
+
function assertArray(value, msg) {
|
|
14
|
+
if (!Array.isArray(value)) {
|
|
15
|
+
throw new TypeError(msg);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function assertBoolean(value, msg) {
|
|
19
|
+
if (typeof value !== "boolean") {
|
|
20
|
+
throw new TypeError(msg);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
24
23
|
function assertDefined(value, ...[msg]) {
|
|
25
24
|
if (value === void 0) {
|
|
26
25
|
throw new TypeError(msg);
|
|
@@ -31,14 +30,18 @@ function assertNotNull(value, ...[msg]) {
|
|
|
31
30
|
throw new TypeError(msg);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
33
|
+
function assertNumber(value, msg) {
|
|
34
|
+
if (typeof value !== "number") {
|
|
35
|
+
throw new TypeError(msg);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
34
38
|
function assertObject(value, msg) {
|
|
35
39
|
if (!isObject(value)) {
|
|
36
40
|
throw new TypeError(msg);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
if (!validationFunction(value)) {
|
|
43
|
+
function assertString(value, msg) {
|
|
44
|
+
if (typeof value !== "string") {
|
|
42
45
|
throw new TypeError(msg);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -512,10 +515,13 @@ exports.arrayCopyTwoDimensional = arrayCopyTwoDimensional;
|
|
|
512
515
|
exports.arrayEquals = arrayEquals;
|
|
513
516
|
exports.arrayRemove = arrayRemove;
|
|
514
517
|
exports.arrayRemoveInPlace = arrayRemoveInPlace;
|
|
518
|
+
exports.assertArray = assertArray;
|
|
519
|
+
exports.assertBoolean = assertBoolean;
|
|
515
520
|
exports.assertDefined = assertDefined;
|
|
516
521
|
exports.assertNotNull = assertNotNull;
|
|
522
|
+
exports.assertNumber = assertNumber;
|
|
517
523
|
exports.assertObject = assertObject;
|
|
518
|
-
exports.
|
|
524
|
+
exports.assertString = assertString;
|
|
519
525
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
520
526
|
exports.clamp = clamp;
|
|
521
527
|
exports.combineSets = combineSets;
|
package/dist/index.mjs
CHANGED
|
@@ -8,17 +8,16 @@ function isObject(variable) {
|
|
|
8
8
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
11
|
+
function assertArray(value, msg) {
|
|
12
|
+
if (!Array.isArray(value)) {
|
|
13
|
+
throw new TypeError(msg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function assertBoolean(value, msg) {
|
|
17
|
+
if (typeof value !== "boolean") {
|
|
18
|
+
throw new TypeError(msg);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
22
21
|
function assertDefined(value, ...[msg]) {
|
|
23
22
|
if (value === void 0) {
|
|
24
23
|
throw new TypeError(msg);
|
|
@@ -29,14 +28,18 @@ function assertNotNull(value, ...[msg]) {
|
|
|
29
28
|
throw new TypeError(msg);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
31
|
+
function assertNumber(value, msg) {
|
|
32
|
+
if (typeof value !== "number") {
|
|
33
|
+
throw new TypeError(msg);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
32
36
|
function assertObject(value, msg) {
|
|
33
37
|
if (!isObject(value)) {
|
|
34
38
|
throw new TypeError(msg);
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
if (!validationFunction(value)) {
|
|
41
|
+
function assertString(value, msg) {
|
|
42
|
+
if (typeof value !== "string") {
|
|
40
43
|
throw new TypeError(msg);
|
|
41
44
|
}
|
|
42
45
|
}
|
|
@@ -500,4 +503,4 @@ function* tupleKeys(tuple) {
|
|
|
500
503
|
|
|
501
504
|
const ReadonlyMap = Map;
|
|
502
505
|
|
|
503
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertDefined, assertNotNull, assertObject,
|
|
506
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertArray, assertBoolean, assertDefined, 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, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToReadonlySet, objectKeysToSet, objectToMap, objectToReadonlyMap, objectToReverseMap, objectToReverseReadonlyMap, objectValuesToReadonlySet, 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": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Helper functions for TypeScript projects.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://complete-ts.github.io/",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "22.13.5",
|
|
39
|
-
"complete-node": "3.1.
|
|
39
|
+
"complete-node": "3.1.6",
|
|
40
40
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
41
41
|
"glob": "11.0.1",
|
|
42
42
|
"typescript": "5.7.3",
|
|
43
43
|
"typescript-eslint": "8.25.0",
|
|
44
|
-
"unbuild": "3.
|
|
44
|
+
"unbuild": "3.5.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/functions/assert.ts
CHANGED
|
@@ -6,18 +6,25 @@
|
|
|
6
6
|
|
|
7
7
|
import { isObject } from "./types.js";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
/** Helper function to throw an error if the provided value is not an array. */
|
|
10
|
+
export function assertArray(
|
|
11
|
+
value: unknown,
|
|
12
|
+
msg: string,
|
|
13
|
+
): asserts value is unknown[] {
|
|
14
|
+
if (!Array.isArray(value)) {
|
|
15
|
+
throw new TypeError(msg);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
20
|
+
export function assertBoolean(
|
|
21
|
+
value: unknown,
|
|
22
|
+
msg: string,
|
|
23
|
+
): asserts value is boolean {
|
|
24
|
+
if (typeof value !== "boolean") {
|
|
25
|
+
throw new TypeError(msg);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
21
28
|
|
|
22
29
|
/**
|
|
23
30
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
@@ -55,6 +62,16 @@ export function assertNotNull<T>(
|
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
|
|
65
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
66
|
+
export function assertNumber(
|
|
67
|
+
value: unknown,
|
|
68
|
+
msg: string,
|
|
69
|
+
): asserts value is number {
|
|
70
|
+
if (typeof value !== "number") {
|
|
71
|
+
throw new TypeError(msg);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
58
75
|
/**
|
|
59
76
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
60
77
|
* record).
|
|
@@ -73,14 +90,12 @@ export function assertObject(
|
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
92
|
|
|
76
|
-
/** Helper function to throw an error if the provided value is not
|
|
77
|
-
export function
|
|
93
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
94
|
+
export function assertString(
|
|
78
95
|
value: unknown,
|
|
79
|
-
type: keyof typeof TYPES_TO_VALIDATION_FUNCTIONS,
|
|
80
96
|
msg: string,
|
|
81
|
-
): asserts value is
|
|
82
|
-
|
|
83
|
-
if (!validationFunction(value)) {
|
|
97
|
+
): asserts value is string {
|
|
98
|
+
if (typeof value !== "string") {
|
|
84
99
|
throw new TypeError(msg);
|
|
85
100
|
}
|
|
86
101
|
}
|
package/src/functions/string.ts
CHANGED
|
@@ -199,9 +199,9 @@ export function parseSemanticVersion(versionString: string):
|
|
|
199
199
|
const patchVersion = parseIntSafe(patch);
|
|
200
200
|
|
|
201
201
|
if (
|
|
202
|
-
majorVersion === undefined
|
|
203
|
-
minorVersion === undefined
|
|
204
|
-
patchVersion === undefined
|
|
202
|
+
majorVersion === undefined
|
|
203
|
+
|| minorVersion === undefined
|
|
204
|
+
|| patchVersion === undefined
|
|
205
205
|
) {
|
|
206
206
|
return undefined;
|
|
207
207
|
}
|
package/src/functions/types.ts
CHANGED
|
@@ -14,8 +14,8 @@ export function isObject(
|
|
|
14
14
|
variable: unknown,
|
|
15
15
|
): variable is Record<string, unknown> {
|
|
16
16
|
return (
|
|
17
|
-
typeof variable === "object"
|
|
18
|
-
variable !== null
|
|
19
|
-
!Array.isArray(variable)
|
|
17
|
+
typeof variable === "object"
|
|
18
|
+
&& variable !== null
|
|
19
|
+
&& !Array.isArray(variable)
|
|
20
20
|
);
|
|
21
21
|
}
|