@pawells/typescript-common 1.0.1 → 1.1.1
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 +177 -2
- package/build/array/array-chunk.d.ts +10 -4
- package/build/array/array-chunk.d.ts.map +1 -1
- package/build/array/array-chunk.js +10 -4
- package/build/array/array-chunk.js.map +1 -1
- package/build/array/array-contains.d.ts +11 -3
- package/build/array/array-contains.d.ts.map +1 -1
- package/build/array/array-contains.js +11 -3
- package/build/array/array-contains.js.map +1 -1
- package/build/array/array-group-by.d.ts +14 -5
- package/build/array/array-group-by.d.ts.map +1 -1
- package/build/array/array-group-by.js +14 -5
- package/build/array/array-group-by.js.map +1 -1
- package/build/array/array-shuffle.d.ts +12 -3
- package/build/array/array-shuffle.d.ts.map +1 -1
- package/build/array/array-shuffle.js +12 -3
- package/build/array/array-shuffle.js.map +1 -1
- package/build/array/assert.d.ts +115 -0
- package/build/array/assert.d.ts.map +1 -0
- package/build/array/assert.js +182 -0
- package/build/array/assert.js.map +1 -0
- package/build/array/index.d.ts +1 -0
- package/build/array/index.d.ts.map +1 -1
- package/build/array/index.js +1 -0
- package/build/array/index.js.map +1 -1
- package/build/array/unique.d.ts +13 -3
- package/build/array/unique.d.ts.map +1 -1
- package/build/array/unique.js +13 -3
- package/build/array/unique.js.map +1 -1
- package/build/asserts/errors.d.ts +129 -0
- package/build/asserts/errors.d.ts.map +1 -0
- package/build/asserts/errors.js +149 -0
- package/build/asserts/errors.js.map +1 -0
- package/build/asserts/generic.d.ts +436 -0
- package/build/asserts/generic.d.ts.map +1 -0
- package/build/asserts/generic.js +543 -0
- package/build/asserts/generic.js.map +1 -0
- package/build/asserts/index.d.ts +41 -0
- package/build/asserts/index.d.ts.map +1 -0
- package/build/asserts/index.js +41 -0
- package/build/asserts/index.js.map +1 -0
- package/build/asserts/internal-utils.d.ts +53 -0
- package/build/asserts/internal-utils.d.ts.map +1 -0
- package/build/asserts/internal-utils.js +108 -0
- package/build/asserts/internal-utils.js.map +1 -0
- package/build/asserts/types.d.ts +180 -0
- package/build/asserts/types.d.ts.map +1 -0
- package/build/asserts/types.js +2 -0
- package/build/asserts/types.js.map +1 -0
- package/build/asserts/utils.d.ts +92 -0
- package/build/asserts/utils.d.ts.map +1 -0
- package/build/asserts/utils.js +103 -0
- package/build/asserts/utils.js.map +1 -0
- package/build/boolean/assert.d.ts +66 -0
- package/build/boolean/assert.d.ts.map +1 -0
- package/build/boolean/assert.js +76 -0
- package/build/boolean/assert.js.map +1 -0
- package/build/boolean/index.d.ts +9 -0
- package/build/boolean/index.d.ts.map +1 -0
- package/build/boolean/index.js +9 -0
- package/build/boolean/index.js.map +1 -0
- package/build/enum/enum-entries.d.ts +8 -3
- package/build/enum/enum-entries.d.ts.map +1 -1
- package/build/enum/enum-entries.js +8 -3
- package/build/enum/enum-entries.js.map +1 -1
- package/build/enum/enum-key-by-value.d.ts +10 -5
- package/build/enum/enum-key-by-value.d.ts.map +1 -1
- package/build/enum/enum-key-by-value.js +10 -5
- package/build/enum/enum-key-by-value.js.map +1 -1
- package/build/enum/enum-keys.d.ts +12 -3
- package/build/enum/enum-keys.d.ts.map +1 -1
- package/build/enum/enum-keys.js +12 -3
- package/build/enum/enum-keys.js.map +1 -1
- package/build/enum/enum-safe-value.d.ts +11 -6
- package/build/enum/enum-safe-value.d.ts.map +1 -1
- package/build/enum/enum-safe-value.js +11 -6
- package/build/enum/enum-safe-value.js.map +1 -1
- package/build/enum/validate-enum-value.d.ts +10 -5
- package/build/enum/validate-enum-value.d.ts.map +1 -1
- package/build/enum/validate-enum-value.js +10 -5
- package/build/enum/validate-enum-value.js.map +1 -1
- package/build/index.d.ts +5 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +12 -0
- package/build/index.js.map +1 -1
- package/build/number/assert.d.ts +154 -0
- package/build/number/assert.d.ts.map +1 -0
- package/build/number/assert.js +153 -0
- package/build/number/assert.js.map +1 -0
- package/build/number/index.d.ts +9 -0
- package/build/number/index.d.ts.map +1 -0
- package/build/number/index.js +9 -0
- package/build/number/index.js.map +1 -0
- package/build/object/assert.d.ts +138 -0
- package/build/object/assert.d.ts.map +1 -0
- package/build/object/assert.js +204 -0
- package/build/object/assert.js.map +1 -0
- package/build/object/clone.d.ts +17 -6
- package/build/object/clone.d.ts.map +1 -1
- package/build/object/clone.js +17 -6
- package/build/object/clone.js.map +1 -1
- package/build/object/filter-cached.d.ts +15 -3
- package/build/object/filter-cached.d.ts.map +1 -1
- package/build/object/filter-cached.js +15 -3
- package/build/object/filter-cached.js.map +1 -1
- package/build/object/has-circular-reference.d.ts +12 -3
- package/build/object/has-circular-reference.d.ts.map +1 -1
- package/build/object/has-circular-reference.js +12 -3
- package/build/object/has-circular-reference.js.map +1 -1
- package/build/object/index.d.ts +1 -0
- package/build/object/index.d.ts.map +1 -1
- package/build/object/index.js +1 -0
- package/build/object/index.js.map +1 -1
- package/build/object/key-value-pairs.d.ts +11 -3
- package/build/object/key-value-pairs.d.ts.map +1 -1
- package/build/object/key-value-pairs.js +11 -3
- package/build/object/key-value-pairs.js.map +1 -1
- package/build/object/map-cached.d.ts +14 -3
- package/build/object/map-cached.d.ts.map +1 -1
- package/build/object/map-cached.js +14 -3
- package/build/object/map-cached.js.map +1 -1
- package/build/object/merge.d.ts +18 -7
- package/build/object/merge.d.ts.map +1 -1
- package/build/object/merge.js +18 -7
- package/build/object/merge.js.map +1 -1
- package/build/object/omit.d.ts +13 -4
- package/build/object/omit.d.ts.map +1 -1
- package/build/object/omit.js +13 -4
- package/build/object/omit.js.map +1 -1
- package/build/string/assert.d.ts +100 -0
- package/build/string/assert.d.ts.map +1 -0
- package/build/string/assert.js +185 -0
- package/build/string/assert.js.map +1 -0
- package/build/string/formatting.d.ts +10 -3
- package/build/string/formatting.d.ts.map +1 -1
- package/build/string/formatting.js +10 -3
- package/build/string/formatting.js.map +1 -1
- package/build/string/index.d.ts +1 -0
- package/build/string/index.d.ts.map +1 -1
- package/build/string/index.js +1 -0
- package/build/string/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SetExceptionClass, SetExceptionMessage, ThrowException } from '../asserts/utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when a value is not a valid boolean or fails a boolean assertion.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* throw new BooleanError('Value is not a valid boolean');
|
|
7
|
+
*/
|
|
8
|
+
export class BooleanError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message ?? 'Invalid Boolean');
|
|
11
|
+
this.name = 'BooleanError';
|
|
12
|
+
Object.setPrototypeOf(this, BooleanError.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Asserts that a value is a boolean primitive type.
|
|
17
|
+
*
|
|
18
|
+
* This function performs a strict type assertion that validates the provided value
|
|
19
|
+
* is of type 'boolean', ensuring it's either `true` or `false`. The assertion will
|
|
20
|
+
* reject truthy/falsy values that are not actual boolean primitives, making it
|
|
21
|
+
* ideal for type narrowing in TypeScript and runtime type validation.
|
|
22
|
+
*
|
|
23
|
+
* If the assertion fails, the function throws an exception and never returns.
|
|
24
|
+
* If the assertion passes, TypeScript will narrow the type to `boolean` for
|
|
25
|
+
* subsequent code execution.
|
|
26
|
+
*
|
|
27
|
+
* @param value - The value to validate and assert as a boolean primitive
|
|
28
|
+
* @param exception - Optional exception configuration for custom error handling.
|
|
29
|
+
* Can include custom error message, error type, or other metadata.
|
|
30
|
+
* @throws {Error} When value is not a boolean primitive. The specific error type
|
|
31
|
+
* depends on the exception configuration provided.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* Basic usage with valid boolean values:
|
|
35
|
+
* ```typescript
|
|
36
|
+
* AssertBoolean(true); // ✓ Passes - value is boolean true
|
|
37
|
+
* AssertBoolean(false); // ✓ Passes - value is boolean false
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* Assertion failures with non-boolean values:
|
|
42
|
+
* ```typescript
|
|
43
|
+
* AssertBoolean(1); // ✗ Throws - truthy number, not boolean
|
|
44
|
+
* AssertBoolean(0); // ✗ Throws - falsy number, not boolean
|
|
45
|
+
* AssertBoolean("true"); // ✗ Throws - string, not boolean
|
|
46
|
+
* AssertBoolean("false"); // ✗ Throws - string, not boolean
|
|
47
|
+
* AssertBoolean(null); // ✗ Throws - null, not boolean
|
|
48
|
+
* AssertBoolean(undefined); // ✗ Throws - undefined, not boolean
|
|
49
|
+
* AssertBoolean([]); // ✗ Throws - array, not boolean
|
|
50
|
+
* AssertBoolean({}); // ✗ Throws - object, not boolean
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* Using with custom exception handling:
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { AssertBoolean } from './boolean.js';
|
|
57
|
+
*
|
|
58
|
+
* // Custom error message
|
|
59
|
+
* AssertBoolean(value, { message: 'Expected a boolean value' });
|
|
60
|
+
*
|
|
61
|
+
* // Type narrowing after successful assertion
|
|
62
|
+
* function processValue(input: unknown) {
|
|
63
|
+
* AssertBoolean(input);
|
|
64
|
+
* // TypeScript now knows 'input' is boolean
|
|
65
|
+
* return input ? 'yes' : 'no';
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function AssertBoolean(value, exception = {}) {
|
|
70
|
+
SetExceptionClass(exception, BooleanError);
|
|
71
|
+
if (typeof value !== 'boolean') {
|
|
72
|
+
SetExceptionMessage(exception, `Expected boolean but received ${typeof value}: ${String(value)}`);
|
|
73
|
+
ThrowException(exception);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/boolean/assert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,iBAAiB,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,YAA8B,EAAE;IAC7E,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAChC,mBAAmB,CAAC,SAAS,EAAE,iCAAiC,OAAO,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClG,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/boolean/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/boolean/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,aAAa,CAAC"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { TEnumType, TEnumValue } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Returns non-numeric key-value pairs from an enum
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
3
|
+
* Returns non-numeric key-value pairs from an enum.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The enum type
|
|
6
|
+
* @param e - The enum object
|
|
7
|
+
* @returns Array of `[key, value]` tuples for non-numeric keys only
|
|
8
|
+
*
|
|
6
9
|
* @example
|
|
10
|
+
* ```typescript
|
|
7
11
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
8
12
|
* EnumEntries(Direction); // [['Up', 'UP'], ['Down', 'DOWN']]
|
|
13
|
+
* ```
|
|
9
14
|
*/
|
|
10
15
|
export declare function EnumEntries<T extends TEnumType = TEnumType>(e: T): [string, TEnumValue][];
|
|
11
16
|
//# sourceMappingURL=enum-entries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-entries.d.ts","sourceRoot":"","sources":["../../src/enum/enum-entries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"enum-entries.d.ts","sourceRoot":"","sources":["../../src/enum/enum-entries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAIzF"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns non-numeric key-value pairs from an enum
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Returns non-numeric key-value pairs from an enum.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The enum type
|
|
5
|
+
* @param e - The enum object
|
|
6
|
+
* @returns Array of `[key, value]` tuples for non-numeric keys only
|
|
7
|
+
*
|
|
5
8
|
* @example
|
|
9
|
+
* ```typescript
|
|
6
10
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
7
11
|
* EnumEntries(Direction); // [['Up', 'UP'], ['Down', 'DOWN']]
|
|
12
|
+
* ```
|
|
8
13
|
*/
|
|
9
14
|
export function EnumEntries(e) {
|
|
10
15
|
if (!e)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-entries.js","sourceRoot":"","sources":["../../src/enum/enum-entries.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"enum-entries.js","sourceRoot":"","sources":["../../src/enum/enum-entries.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAkC,CAAI;IAChE,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAElB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { TEnumType, TEnumValue } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Gets the enum key for a given value
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
3
|
+
* Gets the enum key for a given value.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The enum type
|
|
6
|
+
* @param e - The enum object
|
|
7
|
+
* @param value - The enum value to look up
|
|
8
|
+
* @returns The key corresponding to the value, or `undefined` if not found
|
|
9
|
+
*
|
|
7
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
8
12
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
9
|
-
* EnumKeyByValue(Direction, 'UP');
|
|
13
|
+
* EnumKeyByValue(Direction, 'UP'); // 'Up'
|
|
10
14
|
* EnumKeyByValue(Direction, 'INVALID'); // undefined
|
|
15
|
+
* ```
|
|
11
16
|
*/
|
|
12
17
|
export declare function EnumKeyByValue<T extends TEnumType = TEnumType>(e: T, value: TEnumValue): string | undefined;
|
|
13
18
|
//# sourceMappingURL=enum-key-by-value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-key-by-value.d.ts","sourceRoot":"","sources":["../../src/enum/enum-key-by-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD
|
|
1
|
+
{"version":3,"file":"enum-key-by-value.d.ts","sourceRoot":"","sources":["../../src/enum/enum-key-by-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAQ3G"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { EnumEntries } from './enum-entries.js';
|
|
2
2
|
/**
|
|
3
|
-
* Gets the enum key for a given value
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
3
|
+
* Gets the enum key for a given value.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The enum type
|
|
6
|
+
* @param e - The enum object
|
|
7
|
+
* @param value - The enum value to look up
|
|
8
|
+
* @returns The key corresponding to the value, or `undefined` if not found
|
|
9
|
+
*
|
|
7
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
8
12
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
9
|
-
* EnumKeyByValue(Direction, 'UP');
|
|
13
|
+
* EnumKeyByValue(Direction, 'UP'); // 'Up'
|
|
10
14
|
* EnumKeyByValue(Direction, 'INVALID'); // undefined
|
|
15
|
+
* ```
|
|
11
16
|
*/
|
|
12
17
|
export function EnumKeyByValue(e, value) {
|
|
13
18
|
if (value === null || typeof value === 'undefined' || !e)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-key-by-value.js","sourceRoot":"","sources":["../../src/enum/enum-key-by-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD
|
|
1
|
+
{"version":3,"file":"enum-key-by-value.js","sourceRoot":"","sources":["../../src/enum/enum-key-by-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAkC,CAAI,EAAE,KAAiB;IACtF,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAE3E,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC;IACvD,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAE3B,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns non-numeric keys from an enum object
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Returns non-numeric keys from an enum object.
|
|
3
|
+
*
|
|
4
|
+
* @template O - The enum object type
|
|
5
|
+
* @template K - The key type (defaults to `keyof O`)
|
|
6
|
+
* @param obj - The enum object
|
|
7
|
+
* @returns Array of enum keys (reverse-mapping numeric keys are excluded)
|
|
8
|
+
*
|
|
5
9
|
* @example
|
|
10
|
+
* ```typescript
|
|
6
11
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
7
12
|
* EnumKeys(Direction); // ['Up', 'Down']
|
|
13
|
+
*
|
|
14
|
+
* enum Status { Active = 0, Inactive = 1 }
|
|
15
|
+
* EnumKeys(Status); // ['Active', 'Inactive']
|
|
16
|
+
* ```
|
|
8
17
|
*/
|
|
9
18
|
export declare function EnumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[];
|
|
10
19
|
//# sourceMappingURL=enum-keys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-keys.d.ts","sourceRoot":"","sources":["../../src/enum/enum-keys.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"enum-keys.d.ts","sourceRoot":"","sources":["../../src/enum/enum-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAInF"}
|
package/build/enum/enum-keys.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns non-numeric keys from an enum object
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Returns non-numeric keys from an enum object.
|
|
3
|
+
*
|
|
4
|
+
* @template O - The enum object type
|
|
5
|
+
* @template K - The key type (defaults to `keyof O`)
|
|
6
|
+
* @param obj - The enum object
|
|
7
|
+
* @returns Array of enum keys (reverse-mapping numeric keys are excluded)
|
|
8
|
+
*
|
|
5
9
|
* @example
|
|
10
|
+
* ```typescript
|
|
6
11
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
7
12
|
* EnumKeys(Direction); // ['Up', 'Down']
|
|
13
|
+
*
|
|
14
|
+
* enum Status { Active = 0, Inactive = 1 }
|
|
15
|
+
* EnumKeys(Status); // ['Active', 'Inactive']
|
|
16
|
+
* ```
|
|
8
17
|
*/
|
|
9
18
|
export function EnumKeys(obj) {
|
|
10
19
|
if (!obj)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-keys.js","sourceRoot":"","sources":["../../src/enum/enum-keys.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"enum-keys.js","sourceRoot":"","sources":["../../src/enum/enum-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAgD,GAAM;IAC7E,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IAEpB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAQ,CAAC;AACvE,CAAC"}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { TEnumType, TEnumValue } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Gets an enum value safely
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
3
|
+
* Gets an enum value safely, returning a fallback if the value is not a valid enum member.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The enum type
|
|
6
|
+
* @param e - The enum object
|
|
7
|
+
* @param value - The value to check against the enum
|
|
8
|
+
* @param fallback - The fallback value to return if `value` is not a valid enum member
|
|
9
|
+
* @returns `value` if it is valid in the enum, otherwise `fallback`
|
|
10
|
+
*
|
|
8
11
|
* @example
|
|
12
|
+
* ```typescript
|
|
9
13
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
10
|
-
* EnumSafeValue(Direction, 'UP', 'DOWN');
|
|
14
|
+
* EnumSafeValue(Direction, 'UP', 'DOWN'); // 'UP'
|
|
11
15
|
* EnumSafeValue(Direction, 'INVALID', 'DOWN'); // 'DOWN'
|
|
16
|
+
* ```
|
|
12
17
|
*/
|
|
13
18
|
export declare function EnumSafeValue<T extends TEnumType = TEnumType>(e: T, value: TEnumValue, fallback: TEnumValue): TEnumValue;
|
|
14
19
|
//# sourceMappingURL=enum-safe-value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-safe-value.d.ts","sourceRoot":"","sources":["../../src/enum/enum-safe-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD
|
|
1
|
+
{"version":3,"file":"enum-safe-value.d.ts","sourceRoot":"","sources":["../../src/enum/enum-safe-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,GAAG,UAAU,CAExH"}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { ValidateEnumValue } from './validate-enum-value.js';
|
|
2
2
|
/**
|
|
3
|
-
* Gets an enum value safely
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
3
|
+
* Gets an enum value safely, returning a fallback if the value is not a valid enum member.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The enum type
|
|
6
|
+
* @param e - The enum object
|
|
7
|
+
* @param value - The value to check against the enum
|
|
8
|
+
* @param fallback - The fallback value to return if `value` is not a valid enum member
|
|
9
|
+
* @returns `value` if it is valid in the enum, otherwise `fallback`
|
|
10
|
+
*
|
|
8
11
|
* @example
|
|
12
|
+
* ```typescript
|
|
9
13
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
10
|
-
* EnumSafeValue(Direction, 'UP', 'DOWN');
|
|
14
|
+
* EnumSafeValue(Direction, 'UP', 'DOWN'); // 'UP'
|
|
11
15
|
* EnumSafeValue(Direction, 'INVALID', 'DOWN'); // 'DOWN'
|
|
16
|
+
* ```
|
|
12
17
|
*/
|
|
13
18
|
export function EnumSafeValue(e, value, fallback) {
|
|
14
19
|
return ValidateEnumValue(e, value) ? value : fallback;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-safe-value.js","sourceRoot":"","sources":["../../src/enum/enum-safe-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D
|
|
1
|
+
{"version":3,"file":"enum-safe-value.js","sourceRoot":"","sources":["../../src/enum/enum-safe-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAAkC,CAAI,EAAE,KAAiB,EAAE,QAAoB;IAC3G,OAAO,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvD,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { TEnumType, TEnumValue } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Checks if a value is a valid
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
3
|
+
* Checks if a value is a valid member of the given enum.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The enum type
|
|
6
|
+
* @param e - The enum object
|
|
7
|
+
* @param value - The value to check
|
|
8
|
+
* @returns `true` if the value is a valid enum member, `false` otherwise
|
|
9
|
+
*
|
|
7
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
8
12
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
9
|
-
* ValidateEnumValue(Direction, 'UP');
|
|
13
|
+
* ValidateEnumValue(Direction, 'UP'); // true
|
|
10
14
|
* ValidateEnumValue(Direction, 'INVALID'); // false
|
|
15
|
+
* ```
|
|
11
16
|
*/
|
|
12
17
|
export declare function ValidateEnumValue<T extends TEnumType = TEnumType>(e: T, value: TEnumValue): boolean;
|
|
13
18
|
//# sourceMappingURL=validate-enum-value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-enum-value.d.ts","sourceRoot":"","sources":["../../src/enum/validate-enum-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD
|
|
1
|
+
{"version":3,"file":"validate-enum-value.d.ts","sourceRoot":"","sources":["../../src/enum/validate-enum-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAKnG"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { EnumValues } from './enum-values.js';
|
|
2
2
|
/**
|
|
3
|
-
* Checks if a value is a valid
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
3
|
+
* Checks if a value is a valid member of the given enum.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The enum type
|
|
6
|
+
* @param e - The enum object
|
|
7
|
+
* @param value - The value to check
|
|
8
|
+
* @returns `true` if the value is a valid enum member, `false` otherwise
|
|
9
|
+
*
|
|
7
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
8
12
|
* enum Direction { Up = 'UP', Down = 'DOWN' }
|
|
9
|
-
* ValidateEnumValue(Direction, 'UP');
|
|
13
|
+
* ValidateEnumValue(Direction, 'UP'); // true
|
|
10
14
|
* ValidateEnumValue(Direction, 'INVALID'); // false
|
|
15
|
+
* ```
|
|
11
16
|
*/
|
|
12
17
|
export function ValidateEnumValue(e, value) {
|
|
13
18
|
if (value === null || typeof value === 'undefined' || !e)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-enum-value.js","sourceRoot":"","sources":["../../src/enum/validate-enum-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C
|
|
1
|
+
{"version":3,"file":"validate-enum-value.js","sourceRoot":"","sources":["../../src/enum/validate-enum-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAAkC,CAAI,EAAE,KAAiB;IACzF,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvE,MAAM,cAAc,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IACrC,OAAQ,cAA+B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC"}
|
package/build/index.d.ts
CHANGED
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
*/
|
|
20
20
|
export * as ArrayUtils from './array/index.js';
|
|
21
21
|
export * as ObjectUtils from './object/index.js';
|
|
22
|
+
export * as AssertsUtils from './asserts/index.js';
|
|
23
|
+
export * as BooleanUtils from './boolean/index.js';
|
|
24
|
+
export * as NumberUtils from './number/index.js';
|
|
22
25
|
export * as StringUtils from './string/index.js';
|
|
23
26
|
export * as TimeUtils from './time/index.js';
|
|
24
27
|
export * as EnumUtils from './enum/index.js';
|
|
@@ -29,4 +32,6 @@ export { AssertObject, ObjectClone, TransformObject, ObjectEquals, ObjectFilter,
|
|
|
29
32
|
export { ElapsedTime, Stopwatch, } from './time/index.js';
|
|
30
33
|
export { EnumKeys, EnumValues, EnumEntries, ValidateEnumValue, EnumKeyByValue, EnumSafeValue, } from './enum/index.js';
|
|
31
34
|
export { Debounce, Throttle, Memoize, Once, Compose, Pipe, Sleep, } from './function/index.js';
|
|
35
|
+
export { AssertArray, AssertArray2D, AssertArrayAll, AssertArrayAny, AssertArrayNotEmpty, AssertBoolean, AssertEquals, AssertExtends, AssertFunction, AssertInstanceOf, AssertIsType, AssertNotEquals, AssertNotNull, AssertNull, AssertNumber, AssertObjectHasOwnProperty, AssertObjectHasProperty, AssertObjectPropertyNotNull, AssertPredicate, AssertString, AssertStringMatches, AssertStringNotEmpty, AssertSymbol, SetExceptionClass, SetExceptionMessage, ThrowException, AssertionError, BaseError, BufferOverflowError, InvalidArgumentError, NotFoundError, NotSupportedError, ValidationError, ArrayError, BooleanError, ExtendsError, FunctionError, InstanceOfError, NotNullError, NullError, NumberError, NumberRangeError, ObjectError, ObjectPropertyError, PredicateError, StringError, SymbolError, TypeGuardError, } from './asserts/index.js';
|
|
36
|
+
export type { IAssertException, TConstraintValue, TComparisonOperator, TValidationResult, TGuard, TValidationPredicate, TArrayTypeGuard, TObjectTypeGuard, TNonNullableGuard, TAssertFunction, TConstructorFunction, IAssertArrayArgs, IAssertArray2DArgs, TSizeConstraint, TDimensionConstraint, IAssertNumberArgs, TNumericComparison, TNumericRangeConstraints, TNumericTypeConstraints, } from './asserts/index.js';
|
|
32
37
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAG/C,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAGjD,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAGjD,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAEN,WAAW,EACX,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,UAAU,EACV,WAAW,EACX,YAAY,EAC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eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EAEd,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,GACd,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAEX,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,EACN,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EAEpB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EAEpB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACvB,MAAM,oBAAoB,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
export * as ArrayUtils from './array/index.js';
|
|
22
22
|
// Object utilities
|
|
23
23
|
export * as ObjectUtils from './object/index.js';
|
|
24
|
+
// Asserts utilities
|
|
25
|
+
export * as AssertsUtils from './asserts/index.js';
|
|
26
|
+
// Boolean utilities
|
|
27
|
+
export * as BooleanUtils from './boolean/index.js';
|
|
28
|
+
// Number utilities
|
|
29
|
+
export * as NumberUtils from './number/index.js';
|
|
24
30
|
// String utilities
|
|
25
31
|
export * as StringUtils from './string/index.js';
|
|
26
32
|
// Time utilities
|
|
@@ -48,4 +54,10 @@ EnumKeys, EnumValues, EnumEntries, ValidateEnumValue, EnumKeyByValue, EnumSafeVa
|
|
|
48
54
|
export {
|
|
49
55
|
// Function utilities
|
|
50
56
|
Debounce, Throttle, Memoize, Once, Compose, Pipe, Sleep, } from './function/index.js';
|
|
57
|
+
export {
|
|
58
|
+
// Asserts utilities
|
|
59
|
+
// (AssertObject is omitted here — it conflicts with ObjectUtils.AssertObject; use AssertsUtils.AssertObject instead)
|
|
60
|
+
AssertArray, AssertArray2D, AssertArrayAll, AssertArrayAny, AssertArrayNotEmpty, AssertBoolean, AssertEquals, AssertExtends, AssertFunction, AssertInstanceOf, AssertIsType, AssertNotEquals, AssertNotNull, AssertNull, AssertNumber, AssertObjectHasOwnProperty, AssertObjectHasProperty, AssertObjectPropertyNotNull, AssertPredicate, AssertString, AssertStringMatches, AssertStringNotEmpty, AssertSymbol, SetExceptionClass, SetExceptionMessage, ThrowException,
|
|
61
|
+
// Error classes
|
|
62
|
+
AssertionError, BaseError, BufferOverflowError, InvalidArgumentError, NotFoundError, NotSupportedError, ValidationError, ArrayError, BooleanError, ExtendsError, FunctionError, InstanceOfError, NotNullError, NullError, NumberError, NumberRangeError, ObjectError, ObjectPropertyError, PredicateError, StringError, SymbolError, TypeGuardError, } from './asserts/index.js';
|
|
51
63
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,kBAAkB;AAClB,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,mBAAmB;AACnB,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAEjD,mBAAmB;AACnB,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAEjD,iBAAiB;AACjB,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,iBAAiB;AACjB,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,qBAAqB;AACrB,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAErD,6CAA6C;AAC7C,OAAO;AACN,kBAAkB;AAClB,WAAW,EACX,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,GACX,MAAM,kBAAkB,CAAC;AAE1B,OAAO;AACN,mBAAmB;AACnB,SAAS,EACT,WAAW,EACX,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,gBAAgB,GAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO;AACN,mBAAmB;AACnB,YAAY,EACZ,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,UAAU,EACV,cAAc,EACd,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,aAAa,EACb,UAAU,GACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO;AACN,iBAAiB;AACjB,WAAW,EACX,SAAS,GACT,MAAM,iBAAiB,CAAC;AAEzB,OAAO;AACN,iBAAiB;AACjB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,aAAa,GACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO;AACN,qBAAqB;AACrB,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,KAAK,GACL,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,kBAAkB;AAClB,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,mBAAmB;AACnB,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAEjD,oBAAoB;A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R,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,aAAa,GACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO;AACN,qBAAqB;AACrB,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,KAAK,GACL,MAAM,qBAAqB,CAAC;AAE7B,OAAO;AACN,oBAAoB;AACpB,qHAAqH;AACrH,WAAW,EACX,aAAa,EACb,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,UAAU,EACV,YAAY,EACZ,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC3B,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,cAAc;AACd,gBAAgB;AAChB,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,GACd,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { IAssertException } from '../asserts/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when a value is not a valid number or fails basic numeric validation.
|
|
4
|
+
*
|
|
5
|
+
* This error is used for fundamental number validation failures, such as when
|
|
6
|
+
* a value is not of type 'number', is NaN, or fails other basic numeric checks.
|
|
7
|
+
* It serves as the base class for more specific number-related errors.
|
|
8
|
+
*
|
|
9
|
+
* @extends Error
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* throw new NumberError('Value is not a valid number');
|
|
13
|
+
* throw new NumberError('Expected number but received string');
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class NumberError extends Error {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown when a numeric value is outside the expected range or bounds.
|
|
21
|
+
*
|
|
22
|
+
* This specialized error extends NumberError and is used specifically for
|
|
23
|
+
* range validation failures, such as values being too large, too small,
|
|
24
|
+
* or not matching specific equality constraints. It provides more context
|
|
25
|
+
* for range-related validation failures.
|
|
26
|
+
*
|
|
27
|
+
* @extends NumberError
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* throw new NumberRangeError('Value 150 exceeds maximum of 100');
|
|
31
|
+
* throw new NumberRangeError('Value -5 is below minimum of 0');
|
|
32
|
+
* throw new NumberRangeError('Value must be exactly 42');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class NumberRangeError extends NumberError {
|
|
36
|
+
constructor(message?: string);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Type alias for numeric comparison operators.
|
|
40
|
+
* Represents the available comparison operations for numeric validation.
|
|
41
|
+
*/
|
|
42
|
+
export type TNumericComparison = 'gt' | 'gte' | 'lt' | 'lte' | 'eq';
|
|
43
|
+
/**
|
|
44
|
+
* Type alias for numeric range constraint properties.
|
|
45
|
+
* Groups the range-based validation properties.
|
|
46
|
+
*/
|
|
47
|
+
export type TNumericRangeConstraints = Pick<IAssertNumberArgs, 'gt' | 'gte' | 'lt' | 'lte' | 'eq'>;
|
|
48
|
+
/**
|
|
49
|
+
* Type alias for numeric type constraint properties.
|
|
50
|
+
* Groups the type-based validation properties.
|
|
51
|
+
*/
|
|
52
|
+
export type TNumericTypeConstraints = Pick<IAssertNumberArgs, 'finite' | 'integer'>;
|
|
53
|
+
/**
|
|
54
|
+
* Configuration interface for numeric validation constraints.
|
|
55
|
+
*
|
|
56
|
+
* All properties are optional, allowing for flexible validation rules.
|
|
57
|
+
* Multiple constraints can be combined — all specified conditions must be
|
|
58
|
+
* satisfied simultaneously (AND logic).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Single constraint examples
|
|
63
|
+
* const minOnly: IAssertNumberArgs = { gte: 0 }; // >= 0
|
|
64
|
+
* const maxOnly: IAssertNumberArgs = { lt: 100 }; // < 100
|
|
65
|
+
* const exactValue: IAssertNumberArgs = { eq: 42 }; // === 42
|
|
66
|
+
*
|
|
67
|
+
* // Multiple constraint examples
|
|
68
|
+
* const range: IAssertNumberArgs = { gte: 0, lte: 100 }; // 0 <= value <= 100
|
|
69
|
+
* const exclusive: IAssertNumberArgs = { gt: 0, lt: 1 }; // 0 < value < 1
|
|
70
|
+
*
|
|
71
|
+
* // Used with AssertNumber
|
|
72
|
+
* AssertNumber(50, { gte: 0, lte: 100 }); // ✓ Valid
|
|
73
|
+
* AssertNumber(-1, { gte: 0, lte: 100 }); // ✗ Throws
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export interface IAssertNumberArgs {
|
|
77
|
+
/** When `true`, the value must be finite (not `Infinity` or `-Infinity`) */
|
|
78
|
+
finite?: boolean;
|
|
79
|
+
/** When `true`, the value must be an integer (no fractional component) */
|
|
80
|
+
integer?: boolean;
|
|
81
|
+
/** Value must be greater than this number (exclusive) */
|
|
82
|
+
gt?: number;
|
|
83
|
+
/** Value must be greater than or equal to this number (inclusive) */
|
|
84
|
+
gte?: number;
|
|
85
|
+
/** Value must be less than this number (exclusive) */
|
|
86
|
+
lt?: number;
|
|
87
|
+
/** Value must be less than or equal to this number (inclusive) */
|
|
88
|
+
lte?: number;
|
|
89
|
+
/** Value must be exactly equal to this number */
|
|
90
|
+
eq?: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Asserts that a numeric value meets specified constraints including type, range, and mathematical properties.
|
|
94
|
+
*
|
|
95
|
+
* This function validates that a number satisfies one or more conditions defined in the NumberArgs parameter.
|
|
96
|
+
* It supports various validation types including finite/infinite checks, integer validation, and range
|
|
97
|
+
* constraints with comparison operations. Multiple constraints are evaluated with AND logic - all specified
|
|
98
|
+
* conditions must be satisfied for the assertion to pass.
|
|
99
|
+
*
|
|
100
|
+
* The function is particularly useful for validating user inputs, configuration values, or any numeric
|
|
101
|
+
* data that must meet specific criteria. It provides clear error messages indicating which constraint
|
|
102
|
+
* was violated.
|
|
103
|
+
*
|
|
104
|
+
* @param value - The numeric value to validate against the specified constraints
|
|
105
|
+
* @param args - Object containing one or more validation rules (finite, integer, range constraints)
|
|
106
|
+
* @param exception - Optional configuration for custom error handling and messages
|
|
107
|
+
* @throws {NumberError} When value is not a number or is NaN
|
|
108
|
+
* @throws {NumberRangeError} When value fails any of the specified constraints
|
|
109
|
+
* @returns void - Function only returns if all validations pass
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Type validation
|
|
114
|
+
* AssertNumber(42, { finite: true }); // ✓ 42 is finite
|
|
115
|
+
* AssertNumber(5, { integer: true }); // ✓ 5 is an integer
|
|
116
|
+
* AssertNumber(3.14, { integer: true }); // ✗ Throws: must be integer
|
|
117
|
+
* AssertNumber(Infinity, { finite: true }); // ✗ Throws: must be finite
|
|
118
|
+
*
|
|
119
|
+
* // Range validation
|
|
120
|
+
* AssertNumber(50, { gte: 0 }); // ✓ 50 >= 0
|
|
121
|
+
* AssertNumber(10, { lt: 100 }); // ✓ 10 < 100
|
|
122
|
+
* AssertNumber(42, { eq: 42 }); // ✓ 42 === 42
|
|
123
|
+
*
|
|
124
|
+
* // Combined constraints (AND logic)
|
|
125
|
+
* AssertNumber(50, { finite: true, gte: 0, lte: 100 }); // ✓ finite and 0 <= 50 <= 100
|
|
126
|
+
* AssertNumber(10, { integer: true, gt: 0, lt: 20 }); // ✓ integer and 0 < 10 < 20
|
|
127
|
+
* AssertNumber(3.5, { integer: true, gte: 0 }); // ✗ Throws: must be integer
|
|
128
|
+
*
|
|
129
|
+
* // Validation failures
|
|
130
|
+
* AssertNumber(-1, { gte: 0 }); // ✗ Throws: must be >= 0
|
|
131
|
+
* AssertNumber(150, { lte: 100 }); // ✗ Throws: must be <= 100
|
|
132
|
+
* AssertNumber(41, { eq: 42 }); // ✗ Throws: must equal 42
|
|
133
|
+
* AssertNumber(50, { gt: 60 }); // ✗ Throws: must be > 60
|
|
134
|
+
*
|
|
135
|
+
* // Practical usage examples
|
|
136
|
+
* function validateAge(age: number) {
|
|
137
|
+
* AssertNumber(age, { finite: true, integer: true, gte: 0, lte: 150 }); // Valid human age
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
* function validatePercentage(pct: number) {
|
|
141
|
+
* AssertNumber(pct, { finite: true, gte: 0, lte: 100 }); // 0-100%
|
|
142
|
+
* }
|
|
143
|
+
*
|
|
144
|
+
* function validateTemperature(temp: number) {
|
|
145
|
+
* AssertNumber(temp, { finite: true, gt: -273.15 }); // Above absolute zero
|
|
146
|
+
* }
|
|
147
|
+
*
|
|
148
|
+
* function validateArrayIndex(index: number) {
|
|
149
|
+
* AssertNumber(index, { integer: true, gte: 0 }); // Non-negative integer
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function AssertNumber(value: unknown, args?: IAssertNumberArgs, exception?: IAssertException): asserts value is number;
|
|
154
|
+
//# sourceMappingURL=assert.d.ts.map
|