complete-common 1.1.2 → 1.2.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 +6 -13
- package/dist/functions/assert.d.mts +6 -13
- package/dist/functions/assert.d.ts +6 -13
- package/dist/functions/assert.d.ts.map +1 -1
- package/dist/index.cjs +15 -15
- package/dist/index.mjs +13 -15
- package/package.json +3 -3
- package/src/functions/assert.ts +23 -18
- package/src/functions/string.ts +3 -3
- package/src/functions/types.ts +3 -3
|
@@ -3,16 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly number: (val: unknown) => val is number;
|
|
9
|
-
readonly boolean: (val: unknown) => val is boolean;
|
|
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 a boolean. */
|
|
7
|
+
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
16
8
|
/**
|
|
17
9
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
18
10
|
*
|
|
@@ -29,6 +21,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
29
21
|
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
30
22
|
"The assertion is useless because the provided value does not contain null."
|
|
31
23
|
]): asserts value is Exclude<T, null>;
|
|
24
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
25
|
+
export declare function assertNumber(value: unknown, msg: string): asserts value is number;
|
|
32
26
|
/**
|
|
33
27
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
34
28
|
* record).
|
|
@@ -39,7 +33,6 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
39
33
|
* Under the hood, this function uses the `isObject` helper function.
|
|
40
34
|
*/
|
|
41
35
|
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 {};
|
|
36
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
37
|
+
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
45
38
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -3,16 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly number: (val: unknown) => val is number;
|
|
9
|
-
readonly boolean: (val: unknown) => val is boolean;
|
|
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 a boolean. */
|
|
7
|
+
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
16
8
|
/**
|
|
17
9
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
18
10
|
*
|
|
@@ -29,6 +21,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
29
21
|
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
30
22
|
"The assertion is useless because the provided value does not contain null."
|
|
31
23
|
]): asserts value is Exclude<T, null>;
|
|
24
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
25
|
+
export declare function assertNumber(value: unknown, msg: string): asserts value is number;
|
|
32
26
|
/**
|
|
33
27
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
34
28
|
* record).
|
|
@@ -39,7 +33,6 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
39
33
|
* Under the hood, this function uses the `isObject` helper function.
|
|
40
34
|
*/
|
|
41
35
|
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 {};
|
|
36
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
37
|
+
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
45
38
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -3,16 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly number: (val: unknown) => val is number;
|
|
9
|
-
readonly boolean: (val: unknown) => val is boolean;
|
|
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 a boolean. */
|
|
7
|
+
export declare function assertBoolean(value: unknown, msg: string): asserts value is boolean;
|
|
16
8
|
/**
|
|
17
9
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
18
10
|
*
|
|
@@ -29,6 +21,8 @@ export declare function assertDefined<T>(value: T, ...[msg]: [undefined] extends
|
|
|
29
21
|
export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T] ? [string] : [
|
|
30
22
|
"The assertion is useless because the provided value does not contain null."
|
|
31
23
|
]): asserts value is Exclude<T, null>;
|
|
24
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
25
|
+
export declare function assertNumber(value: unknown, msg: string): asserts value is number;
|
|
32
26
|
/**
|
|
33
27
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
34
28
|
* record).
|
|
@@ -39,7 +33,6 @@ export declare function assertNotNull<T>(value: T, ...[msg]: [null] extends [T]
|
|
|
39
33
|
* Under the hood, this function uses the `isObject` helper function.
|
|
40
34
|
*/
|
|
41
35
|
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 {};
|
|
36
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
37
|
+
export declare function assertString(value: unknown, msg: string): asserts value is string;
|
|
45
38
|
//# 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,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,11 @@ function isObject(variable) {
|
|
|
10
10
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
array: (val) => Array.isArray(val),
|
|
19
|
-
null: (val) => val === null,
|
|
20
|
-
undefined: (val) => val === void 0,
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
22
|
-
function: (val) => typeof val === "function"
|
|
23
|
-
};
|
|
13
|
+
function assertBoolean(value, msg) {
|
|
14
|
+
if (typeof value !== "boolean") {
|
|
15
|
+
throw new TypeError(msg);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
24
18
|
function assertDefined(value, ...[msg]) {
|
|
25
19
|
if (value === void 0) {
|
|
26
20
|
throw new TypeError(msg);
|
|
@@ -31,14 +25,18 @@ function assertNotNull(value, ...[msg]) {
|
|
|
31
25
|
throw new TypeError(msg);
|
|
32
26
|
}
|
|
33
27
|
}
|
|
28
|
+
function assertNumber(value, msg) {
|
|
29
|
+
if (typeof value !== "number") {
|
|
30
|
+
throw new TypeError(msg);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
34
33
|
function assertObject(value, msg) {
|
|
35
34
|
if (!isObject(value)) {
|
|
36
35
|
throw new TypeError(msg);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
if (!validationFunction(value)) {
|
|
38
|
+
function assertString(value, msg) {
|
|
39
|
+
if (typeof value !== "string") {
|
|
42
40
|
throw new TypeError(msg);
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -512,10 +510,12 @@ exports.arrayCopyTwoDimensional = arrayCopyTwoDimensional;
|
|
|
512
510
|
exports.arrayEquals = arrayEquals;
|
|
513
511
|
exports.arrayRemove = arrayRemove;
|
|
514
512
|
exports.arrayRemoveInPlace = arrayRemoveInPlace;
|
|
513
|
+
exports.assertBoolean = assertBoolean;
|
|
515
514
|
exports.assertDefined = assertDefined;
|
|
516
515
|
exports.assertNotNull = assertNotNull;
|
|
516
|
+
exports.assertNumber = assertNumber;
|
|
517
517
|
exports.assertObject = assertObject;
|
|
518
|
-
exports.
|
|
518
|
+
exports.assertString = assertString;
|
|
519
519
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
520
520
|
exports.clamp = clamp;
|
|
521
521
|
exports.combineSets = combineSets;
|
package/dist/index.mjs
CHANGED
|
@@ -8,17 +8,11 @@ function isObject(variable) {
|
|
|
8
8
|
return typeof variable === "object" && variable !== null && !Array.isArray(variable);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
array: (val) => Array.isArray(val),
|
|
17
|
-
null: (val) => val === null,
|
|
18
|
-
undefined: (val) => val === void 0,
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
20
|
-
function: (val) => typeof val === "function"
|
|
21
|
-
};
|
|
11
|
+
function assertBoolean(value, msg) {
|
|
12
|
+
if (typeof value !== "boolean") {
|
|
13
|
+
throw new TypeError(msg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
22
16
|
function assertDefined(value, ...[msg]) {
|
|
23
17
|
if (value === void 0) {
|
|
24
18
|
throw new TypeError(msg);
|
|
@@ -29,14 +23,18 @@ function assertNotNull(value, ...[msg]) {
|
|
|
29
23
|
throw new TypeError(msg);
|
|
30
24
|
}
|
|
31
25
|
}
|
|
26
|
+
function assertNumber(value, msg) {
|
|
27
|
+
if (typeof value !== "number") {
|
|
28
|
+
throw new TypeError(msg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
32
31
|
function assertObject(value, msg) {
|
|
33
32
|
if (!isObject(value)) {
|
|
34
33
|
throw new TypeError(msg);
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
if (!validationFunction(value)) {
|
|
36
|
+
function assertString(value, msg) {
|
|
37
|
+
if (typeof value !== "string") {
|
|
40
38
|
throw new TypeError(msg);
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -500,4 +498,4 @@ function* tupleKeys(tuple) {
|
|
|
500
498
|
|
|
501
499
|
const ReadonlyMap = Map;
|
|
502
500
|
|
|
503
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertDefined, assertNotNull, assertObject,
|
|
501
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, 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.2.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,15 @@
|
|
|
6
6
|
|
|
7
7
|
import { isObject } from "./types.js";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
19
|
-
function: (val: unknown): val is Function => typeof val === "function",
|
|
20
|
-
} as const;
|
|
9
|
+
/** Helper function to throw an error if the provided value is not a boolean. */
|
|
10
|
+
export function assertBoolean(
|
|
11
|
+
value: unknown,
|
|
12
|
+
msg: string,
|
|
13
|
+
): asserts value is boolean {
|
|
14
|
+
if (typeof value !== "boolean") {
|
|
15
|
+
throw new TypeError(msg);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
21
18
|
|
|
22
19
|
/**
|
|
23
20
|
* Helper function to throw an error if the provided value is equal to `undefined`.
|
|
@@ -55,6 +52,16 @@ export function assertNotNull<T>(
|
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
|
|
55
|
+
/** Helper function to throw an error if the provided value is not a number. */
|
|
56
|
+
export function assertNumber(
|
|
57
|
+
value: unknown,
|
|
58
|
+
msg: string,
|
|
59
|
+
): asserts value is number {
|
|
60
|
+
if (typeof value !== "number") {
|
|
61
|
+
throw new TypeError(msg);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
/**
|
|
59
66
|
* Helper function to throw an error if the provided value is not an object (i.e. a TypeScript
|
|
60
67
|
* record).
|
|
@@ -73,14 +80,12 @@ export function assertObject(
|
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
|
|
76
|
-
/** Helper function to throw an error if the provided value is not
|
|
77
|
-
export function
|
|
83
|
+
/** Helper function to throw an error if the provided value is not a string. */
|
|
84
|
+
export function assertString(
|
|
78
85
|
value: unknown,
|
|
79
|
-
type: keyof typeof TYPES_TO_VALIDATION_FUNCTIONS,
|
|
80
86
|
msg: string,
|
|
81
|
-
): asserts value is
|
|
82
|
-
|
|
83
|
-
if (!validationFunction(value)) {
|
|
87
|
+
): asserts value is string {
|
|
88
|
+
if (typeof value !== "string") {
|
|
84
89
|
throw new TypeError(msg);
|
|
85
90
|
}
|
|
86
91
|
}
|
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
|
}
|