@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,543 @@
|
|
|
1
|
+
import { ObjectEquals } from './internal-utils.js';
|
|
2
|
+
import { SetExceptionClass, SetExceptionMessage, ThrowException } from './utils.js';
|
|
3
|
+
/** Maximum number of characters to include from a value in an error message. */
|
|
4
|
+
const MAX_VALUE_DISPLAY_LENGTH = 50;
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when a nullish assertion fails — the value is not null or undefined
|
|
7
|
+
* but was expected to be. Used by {@link AssertNull} when the provided value is a
|
|
8
|
+
* live (non-null) reference.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* throw new NullError('Expected value to be null or undefined');
|
|
12
|
+
*/
|
|
13
|
+
export class NullError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message ?? 'Value is not null or undefined.');
|
|
16
|
+
this.name = 'NullError';
|
|
17
|
+
Object.setPrototypeOf(this, NullError.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when a non-null assertion fails — the value is null or undefined
|
|
22
|
+
* but was expected to be non-nullish. Used by {@link AssertNotNull} when the
|
|
23
|
+
* provided value is absent.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* throw new NotNullError('Expected a non-null value but received null');
|
|
27
|
+
*/
|
|
28
|
+
export class NotNullError extends Error {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message ?? 'Value is null or undefined.');
|
|
31
|
+
this.name = 'NotNullError';
|
|
32
|
+
Object.setPrototypeOf(this, NotNullError.prototype);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown when a custom predicate assertion fails.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* throw new PredicateError('Predicate assertion failed');
|
|
40
|
+
*/
|
|
41
|
+
export class PredicateError extends Error {
|
|
42
|
+
constructor(message) {
|
|
43
|
+
super(message ?? 'Value does not satisfy the predicate condition');
|
|
44
|
+
this.name = 'PredicateError';
|
|
45
|
+
Object.setPrototypeOf(this, PredicateError.prototype);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Error thrown when a value does not conform to a user-supplied type guard.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* throw new TypeGuardError('Value does not conform to the required type');
|
|
53
|
+
*/
|
|
54
|
+
export class TypeGuardError extends Error {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super(message ?? 'Type guard assertion failed');
|
|
57
|
+
this.name = 'TypeGuardError';
|
|
58
|
+
Object.setPrototypeOf(this, TypeGuardError.prototype);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Error thrown when a value is not an instance of the expected constructor.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* throw new InstanceOfError('Value is not an instance of the expected type');
|
|
66
|
+
*/
|
|
67
|
+
export class InstanceOfError extends Error {
|
|
68
|
+
constructor(message) {
|
|
69
|
+
super(message ?? 'InstanceOf assertion failed');
|
|
70
|
+
this.name = 'InstanceOfError';
|
|
71
|
+
Object.setPrototypeOf(this, InstanceOfError.prototype);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Error thrown when a value is not a function.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* throw new FunctionError('Value is not a function');
|
|
79
|
+
*/
|
|
80
|
+
export class FunctionError extends Error {
|
|
81
|
+
constructor(message) {
|
|
82
|
+
super(message ?? 'Function assertion failed');
|
|
83
|
+
this.name = 'FunctionError';
|
|
84
|
+
Object.setPrototypeOf(this, FunctionError.prototype);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Error thrown when a value is not a symbol.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* throw new SymbolError('Value is not a symbol');
|
|
92
|
+
*/
|
|
93
|
+
export class SymbolError extends Error {
|
|
94
|
+
constructor(message) {
|
|
95
|
+
super(message ?? 'Symbol assertion failed');
|
|
96
|
+
this.name = 'SymbolError';
|
|
97
|
+
Object.setPrototypeOf(this, SymbolError.prototype);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Error thrown when a class does not extend the expected base class.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* throw new ExtendsError('Class does not extend the expected base class');
|
|
105
|
+
*/
|
|
106
|
+
export class ExtendsError extends Error {
|
|
107
|
+
constructor(message) {
|
|
108
|
+
super(message ?? 'Extends assertion failed');
|
|
109
|
+
this.name = 'ExtendsError';
|
|
110
|
+
Object.setPrototypeOf(this, ExtendsError.prototype);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Asserts that a value equals an expected value using deep equality comparison.
|
|
115
|
+
*
|
|
116
|
+
* This function performs a comprehensive deep equality check between the provided value and
|
|
117
|
+
* the expected value using ObjectUtils.Equals. The comparison algorithm handles:
|
|
118
|
+
* - Primitive values (numbers, strings, booleans, null, undefined)
|
|
119
|
+
* - Complex nested objects with multiple levels of nesting
|
|
120
|
+
* - Arrays with elements in the same order
|
|
121
|
+
* - Mixed data structures combining objects and arrays
|
|
122
|
+
* - Special values like NaN, Infinity, and -0
|
|
123
|
+
*
|
|
124
|
+
* The deep comparison ensures that all nested properties and array elements are
|
|
125
|
+
* recursively compared, making it suitable for complex data structure validation
|
|
126
|
+
* in testing scenarios and runtime assertions.
|
|
127
|
+
*
|
|
128
|
+
* @template T - The type of values being compared (both value and expected must be of same type)
|
|
129
|
+
* @param value - The actual value to compare against the expected value
|
|
130
|
+
* @param expected - The expected value that the actual value should equal
|
|
131
|
+
* @param exception - Configuration object for custom error handling and messaging.
|
|
132
|
+
* Allows customization of error type, message, and additional metadata
|
|
133
|
+
* @throws {PropertyError} When values are not deeply equal, with descriptive error message
|
|
134
|
+
* @throws {TError} When custom exception type is specified and values don't match
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Primitive value comparisons
|
|
139
|
+
* AssertEquals(5, 5); // ✓ Valid (numbers)
|
|
140
|
+
* AssertEquals("hello", "hello"); // ✓ Valid (strings)
|
|
141
|
+
* AssertEquals(true, true); // ✓ Valid (booleans)
|
|
142
|
+
*
|
|
143
|
+
* // Array comparisons (order matters)
|
|
144
|
+
* AssertEquals([1, 2, 3], [1, 2, 3]); // ✓ Valid (same elements, same order)
|
|
145
|
+
* AssertEquals([1, 2], [2, 1]); // ✗ Throws (different order)
|
|
146
|
+
* AssertEquals([], []); // ✓ Valid (empty arrays)
|
|
147
|
+
*
|
|
148
|
+
* // Object comparisons (deep equality)
|
|
149
|
+
* AssertEquals({a: 1, b: 2}, {a: 1, b: 2}); // ✓ Valid (same properties)
|
|
150
|
+
* AssertEquals({a: {b: 1}}, {a: {b: 1}}); // ✓ Valid (nested objects)
|
|
151
|
+
* AssertEquals({}, {}); // ✓ Valid (empty objects)
|
|
152
|
+
*
|
|
153
|
+
* // Complex nested structures
|
|
154
|
+
* const obj1 = {users: [{id: 1, name: "John"}], count: 1};
|
|
155
|
+
* const obj2 = {users: [{id: 1, name: "John"}], count: 1};
|
|
156
|
+
* AssertEquals(obj1, obj2); // ✓ Valid (deeply equal)
|
|
157
|
+
*
|
|
158
|
+
* // Failure cases
|
|
159
|
+
* AssertEquals(5, 10); // ✗ Throws PropertyError
|
|
160
|
+
* AssertEquals({a: 1}, {a: 2}); // ✗ Throws PropertyError
|
|
161
|
+
* AssertEquals([1, 2], [1, 2, 3]); // ✗ Throws PropertyError
|
|
162
|
+
*
|
|
163
|
+
* // Custom exception handling
|
|
164
|
+
* AssertEquals(1, 2, {
|
|
165
|
+
* message: "Values should be equal"
|
|
166
|
+
* }); // ✗ Throws with custom message
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export function AssertEquals(value, expected, exception = {}) {
|
|
170
|
+
if (!ObjectEquals(value, expected)) {
|
|
171
|
+
SetExceptionMessage(exception, `Expected ${value} to equal ${expected}`);
|
|
172
|
+
ThrowException(exception);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Asserts that a value does not equal an expected value using deep equality comparison.
|
|
177
|
+
*
|
|
178
|
+
* This function performs a comprehensive deep equality check and ensures the values are NOT equal.
|
|
179
|
+
* It uses the same sophisticated comparison logic as AssertEquals but with inverted logic,
|
|
180
|
+
* making it perfect for validating that values have changed, are distinct from unwanted values,
|
|
181
|
+
* or ensuring that mutations have occurred successfully.
|
|
182
|
+
*
|
|
183
|
+
* The deep comparison algorithm checks:
|
|
184
|
+
* - All primitive values for strict inequality
|
|
185
|
+
* - Nested object properties at all levels
|
|
186
|
+
* - Array elements and their ordering
|
|
187
|
+
* - Mixed data structures with complex nesting
|
|
188
|
+
* - Special numeric values (NaN, Infinity, -0)
|
|
189
|
+
*
|
|
190
|
+
* This function is particularly useful in testing scenarios where you need to verify
|
|
191
|
+
* that data transformations, mutations, or state changes have actually occurred.
|
|
192
|
+
*
|
|
193
|
+
* @template T - The type of values being compared (both value and expected must be of same type)
|
|
194
|
+
* @param value - The actual value to compare against the unwanted value
|
|
195
|
+
* @param expected - The value that should NOT be equal to the actual value
|
|
196
|
+
* @param exception - Configuration object for custom error handling and messaging.
|
|
197
|
+
* Defaults to empty object if not provided, allowing for optional customization
|
|
198
|
+
* @throws {PropertyError} When values are deeply equal (and shouldn't be), with descriptive error message
|
|
199
|
+
* @throws {TError} When custom exception type is specified and values are unexpectedly equal
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Primitive value comparisons (should be different)
|
|
204
|
+
* AssertNotEquals(5, 10); // ✓ Valid (different numbers)
|
|
205
|
+
* AssertNotEquals("hello", "world"); // ✓ Valid (different strings)
|
|
206
|
+
* AssertNotEquals(true, false); // ✓ Valid (different booleans)
|
|
207
|
+
*
|
|
208
|
+
* // Array comparisons (should be different)
|
|
209
|
+
* AssertNotEquals([1, 2], [1, 3]); // ✓ Valid (different elements)
|
|
210
|
+
* AssertNotEquals([1, 2], [2, 1]); // ✓ Valid (different order)
|
|
211
|
+
* AssertNotEquals([1], [1, 2]); // ✓ Valid (different lengths)
|
|
212
|
+
*
|
|
213
|
+
* // Object comparisons (should be different)
|
|
214
|
+
* AssertNotEquals({a: 1}, {a: 2}); // ✓ Valid (different property values)
|
|
215
|
+
* AssertNotEquals({a: 1}, {b: 1}); // ✓ Valid (different property names)
|
|
216
|
+
* AssertNotEquals({a: {b: 1}}, {a: {b: 2}}); // ✓ Valid (different nested values)
|
|
217
|
+
*
|
|
218
|
+
* // Testing mutations and transformations
|
|
219
|
+
* const original = {users: [{id: 1, name: "John"}]};
|
|
220
|
+
* const modified = {users: [{id: 1, name: "Jane"}]};
|
|
221
|
+
* AssertNotEquals(original, modified); // ✓ Valid (data was modified)
|
|
222
|
+
*
|
|
223
|
+
* // Verifying state changes
|
|
224
|
+
* let counter = 0;
|
|
225
|
+
* const initialState = counter;
|
|
226
|
+
* counter++;
|
|
227
|
+
* AssertNotEquals(counter, initialState); // ✓ Valid (state changed)
|
|
228
|
+
*
|
|
229
|
+
* // Failure cases (when values are unexpectedly equal)
|
|
230
|
+
* AssertNotEquals(5, 5); // ✗ Throws PropertyError
|
|
231
|
+
* AssertNotEquals([1, 2], [1, 2]); // ✗ Throws PropertyError
|
|
232
|
+
* AssertNotEquals({a: 1}, {a: 1}); // ✗ Throws PropertyError
|
|
233
|
+
*
|
|
234
|
+
* // Custom exception handling
|
|
235
|
+
* AssertNotEquals(1, 1, {
|
|
236
|
+
* message: "Values should be different"
|
|
237
|
+
* }); // ✗ Throws with custom message
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export function AssertNotEquals(value, expected, exception = {}) {
|
|
241
|
+
if (ObjectEquals(value, expected)) {
|
|
242
|
+
SetExceptionMessage(exception, `Expected ${value} to not equal ${expected}`);
|
|
243
|
+
ThrowException(exception);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Asserts that a value is null or undefined (nullish assertion).
|
|
248
|
+
*
|
|
249
|
+
* This method validates that the provided value is either null or undefined,
|
|
250
|
+
* effectively performing a nullish assertion. This is useful for validating
|
|
251
|
+
* that optional values are properly unset, that cleanup operations succeeded,
|
|
252
|
+
* or that certain conditions result in null/undefined states.
|
|
253
|
+
*
|
|
254
|
+
* @template T - The type of the value being validated
|
|
255
|
+
* @param value - The value to validate as null or undefined
|
|
256
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
257
|
+
* @throws {NullError} When value is not null or undefined
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* AssertNull(null); // ✓ Valid
|
|
262
|
+
* AssertNull(undefined); // ✓ Valid
|
|
263
|
+
* AssertNull("hello"); // ✗ Throws NullError
|
|
264
|
+
* AssertNull(0); // ✗ Throws NullError
|
|
265
|
+
* AssertNull(false); // ✗ Throws NullError
|
|
266
|
+
* AssertNull(""); // ✗ Throws NullError
|
|
267
|
+
*
|
|
268
|
+
* // Validation of cleanup operations
|
|
269
|
+
* function cleanup(resource: Resource | null) {
|
|
270
|
+
* resource?.dispose();
|
|
271
|
+
* resource = null;
|
|
272
|
+
* AssertNull(resource); // Verify cleanup succeeded
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
export function AssertNull(value, exception = {}) {
|
|
277
|
+
SetExceptionClass(exception, NullError);
|
|
278
|
+
if (value !== null && value !== undefined) {
|
|
279
|
+
SetExceptionMessage(exception, `Expected null or undefined but received ${typeof value}: ${JSON.stringify(value)}`);
|
|
280
|
+
ThrowException(exception);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Asserts that a value is not null or undefined (non-nullish assertion).
|
|
285
|
+
*
|
|
286
|
+
* This method validates that the provided value is neither null nor undefined,
|
|
287
|
+
* effectively performing a non-nullish assertion. This is particularly useful
|
|
288
|
+
* for validating function parameters, API responses, and optional values that
|
|
289
|
+
* should have been initialized. After this assertion, TypeScript will narrow
|
|
290
|
+
* the type to exclude null and undefined.
|
|
291
|
+
*
|
|
292
|
+
* @template T - The type of the value being validated
|
|
293
|
+
* @template TError - Custom error type to throw on failure
|
|
294
|
+
* @param value - The value to validate for non-null/undefined
|
|
295
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
296
|
+
* @throws {NotNullError} When value is null or undefined
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* AssertNotNull("hello"); // ✓ Valid
|
|
301
|
+
* AssertNotNull(0); // ✓ Valid (0 is not null/undefined)
|
|
302
|
+
* AssertNotNull(false); // ✓ Valid (false is not null/undefined)
|
|
303
|
+
* AssertNotNull(""); // ✓ Valid (empty string is not null/undefined)
|
|
304
|
+
* AssertNotNull(null); // ✗ Throws NotNullError
|
|
305
|
+
* AssertNotNull(undefined); // ✗ Throws NotNullError
|
|
306
|
+
*
|
|
307
|
+
* // Type narrowing example
|
|
308
|
+
* function process(value: string | null | undefined) {
|
|
309
|
+
* AssertNotNull(value);
|
|
310
|
+
* // value is now typed as string (null/undefined excluded)
|
|
311
|
+
* return value.toUpperCase();
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
export function AssertNotNull(value, exception = {}) {
|
|
316
|
+
SetExceptionClass(exception, NotNullError);
|
|
317
|
+
if (value === null || value === undefined) {
|
|
318
|
+
const actualValue = value === null ? 'null' : 'undefined';
|
|
319
|
+
SetExceptionMessage(exception, `Expected non-null/non-undefined value but received ${actualValue}`);
|
|
320
|
+
ThrowException(exception);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Generic assertion method that validates a value using a custom predicate function.
|
|
325
|
+
*
|
|
326
|
+
* This method provides a flexible way to perform custom validations using any
|
|
327
|
+
* predicate function that returns a boolean. It's the most generic assertion
|
|
328
|
+
* in the library and can be used to implement complex validation logic that
|
|
329
|
+
* doesn't fit into other specific assertion methods.
|
|
330
|
+
*
|
|
331
|
+
* @template T - The type of value being validated
|
|
332
|
+
* @template TError - Custom error type to throw on failure
|
|
333
|
+
* @param value - The value to validate
|
|
334
|
+
* @param predicate - A TValidationPredicate function that returns true if the value is valid
|
|
335
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
336
|
+
* @throws {PredicateError} When predicate returns false
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* // Simple numeric validation
|
|
341
|
+
* AssertPredicate(42, (x) => x > 0 && x < 100); // ✓ Valid
|
|
342
|
+
*
|
|
343
|
+
* // String validation
|
|
344
|
+
* AssertPredicate("hello", (s) => s.length > 3); // ✓ Valid
|
|
345
|
+
* AssertPredicate("hi", (s) => s.length > 3); // ✗ Throws PredicateError
|
|
346
|
+
*
|
|
347
|
+
* // Complex object validation
|
|
348
|
+
* AssertPredicate(user, (u) =>
|
|
349
|
+
* typeof u.name === 'string' &&
|
|
350
|
+
* u.age >= 0 &&
|
|
351
|
+
* u.email.includes('@')
|
|
352
|
+
* );
|
|
353
|
+
*
|
|
354
|
+
* // Array validation
|
|
355
|
+
* AssertPredicate([1, 2, 3], (arr) =>
|
|
356
|
+
* arr.every(n => typeof n === 'number')
|
|
357
|
+
* );
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
export function AssertPredicate(value, predicate, exception = {}) {
|
|
361
|
+
SetExceptionClass(exception, PredicateError);
|
|
362
|
+
if (!predicate(value)) {
|
|
363
|
+
SetExceptionMessage(exception, 'Value does not satisfy the predicate condition');
|
|
364
|
+
ThrowException(exception);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Asserts that a value matches a specific type using a type guard function.
|
|
369
|
+
*
|
|
370
|
+
* This method validates that the provided value passes a custom type guard,
|
|
371
|
+
* enabling complex type validations beyond primitive type checks. Type guards
|
|
372
|
+
* are functions that return `value is T` and provide runtime type checking
|
|
373
|
+
* with TypeScript type narrowing. This is particularly useful for validating
|
|
374
|
+
* complex object structures and custom types.
|
|
375
|
+
*
|
|
376
|
+
* @template T - The target type to validate for
|
|
377
|
+
* @template TError - Custom error type to throw on failure
|
|
378
|
+
* @param value - The value to validate
|
|
379
|
+
* @param typeGuard - A TGuard function that returns `value is T`
|
|
380
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
381
|
+
* @throws {TypeGuardError} When value does not pass the type guard
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* // Define interfaces and type guards
|
|
386
|
+
* interface User { name: string; age: number; }
|
|
387
|
+
* const isUser = (obj: unknown): obj is User =>
|
|
388
|
+
* typeof obj === 'object' && obj !== null &&
|
|
389
|
+
* 'name' in obj && typeof obj.name === 'string' &&
|
|
390
|
+
* 'age' in obj && typeof obj.age === 'number';
|
|
391
|
+
*
|
|
392
|
+
* // Usage
|
|
393
|
+
* AssertIsType(data, isUser);
|
|
394
|
+
* // data is now typed as User
|
|
395
|
+
*
|
|
396
|
+
* // Array of specific type
|
|
397
|
+
* const isStringArray = (arr: unknown): arr is string[] =>
|
|
398
|
+
* Array.isArray(arr) && arr.every(item => typeof item === 'string');
|
|
399
|
+
*
|
|
400
|
+
* AssertIsType(someArray, isStringArray);
|
|
401
|
+
* // someArray is now typed as string[]
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
export function AssertIsType(value, typeGuard, exception = {}) {
|
|
405
|
+
SetExceptionClass(exception, TypeGuardError);
|
|
406
|
+
if (!typeGuard(value)) {
|
|
407
|
+
const actualType = value === null ? 'null' : value === undefined ? 'undefined' : typeof value;
|
|
408
|
+
SetExceptionMessage(exception, `Expected value to conform to required type but received ${actualType}: ${JSON.stringify(value).slice(0, MAX_VALUE_DISPLAY_LENGTH)}`);
|
|
409
|
+
ThrowException(exception);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Asserts that a value is an instance of a specific class or constructor function.
|
|
414
|
+
*
|
|
415
|
+
* This method validates that the provided value is an instance of the specified
|
|
416
|
+
* constructor function using the instanceof operator. This is useful for validating
|
|
417
|
+
* object instances, built-in types like Date and Error, and custom class instances.
|
|
418
|
+
* After this assertion, the value is properly typed as an instance of the constructor.
|
|
419
|
+
*
|
|
420
|
+
* @template T - The instance type to validate for
|
|
421
|
+
* @template TError - Custom error type to throw on failure
|
|
422
|
+
* @param value - The value to validate as an instance
|
|
423
|
+
* @param constructor - The constructor function to check against
|
|
424
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
425
|
+
* @throws {InstanceOfError} When value is not an instance of the constructor
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* // Built-in types
|
|
430
|
+
* AssertInstanceOf(new Date(), Date); // ✓ Valid
|
|
431
|
+
* AssertInstanceOf(new Error(), Error); // ✓ Valid
|
|
432
|
+
* AssertInstanceOf([], Array); // ✓ Valid
|
|
433
|
+
* AssertInstanceOf(/regex/, RegExp); // ✓ Valid
|
|
434
|
+
*
|
|
435
|
+
* // Custom classes
|
|
436
|
+
* class Person { constructor(public name: string) {} }
|
|
437
|
+
* const person = new Person("John");
|
|
438
|
+
* AssertInstanceOf(person, Person); // ✓ Valid
|
|
439
|
+
*
|
|
440
|
+
* // Invalid cases
|
|
441
|
+
* AssertInstanceOf("string", Date); // ✗ Throws InstanceOfError
|
|
442
|
+
* AssertInstanceOf(123, Error); // ✗ Throws InstanceOfError
|
|
443
|
+
* AssertInstanceOf({}, Array); // ✗ Throws InstanceOfError
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
export function AssertInstanceOf(value, constructor, exception = {}) {
|
|
447
|
+
SetExceptionClass(exception, InstanceOfError);
|
|
448
|
+
if (!(value instanceof constructor)) {
|
|
449
|
+
const actualType = value === null ? 'null' : value === undefined ? 'undefined' : value.constructor?.name || typeof value;
|
|
450
|
+
SetExceptionMessage(exception, `Expected instance of ${constructor.name} but received ${actualType}`);
|
|
451
|
+
ThrowException(exception);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Asserts that a value is a function.
|
|
456
|
+
*
|
|
457
|
+
* This method validates that the provided value is a function (typeof === 'function').
|
|
458
|
+
* Useful for runtime validation of callbacks, API hooks, and dynamic invocations.
|
|
459
|
+
* Throws FunctionError or custom error if assertion fails.
|
|
460
|
+
*
|
|
461
|
+
* @param value - The value to validate as a function
|
|
462
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
463
|
+
* @throws {FunctionError} When value is not a function
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* AssertFunction(() => {}); // ✓ Valid
|
|
467
|
+
* AssertFunction(function() {}); // ✓ Valid
|
|
468
|
+
* AssertFunction(123); // ✗ Throws FunctionError
|
|
469
|
+
* AssertFunction(null); // ✗ Throws FunctionError
|
|
470
|
+
*/
|
|
471
|
+
export function AssertFunction(value, exception = {}) {
|
|
472
|
+
SetExceptionClass(exception, FunctionError);
|
|
473
|
+
if (typeof value !== 'function') {
|
|
474
|
+
const actualType = value === null ? 'null' : value === undefined ? 'undefined' : typeof value;
|
|
475
|
+
SetExceptionMessage(exception, `Expected function but received ${actualType}`);
|
|
476
|
+
ThrowException(exception);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Asserts that a value is a symbol.
|
|
481
|
+
*
|
|
482
|
+
* This method validates that the provided value is a symbol (typeof === 'symbol').
|
|
483
|
+
* Useful for runtime validation of unique keys, metadata, and advanced API contracts.
|
|
484
|
+
* Throws SymbolError or custom error if assertion fails.
|
|
485
|
+
*
|
|
486
|
+
* @param value - The value to validate as a symbol
|
|
487
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
488
|
+
* @throws {SymbolError} When value is not a symbol
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* AssertSymbol(Symbol('foo')); // ✓ Valid
|
|
492
|
+
* AssertSymbol(Symbol.iterator); // ✓ Valid
|
|
493
|
+
* AssertSymbol('not-a-symbol'); // ✗ Throws SymbolError
|
|
494
|
+
* AssertSymbol(123); // ✗ Throws SymbolError
|
|
495
|
+
*/
|
|
496
|
+
export function AssertSymbol(value, exception = {}) {
|
|
497
|
+
SetExceptionClass(exception, SymbolError);
|
|
498
|
+
if (typeof value !== 'symbol') {
|
|
499
|
+
const actualType = value === null ? 'null' : value === undefined ? 'undefined' : typeof value;
|
|
500
|
+
SetExceptionMessage(exception, `Expected symbol but received ${actualType}`);
|
|
501
|
+
ThrowException(exception);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Asserts that a class extends another class.
|
|
506
|
+
*
|
|
507
|
+
* This method validates that the provided derived class extends the specified base class.
|
|
508
|
+
* Useful for runtime validation of inheritance relationships in TypeScript and JavaScript.
|
|
509
|
+
* Throws ExtendsError or custom error if assertion fails.
|
|
510
|
+
*
|
|
511
|
+
* @param derived - The class to validate as extending base
|
|
512
|
+
* @param base - The base class to check against
|
|
513
|
+
* @param exception - Optional exception configuration for custom error handling
|
|
514
|
+
* @throws {ExtendsError} When derived does not extend base
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* class Base {}
|
|
518
|
+
* class Derived extends Base {}
|
|
519
|
+
* AssertExtends(Derived, Base); // ✓ Valid
|
|
520
|
+
* AssertExtends(Base, Derived); // ✗ Throws ExtendsError
|
|
521
|
+
*/
|
|
522
|
+
export function AssertExtends(derived, base, exception = {}) {
|
|
523
|
+
SetExceptionClass(exception, ExtendsError);
|
|
524
|
+
if (typeof derived !== 'function' || typeof base !== 'function') {
|
|
525
|
+
SetExceptionMessage(exception, 'Both arguments must be class constructors');
|
|
526
|
+
ThrowException(exception);
|
|
527
|
+
}
|
|
528
|
+
let proto = Object.getPrototypeOf(derived.prototype);
|
|
529
|
+
const baseProto = base.prototype;
|
|
530
|
+
let found = false;
|
|
531
|
+
while (proto) {
|
|
532
|
+
if (proto === baseProto) {
|
|
533
|
+
found = true;
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
536
|
+
proto = Object.getPrototypeOf(proto);
|
|
537
|
+
}
|
|
538
|
+
if (!found) {
|
|
539
|
+
SetExceptionMessage(exception, `Expected ${derived.name} to extend ${base.name}`);
|
|
540
|
+
ThrowException(exception);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
//# sourceMappingURL=generic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../src/asserts/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpF,gFAAgF;AAChF,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAQpC;;;;;;;GAOG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,iCAAiC,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;CACD;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,6BAA6B,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACxC,YAAY,OAAgB;QAC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,CAAC;IACtC,CAAC;IACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,mBAAmB,CAAC,SAAS,EAAE,YAAY,OAAO,CAAC,IAAI,cAAc,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAClF,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main entry point for the asserts package.
|
|
3
|
+
* Provides assertion utilities for various data types including arrays, booleans, numbers, objects, and strings.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Export all array assertion functions and types
|
|
7
|
+
*/
|
|
8
|
+
export * from '../array/assert.js';
|
|
9
|
+
/**
|
|
10
|
+
* Export all boolean assertion functions and types
|
|
11
|
+
*/
|
|
12
|
+
export * from '../boolean/assert.js';
|
|
13
|
+
/**
|
|
14
|
+
* Export all generic assertion functions and types
|
|
15
|
+
*/
|
|
16
|
+
export * from './generic.js';
|
|
17
|
+
/**
|
|
18
|
+
* Export all number assertion functions and types
|
|
19
|
+
*/
|
|
20
|
+
export * from '../number/assert.js';
|
|
21
|
+
/**
|
|
22
|
+
* Export all object assertion functions and types
|
|
23
|
+
*/
|
|
24
|
+
export * from '../object/assert.js';
|
|
25
|
+
/**
|
|
26
|
+
* Export all string assertion functions and types
|
|
27
|
+
*/
|
|
28
|
+
export * from '../string/assert.js';
|
|
29
|
+
/**
|
|
30
|
+
* Export type definitions and interfaces
|
|
31
|
+
*/
|
|
32
|
+
export * from './types.js';
|
|
33
|
+
/**
|
|
34
|
+
* Export utility functions for advanced usage
|
|
35
|
+
*/
|
|
36
|
+
export * from './utils.js';
|
|
37
|
+
/**
|
|
38
|
+
* Export error classes for standardized error handling
|
|
39
|
+
*/
|
|
40
|
+
export * from './errors.js';
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/asserts/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,cAAc,oBAAoB,CAAC;AAEnC;;GAEG;AACH,cAAc,sBAAsB,CAAC;AAErC;;GAEG;AACH,cAAc,cAAc,CAAC;AAE7B;;GAEG;AACH,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AACH,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AACH,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AACH,cAAc,YAAY,CAAC;AAE3B;;GAEG;AACH,cAAc,YAAY,CAAC;AAE3B;;GAEG;AACH,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main entry point for the asserts package.
|
|
3
|
+
* Provides assertion utilities for various data types including arrays, booleans, numbers, objects, and strings.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Export all array assertion functions and types
|
|
7
|
+
*/
|
|
8
|
+
export * from '../array/assert.js';
|
|
9
|
+
/**
|
|
10
|
+
* Export all boolean assertion functions and types
|
|
11
|
+
*/
|
|
12
|
+
export * from '../boolean/assert.js';
|
|
13
|
+
/**
|
|
14
|
+
* Export all generic assertion functions and types
|
|
15
|
+
*/
|
|
16
|
+
export * from './generic.js';
|
|
17
|
+
/**
|
|
18
|
+
* Export all number assertion functions and types
|
|
19
|
+
*/
|
|
20
|
+
export * from '../number/assert.js';
|
|
21
|
+
/**
|
|
22
|
+
* Export all object assertion functions and types
|
|
23
|
+
*/
|
|
24
|
+
export * from '../object/assert.js';
|
|
25
|
+
/**
|
|
26
|
+
* Export all string assertion functions and types
|
|
27
|
+
*/
|
|
28
|
+
export * from '../string/assert.js';
|
|
29
|
+
/**
|
|
30
|
+
* Export type definitions and interfaces
|
|
31
|
+
*/
|
|
32
|
+
export * from './types.js';
|
|
33
|
+
/**
|
|
34
|
+
* Export utility functions for advanced usage
|
|
35
|
+
*/
|
|
36
|
+
export * from './utils.js';
|
|
37
|
+
/**
|
|
38
|
+
* Export error classes for standardized error handling
|
|
39
|
+
*/
|
|
40
|
+
export * from './errors.js';
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/asserts/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,cAAc,oBAAoB,CAAC;AAEnC;;GAEG;AACH,cAAc,sBAAsB,CAAC;AAErC;;GAEG;AACH,cAAc,cAAc,CAAC;AAE7B;;GAEG;AACH,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AACH,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AACH,cAAc,qBAAqB,CAAC;AAEpC;;GAEG;AACH,cAAc,YAAY,CAAC;AAE3B;;GAEG;AACH,cAAc,YAAY,CAAC;AAE3B;;GAEG;AACH,cAAc,aAAa,CAAC"}
|