@pawells/typescript-common 1.1.6 → 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/README.md +32 -6
- package/build/array/array-chunk.js +1 -1
- package/build/array/array-chunk.js.map +1 -1
- package/build/array/array-contains.d.ts +1 -1
- package/build/array/array-contains.d.ts.map +1 -1
- package/build/array/array-count-by.d.ts +1 -1
- package/build/array/array-count-by.d.ts.map +1 -1
- package/build/array/array-difference.d.ts +1 -1
- package/build/array/array-difference.d.ts.map +1 -1
- package/build/array/array-filter.d.ts +1 -1
- package/build/array/array-filter.d.ts.map +1 -1
- package/build/array/array-filter.js +5 -0
- package/build/array/array-filter.js.map +1 -1
- package/build/array/array-group-by.d.ts +1 -1
- package/build/array/array-group-by.d.ts.map +1 -1
- package/build/array/array-intersection.d.ts +1 -1
- package/build/array/array-intersection.d.ts.map +1 -1
- package/build/array/array-partition.d.ts +1 -1
- package/build/array/array-partition.d.ts.map +1 -1
- package/build/array/array-sort-by.d.ts +1 -1
- package/build/array/array-sort-by.d.ts.map +1 -1
- package/build/array/assert.d.ts +17 -24
- package/build/array/assert.d.ts.map +1 -1
- package/build/array/assert.js +13 -21
- package/build/array/assert.js.map +1 -1
- package/build/asserts/errors.d.ts +18 -0
- package/build/asserts/errors.d.ts.map +1 -1
- package/build/asserts/errors.js +23 -0
- package/build/asserts/errors.js.map +1 -1
- package/build/asserts/generic.d.ts +19 -20
- package/build/asserts/generic.d.ts.map +1 -1
- package/build/asserts/generic.js +19 -34
- package/build/asserts/generic.js.map +1 -1
- package/build/asserts/internal-utils.d.ts +1 -44
- package/build/asserts/internal-utils.d.ts.map +1 -1
- package/build/asserts/internal-utils.js +2 -104
- package/build/asserts/internal-utils.js.map +1 -1
- package/build/boolean/assert.d.ts +2 -1
- package/build/boolean/assert.d.ts.map +1 -1
- package/build/boolean/assert.js +2 -3
- package/build/boolean/assert.js.map +1 -1
- package/build/function/memoize.d.ts +2 -1
- package/build/function/memoize.d.ts.map +1 -1
- package/build/function/memoize.js +4 -7
- package/build/function/memoize.js.map +1 -1
- package/build/function/once.d.ts.map +1 -1
- package/build/function/once.js +14 -2
- package/build/function/once.js.map +1 -1
- package/build/function/throttle.d.ts.map +1 -1
- package/build/function/throttle.js +4 -2
- package/build/function/throttle.js.map +1 -1
- package/build/index.d.ts +5 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -5
- package/build/index.js.map +1 -1
- package/build/lru-cache.d.ts +105 -0
- package/build/lru-cache.d.ts.map +1 -0
- package/build/lru-cache.js +139 -0
- package/build/lru-cache.js.map +1 -0
- package/build/number/assert.d.ts +2 -1
- package/build/number/assert.d.ts.map +1 -1
- package/build/number/assert.js +2 -5
- package/build/number/assert.js.map +1 -1
- package/build/object/assert-object.d.ts +13 -2
- package/build/object/assert-object.d.ts.map +1 -1
- package/build/object/assert-object.js +13 -2
- package/build/object/assert-object.js.map +1 -1
- package/build/object/assert.d.ts +4 -3
- package/build/object/assert.d.ts.map +1 -1
- package/build/object/assert.js +5 -8
- package/build/object/assert.js.map +1 -1
- package/build/object/clone.d.ts.map +1 -1
- package/build/object/clone.js +13 -8
- package/build/object/clone.js.map +1 -1
- package/build/object/equals.js +1 -1
- package/build/object/equals.js.map +1 -1
- package/build/object/filter-cached.d.ts.map +1 -1
- package/build/object/filter-cached.js +4 -6
- package/build/object/filter-cached.js.map +1 -1
- package/build/object/filter.d.ts.map +1 -1
- package/build/object/filter.js +2 -19
- package/build/object/filter.js.map +1 -1
- package/build/object/has-circular-reference.d.ts.map +1 -1
- package/build/object/has-circular-reference.js +5 -0
- package/build/object/has-circular-reference.js.map +1 -1
- package/build/object/hash.d.ts +12 -5
- package/build/object/hash.d.ts.map +1 -1
- package/build/object/hash.js +41 -13
- package/build/object/hash.js.map +1 -1
- package/build/object/index.d.ts +1 -1
- package/build/object/index.d.ts.map +1 -1
- package/build/object/index.js +1 -1
- package/build/object/index.js.map +1 -1
- package/build/object/key-value-pairs.d.ts.map +1 -1
- package/build/object/key-value-pairs.js +12 -4
- package/build/object/key-value-pairs.js.map +1 -1
- package/build/object/map-cached.d.ts.map +1 -1
- package/build/object/map-cached.js +2 -3
- package/build/object/map-cached.js.map +1 -1
- package/build/object/merge.d.ts.map +1 -1
- package/build/object/merge.js +3 -6
- package/build/object/merge.js.map +1 -1
- package/build/object/object-diff.d.ts +4 -8
- package/build/object/object-diff.d.ts.map +1 -1
- package/build/object/object-diff.js +8 -11
- package/build/object/object-diff.js.map +1 -1
- package/build/object/property-paths.js +2 -2
- package/build/object/property-paths.js.map +1 -1
- package/build/object/security-utils.d.ts.map +1 -1
- package/build/object/security-utils.js +0 -4
- package/build/object/security-utils.js.map +1 -1
- package/build/object/sort-keys.js +1 -1
- package/build/object/sort-keys.js.map +1 -1
- package/build/string/assert.d.ts +2 -1
- package/build/string/assert.d.ts.map +1 -1
- package/build/string/assert.js +5 -3
- package/build/string/assert.js.map +1 -1
- package/build/time/elapsed-time/elapsed-time.d.ts +1 -0
- package/build/time/elapsed-time/elapsed-time.d.ts.map +1 -1
- package/build/time/elapsed-time/elapsed-time.js +33 -22
- package/build/time/elapsed-time/elapsed-time.js.map +1 -1
- package/build/time/elapsed-time/types.d.ts +2 -2
- package/build/time/elapsed-time/types.d.ts.map +1 -1
- package/build/time/stopwatch/stopwatch.d.ts +20 -0
- package/build/time/stopwatch/stopwatch.d.ts.map +1 -1
- package/build/time/stopwatch/stopwatch.js +26 -4
- package/build/time/stopwatch/stopwatch.js.map +1 -1
- package/package.json +9 -12
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IAssertException, TGuard, TValidationPredicate } from './types.js';
|
|
2
|
+
import { SimpleError } from './errors.js';
|
|
2
3
|
/**
|
|
3
4
|
* Type alias for constructor functions.
|
|
4
5
|
* Represents any class constructor that can be instantiated.
|
|
@@ -12,7 +13,7 @@ export type TConstructorFunction<T = any> = new (...args: any[]) => T;
|
|
|
12
13
|
* @example
|
|
13
14
|
* throw new NullError('Expected value to be null or undefined');
|
|
14
15
|
*/
|
|
15
|
-
export declare class NullError extends
|
|
16
|
+
export declare class NullError extends SimpleError {
|
|
16
17
|
constructor(message?: string);
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
@@ -23,7 +24,7 @@ export declare class NullError extends Error {
|
|
|
23
24
|
* @example
|
|
24
25
|
* throw new NotNullError('Expected a non-null value but received null');
|
|
25
26
|
*/
|
|
26
|
-
export declare class NotNullError extends
|
|
27
|
+
export declare class NotNullError extends SimpleError {
|
|
27
28
|
constructor(message?: string);
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
@@ -32,7 +33,7 @@ export declare class NotNullError extends Error {
|
|
|
32
33
|
* @example
|
|
33
34
|
* throw new PredicateError('Predicate assertion failed');
|
|
34
35
|
*/
|
|
35
|
-
export declare class PredicateError extends
|
|
36
|
+
export declare class PredicateError extends SimpleError {
|
|
36
37
|
constructor(message?: string);
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
@@ -41,7 +42,7 @@ export declare class PredicateError extends Error {
|
|
|
41
42
|
* @example
|
|
42
43
|
* throw new TypeGuardError('Value does not conform to the required type');
|
|
43
44
|
*/
|
|
44
|
-
export declare class TypeGuardError extends
|
|
45
|
+
export declare class TypeGuardError extends SimpleError {
|
|
45
46
|
constructor(message?: string);
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
@@ -50,7 +51,7 @@ export declare class TypeGuardError extends Error {
|
|
|
50
51
|
* @example
|
|
51
52
|
* throw new InstanceOfError('Value is not an instance of the expected type');
|
|
52
53
|
*/
|
|
53
|
-
export declare class InstanceOfError extends
|
|
54
|
+
export declare class InstanceOfError extends SimpleError {
|
|
54
55
|
constructor(message?: string);
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
@@ -59,7 +60,7 @@ export declare class InstanceOfError extends Error {
|
|
|
59
60
|
* @example
|
|
60
61
|
* throw new FunctionError('Value is not a function');
|
|
61
62
|
*/
|
|
62
|
-
export declare class FunctionError extends
|
|
63
|
+
export declare class FunctionError extends SimpleError {
|
|
63
64
|
constructor(message?: string);
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
@@ -68,7 +69,7 @@ export declare class FunctionError extends Error {
|
|
|
68
69
|
* @example
|
|
69
70
|
* throw new SymbolError('Value is not a symbol');
|
|
70
71
|
*/
|
|
71
|
-
export declare class SymbolError extends
|
|
72
|
+
export declare class SymbolError extends SimpleError {
|
|
72
73
|
constructor(message?: string);
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
@@ -77,7 +78,7 @@ export declare class SymbolError extends Error {
|
|
|
77
78
|
* @example
|
|
78
79
|
* throw new ExtendsError('Class does not extend the expected base class');
|
|
79
80
|
*/
|
|
80
|
-
export declare class ExtendsError extends
|
|
81
|
+
export declare class ExtendsError extends SimpleError {
|
|
81
82
|
constructor(message?: string);
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
@@ -100,8 +101,7 @@ export declare class ExtendsError extends Error {
|
|
|
100
101
|
* @param expected - The expected value that the actual value should equal
|
|
101
102
|
* @param exception - Configuration object for custom error handling and messaging.
|
|
102
103
|
* Allows customization of error type, message, and additional metadata
|
|
103
|
-
* @throws {
|
|
104
|
-
* @throws {TError} When custom exception type is specified and values don't match
|
|
104
|
+
* @throws {AssertionError} When values are not deeply equal, with descriptive error message
|
|
105
105
|
*
|
|
106
106
|
* @example
|
|
107
107
|
* ```typescript
|
|
@@ -126,9 +126,9 @@ export declare class ExtendsError extends Error {
|
|
|
126
126
|
* AssertEquals(obj1, obj2); // ✓ Valid (deeply equal)
|
|
127
127
|
*
|
|
128
128
|
* // Failure cases
|
|
129
|
-
* AssertEquals(5, 10); // ✗ Throws
|
|
130
|
-
* AssertEquals({a: 1}, {a: 2}); // ✗ Throws
|
|
131
|
-
* AssertEquals([1, 2], [1, 2, 3]); // ✗ Throws
|
|
129
|
+
* AssertEquals(5, 10); // ✗ Throws AssertionError
|
|
130
|
+
* AssertEquals({a: 1}, {a: 2}); // ✗ Throws AssertionError
|
|
131
|
+
* AssertEquals([1, 2], [1, 2, 3]); // ✗ Throws AssertionError
|
|
132
132
|
*
|
|
133
133
|
* // Custom exception handling
|
|
134
134
|
* AssertEquals(1, 2, {
|
|
@@ -160,8 +160,7 @@ export declare function AssertEquals<T>(value: T, expected: T, exception?: IAsse
|
|
|
160
160
|
* @param expected - The value that should NOT be equal to the actual value
|
|
161
161
|
* @param exception - Configuration object for custom error handling and messaging.
|
|
162
162
|
* Defaults to empty object if not provided, allowing for optional customization
|
|
163
|
-
* @throws {
|
|
164
|
-
* @throws {TError} When custom exception type is specified and values are unexpectedly equal
|
|
163
|
+
* @throws {AssertionError} When values are deeply equal (and shouldn't be), with descriptive error message
|
|
165
164
|
*
|
|
166
165
|
* @example
|
|
167
166
|
* ```typescript
|
|
@@ -192,9 +191,9 @@ export declare function AssertEquals<T>(value: T, expected: T, exception?: IAsse
|
|
|
192
191
|
* AssertNotEquals(counter, initialState); // ✓ Valid (state changed)
|
|
193
192
|
*
|
|
194
193
|
* // Failure cases (when values are unexpectedly equal)
|
|
195
|
-
* AssertNotEquals(5, 5); // ✗ Throws
|
|
196
|
-
* AssertNotEquals([1, 2], [1, 2]); // ✗ Throws
|
|
197
|
-
* AssertNotEquals({a: 1}, {a: 1}); // ✗ Throws
|
|
194
|
+
* AssertNotEquals(5, 5); // ✗ Throws AssertionError
|
|
195
|
+
* AssertNotEquals([1, 2], [1, 2]); // ✗ Throws AssertionError
|
|
196
|
+
* AssertNotEquals({a: 1}, {a: 1}); // ✗ Throws AssertionError
|
|
198
197
|
*
|
|
199
198
|
* // Custom exception handling
|
|
200
199
|
* AssertNotEquals(1, 1, {
|
|
@@ -233,7 +232,7 @@ export declare function AssertNotEquals<T>(value: T, expected: T, exception?: IA
|
|
|
233
232
|
* }
|
|
234
233
|
* ```
|
|
235
234
|
*/
|
|
236
|
-
export declare function AssertNull<T>(value: T, exception?: IAssertException):
|
|
235
|
+
export declare function AssertNull<T>(value: T, exception?: IAssertException): asserts value is T & (null | undefined);
|
|
237
236
|
/**
|
|
238
237
|
* Asserts that a value is not null or undefined (non-nullish assertion).
|
|
239
238
|
*
|
|
@@ -266,7 +265,7 @@ export declare function AssertNull<T>(value: T, exception?: IAssertException): v
|
|
|
266
265
|
* }
|
|
267
266
|
* ```
|
|
268
267
|
*/
|
|
269
|
-
export declare function AssertNotNull<T>(value: T, exception?: IAssertException): asserts value is T
|
|
268
|
+
export declare function AssertNotNull<T>(value: T, exception?: IAssertException): asserts value is NonNullable<T>;
|
|
270
269
|
/**
|
|
271
270
|
* Generic assertion method that validates a value using a custom predicate function.
|
|
272
271
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/asserts/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/asserts/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAC;AAK1D;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEtE;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,WAAW;gBAC7B,OAAO,CAAC,EAAE,MAAM;CAG5B;AAED;;;;;;;GAOG;AACH,qBAAa,YAAa,SAAQ,WAAW;gBAChC,OAAO,CAAC,EAAE,MAAM;CAG5B;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,WAAW;gBAClC,OAAO,CAAC,EAAE,MAAM;CAG5B;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,WAAW;gBAClC,OAAO,CAAC,EAAE,MAAM;CA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.js';
|
|
2
2
|
import { SetExceptionClass, SetExceptionMessage, ThrowException } from './utils.js';
|
|
3
|
+
import { AssertionError, SimpleError } from './errors.js';
|
|
3
4
|
/** Maximum number of characters to include from a value in an error message. */
|
|
4
5
|
const MAX_VALUE_DISPLAY_LENGTH = 50;
|
|
5
6
|
/**
|
|
@@ -10,11 +11,9 @@ const MAX_VALUE_DISPLAY_LENGTH = 50;
|
|
|
10
11
|
* @example
|
|
11
12
|
* throw new NullError('Expected value to be null or undefined');
|
|
12
13
|
*/
|
|
13
|
-
export class NullError extends
|
|
14
|
+
export class NullError extends SimpleError {
|
|
14
15
|
constructor(message) {
|
|
15
16
|
super(message ?? 'Value is not null or undefined.');
|
|
16
|
-
this.name = 'NullError';
|
|
17
|
-
Object.setPrototypeOf(this, NullError.prototype);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
@@ -25,11 +24,9 @@ export class NullError extends Error {
|
|
|
25
24
|
* @example
|
|
26
25
|
* throw new NotNullError('Expected a non-null value but received null');
|
|
27
26
|
*/
|
|
28
|
-
export class NotNullError extends
|
|
27
|
+
export class NotNullError extends SimpleError {
|
|
29
28
|
constructor(message) {
|
|
30
29
|
super(message ?? 'Value is null or undefined.');
|
|
31
|
-
this.name = 'NotNullError';
|
|
32
|
-
Object.setPrototypeOf(this, NotNullError.prototype);
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
/**
|
|
@@ -38,11 +35,9 @@ export class NotNullError extends Error {
|
|
|
38
35
|
* @example
|
|
39
36
|
* throw new PredicateError('Predicate assertion failed');
|
|
40
37
|
*/
|
|
41
|
-
export class PredicateError extends
|
|
38
|
+
export class PredicateError extends SimpleError {
|
|
42
39
|
constructor(message) {
|
|
43
40
|
super(message ?? 'Value does not satisfy the predicate condition');
|
|
44
|
-
this.name = 'PredicateError';
|
|
45
|
-
Object.setPrototypeOf(this, PredicateError.prototype);
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
43
|
/**
|
|
@@ -51,11 +46,9 @@ export class PredicateError extends Error {
|
|
|
51
46
|
* @example
|
|
52
47
|
* throw new TypeGuardError('Value does not conform to the required type');
|
|
53
48
|
*/
|
|
54
|
-
export class TypeGuardError extends
|
|
49
|
+
export class TypeGuardError extends SimpleError {
|
|
55
50
|
constructor(message) {
|
|
56
51
|
super(message ?? 'Type guard assertion failed');
|
|
57
|
-
this.name = 'TypeGuardError';
|
|
58
|
-
Object.setPrototypeOf(this, TypeGuardError.prototype);
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
54
|
/**
|
|
@@ -64,11 +57,9 @@ export class TypeGuardError extends Error {
|
|
|
64
57
|
* @example
|
|
65
58
|
* throw new InstanceOfError('Value is not an instance of the expected type');
|
|
66
59
|
*/
|
|
67
|
-
export class InstanceOfError extends
|
|
60
|
+
export class InstanceOfError extends SimpleError {
|
|
68
61
|
constructor(message) {
|
|
69
62
|
super(message ?? 'InstanceOf assertion failed');
|
|
70
|
-
this.name = 'InstanceOfError';
|
|
71
|
-
Object.setPrototypeOf(this, InstanceOfError.prototype);
|
|
72
63
|
}
|
|
73
64
|
}
|
|
74
65
|
/**
|
|
@@ -77,11 +68,9 @@ export class InstanceOfError extends Error {
|
|
|
77
68
|
* @example
|
|
78
69
|
* throw new FunctionError('Value is not a function');
|
|
79
70
|
*/
|
|
80
|
-
export class FunctionError extends
|
|
71
|
+
export class FunctionError extends SimpleError {
|
|
81
72
|
constructor(message) {
|
|
82
73
|
super(message ?? 'Function assertion failed');
|
|
83
|
-
this.name = 'FunctionError';
|
|
84
|
-
Object.setPrototypeOf(this, FunctionError.prototype);
|
|
85
74
|
}
|
|
86
75
|
}
|
|
87
76
|
/**
|
|
@@ -90,11 +79,9 @@ export class FunctionError extends Error {
|
|
|
90
79
|
* @example
|
|
91
80
|
* throw new SymbolError('Value is not a symbol');
|
|
92
81
|
*/
|
|
93
|
-
export class SymbolError extends
|
|
82
|
+
export class SymbolError extends SimpleError {
|
|
94
83
|
constructor(message) {
|
|
95
84
|
super(message ?? 'Symbol assertion failed');
|
|
96
|
-
this.name = 'SymbolError';
|
|
97
|
-
Object.setPrototypeOf(this, SymbolError.prototype);
|
|
98
85
|
}
|
|
99
86
|
}
|
|
100
87
|
/**
|
|
@@ -103,11 +90,9 @@ export class SymbolError extends Error {
|
|
|
103
90
|
* @example
|
|
104
91
|
* throw new ExtendsError('Class does not extend the expected base class');
|
|
105
92
|
*/
|
|
106
|
-
export class ExtendsError extends
|
|
93
|
+
export class ExtendsError extends SimpleError {
|
|
107
94
|
constructor(message) {
|
|
108
95
|
super(message ?? 'Extends assertion failed');
|
|
109
|
-
this.name = 'ExtendsError';
|
|
110
|
-
Object.setPrototypeOf(this, ExtendsError.prototype);
|
|
111
96
|
}
|
|
112
97
|
}
|
|
113
98
|
/**
|
|
@@ -130,8 +115,7 @@ export class ExtendsError extends Error {
|
|
|
130
115
|
* @param expected - The expected value that the actual value should equal
|
|
131
116
|
* @param exception - Configuration object for custom error handling and messaging.
|
|
132
117
|
* Allows customization of error type, message, and additional metadata
|
|
133
|
-
* @throws {
|
|
134
|
-
* @throws {TError} When custom exception type is specified and values don't match
|
|
118
|
+
* @throws {AssertionError} When values are not deeply equal, with descriptive error message
|
|
135
119
|
*
|
|
136
120
|
* @example
|
|
137
121
|
* ```typescript
|
|
@@ -156,9 +140,9 @@ export class ExtendsError extends Error {
|
|
|
156
140
|
* AssertEquals(obj1, obj2); // ✓ Valid (deeply equal)
|
|
157
141
|
*
|
|
158
142
|
* // Failure cases
|
|
159
|
-
* AssertEquals(5, 10); // ✗ Throws
|
|
160
|
-
* AssertEquals({a: 1}, {a: 2}); // ✗ Throws
|
|
161
|
-
* AssertEquals([1, 2], [1, 2, 3]); // ✗ Throws
|
|
143
|
+
* AssertEquals(5, 10); // ✗ Throws AssertionError
|
|
144
|
+
* AssertEquals({a: 1}, {a: 2}); // ✗ Throws AssertionError
|
|
145
|
+
* AssertEquals([1, 2], [1, 2, 3]); // ✗ Throws AssertionError
|
|
162
146
|
*
|
|
163
147
|
* // Custom exception handling
|
|
164
148
|
* AssertEquals(1, 2, {
|
|
@@ -167,6 +151,7 @@ export class ExtendsError extends Error {
|
|
|
167
151
|
* ```
|
|
168
152
|
*/
|
|
169
153
|
export function AssertEquals(value, expected, exception = {}) {
|
|
154
|
+
SetExceptionClass(exception, AssertionError);
|
|
170
155
|
if (!ObjectEquals(value, expected)) {
|
|
171
156
|
SetExceptionMessage(exception, `Expected ${value} to equal ${expected}`);
|
|
172
157
|
ThrowException(exception);
|
|
@@ -195,8 +180,7 @@ export function AssertEquals(value, expected, exception = {}) {
|
|
|
195
180
|
* @param expected - The value that should NOT be equal to the actual value
|
|
196
181
|
* @param exception - Configuration object for custom error handling and messaging.
|
|
197
182
|
* Defaults to empty object if not provided, allowing for optional customization
|
|
198
|
-
* @throws {
|
|
199
|
-
* @throws {TError} When custom exception type is specified and values are unexpectedly equal
|
|
183
|
+
* @throws {AssertionError} When values are deeply equal (and shouldn't be), with descriptive error message
|
|
200
184
|
*
|
|
201
185
|
* @example
|
|
202
186
|
* ```typescript
|
|
@@ -227,9 +211,9 @@ export function AssertEquals(value, expected, exception = {}) {
|
|
|
227
211
|
* AssertNotEquals(counter, initialState); // ✓ Valid (state changed)
|
|
228
212
|
*
|
|
229
213
|
* // Failure cases (when values are unexpectedly equal)
|
|
230
|
-
* AssertNotEquals(5, 5); // ✗ Throws
|
|
231
|
-
* AssertNotEquals([1, 2], [1, 2]); // ✗ Throws
|
|
232
|
-
* AssertNotEquals({a: 1}, {a: 1}); // ✗ Throws
|
|
214
|
+
* AssertNotEquals(5, 5); // ✗ Throws AssertionError
|
|
215
|
+
* AssertNotEquals([1, 2], [1, 2]); // ✗ Throws AssertionError
|
|
216
|
+
* AssertNotEquals({a: 1}, {a: 1}); // ✗ Throws AssertionError
|
|
233
217
|
*
|
|
234
218
|
* // Custom exception handling
|
|
235
219
|
* AssertNotEquals(1, 1, {
|
|
@@ -238,6 +222,7 @@ export function AssertEquals(value, expected, exception = {}) {
|
|
|
238
222
|
* ```
|
|
239
223
|
*/
|
|
240
224
|
export function AssertNotEquals(value, expected, exception = {}) {
|
|
225
|
+
SetExceptionClass(exception, AssertionError);
|
|
241
226
|
if (ObjectEquals(value, expected)) {
|
|
242
227
|
SetExceptionMessage(exception, `Expected ${value} to not equal ${expected}`);
|
|
243
228
|
ThrowException(exception);
|
|
@@ -1 +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;
|
|
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;AACpF,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1D,gFAAgF;AAChF,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAQpC;;;;;;;GAOG;AACH,MAAM,OAAO,SAAU,SAAQ,WAAW;IACzC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,iCAAiC,CAAC,CAAC;IACrD,CAAC;CACD;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC5C,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,6BAA6B,CAAC,CAAC;IACjD,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,gDAAgD,CAAC,CAAC;IACpE,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,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AAE,YAAY,CAAC,CAAC;IAC3C,IAAI,OAAO,OAAO,KAAK,UAAU,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QACjE,mBAAmB,CAAC,SAAS,EAAE,2CAA2C,CAAC,CAAC;QAC5E,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IACjC,IAAI,KAAK,GAAG,KAAK,CAAC;IAElB,OAAO,KAAK,EAAE,CAAC;QACd,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,KAAK,GAAG,IAAI,CAAC;YACb,MAAM;QACP,CAAC;QACD,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,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"}
|
|
@@ -1,53 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Internal utilities for the asserts package.
|
|
3
|
-
* These utilities are copied from @jtv/common to make @jtv/asserts standalone.
|
|
4
3
|
*/
|
|
5
4
|
/**
|
|
6
5
|
* A constructor function type for creating objects of type O.
|
|
7
6
|
* @template O The object type to construct.
|
|
8
7
|
*/
|
|
9
8
|
export type TConstructableObject<O extends object = object> = new (...args: any[]) => O;
|
|
10
|
-
|
|
11
|
-
* Performs a deep comparison between two values to determine if they are equivalent.
|
|
12
|
-
* Handles primitives, objects, arrays, dates, regular expressions, and special values like NaN.
|
|
13
|
-
*
|
|
14
|
-
* @param a - First value to compare
|
|
15
|
-
* @param b - Second value to compare
|
|
16
|
-
* @returns True if the values are equivalent, false otherwise
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // Primitive values
|
|
21
|
-
* ObjectEquals(42, 42); // true
|
|
22
|
-
* ObjectEquals('hello', 'hello'); // true
|
|
23
|
-
* ObjectEquals(true, false); // false
|
|
24
|
-
*
|
|
25
|
-
* // Objects
|
|
26
|
-
* ObjectEquals({ a: 1, b: 2 }, { a: 1, b: 2 }); // true
|
|
27
|
-
* ObjectEquals({ a: 1, b: 2 }, { a: 1, b: 3 }); // false
|
|
28
|
-
*
|
|
29
|
-
* // Nested objects
|
|
30
|
-
* const obj1 = { user: { name: 'John', age: 30 }, active: true };
|
|
31
|
-
* const obj2 = { user: { name: 'John', age: 30 }, active: true };
|
|
32
|
-
* ObjectEquals(obj1, obj2); // true
|
|
33
|
-
*
|
|
34
|
-
* // Arrays
|
|
35
|
-
* ObjectEquals([1, 2, 3], [1, 2, 3]); // true
|
|
36
|
-
* ObjectEquals([1, [2, 3]], [1, [2, 3]]); // true
|
|
37
|
-
*
|
|
38
|
-
* // Date objects
|
|
39
|
-
* const date1 = new Date('2023-01-01');
|
|
40
|
-
* const date2 = new Date('2023-01-01');
|
|
41
|
-
* ObjectEquals(date1, date2); // true
|
|
42
|
-
*
|
|
43
|
-
* // Regular expressions
|
|
44
|
-
* ObjectEquals(/abc/g, /abc/g); // true
|
|
45
|
-
* ObjectEquals(/abc/g, /abc/i); // false
|
|
46
|
-
*
|
|
47
|
-
* // Special cases
|
|
48
|
-
* ObjectEquals(NaN, NaN); // true (unlike === comparison)
|
|
49
|
-
* ObjectEquals(null, undefined); // false
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export declare function ObjectEquals(a: any, b: any): boolean;
|
|
9
|
+
export { ObjectEquals } from '../object/equals.js';
|
|
53
10
|
//# sourceMappingURL=internal-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-utils.d.ts","sourceRoot":"","sources":["../../src/asserts/internal-utils.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"internal-utils.d.ts","sourceRoot":"","sources":["../../src/asserts/internal-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAGxF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,108 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Internal utilities for the asserts package.
|
|
3
|
-
* These utilities are copied from @jtv/common to make @jtv/asserts standalone.
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Handles primitives, objects, arrays, dates, regular expressions, and special values like NaN.
|
|
8
|
-
*
|
|
9
|
-
* @param a - First value to compare
|
|
10
|
-
* @param b - Second value to compare
|
|
11
|
-
* @returns True if the values are equivalent, false otherwise
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* // Primitive values
|
|
16
|
-
* ObjectEquals(42, 42); // true
|
|
17
|
-
* ObjectEquals('hello', 'hello'); // true
|
|
18
|
-
* ObjectEquals(true, false); // false
|
|
19
|
-
*
|
|
20
|
-
* // Objects
|
|
21
|
-
* ObjectEquals({ a: 1, b: 2 }, { a: 1, b: 2 }); // true
|
|
22
|
-
* ObjectEquals({ a: 1, b: 2 }, { a: 1, b: 3 }); // false
|
|
23
|
-
*
|
|
24
|
-
* // Nested objects
|
|
25
|
-
* const obj1 = { user: { name: 'John', age: 30 }, active: true };
|
|
26
|
-
* const obj2 = { user: { name: 'John', age: 30 }, active: true };
|
|
27
|
-
* ObjectEquals(obj1, obj2); // true
|
|
28
|
-
*
|
|
29
|
-
* // Arrays
|
|
30
|
-
* ObjectEquals([1, 2, 3], [1, 2, 3]); // true
|
|
31
|
-
* ObjectEquals([1, [2, 3]], [1, [2, 3]]); // true
|
|
32
|
-
*
|
|
33
|
-
* // Date objects
|
|
34
|
-
* const date1 = new Date('2023-01-01');
|
|
35
|
-
* const date2 = new Date('2023-01-01');
|
|
36
|
-
* ObjectEquals(date1, date2); // true
|
|
37
|
-
*
|
|
38
|
-
* // Regular expressions
|
|
39
|
-
* ObjectEquals(/abc/g, /abc/g); // true
|
|
40
|
-
* ObjectEquals(/abc/g, /abc/i); // false
|
|
41
|
-
*
|
|
42
|
-
* // Special cases
|
|
43
|
-
* ObjectEquals(NaN, NaN); // true (unlike === comparison)
|
|
44
|
-
* ObjectEquals(null, undefined); // false
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export function ObjectEquals(a, b) {
|
|
48
|
-
// If the values are strictly equal, return true
|
|
49
|
-
if (a === b)
|
|
50
|
-
return true;
|
|
51
|
-
// Handle NaN special case - NaN should equal NaN for assertion purposes
|
|
52
|
-
if (typeof a === 'number' && typeof b === 'number' && isNaN(a) && isNaN(b)) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
// If either value is null, undefined, or not an object, they can't be equivalent
|
|
56
|
-
if (a === null || b === null || a === undefined || b === undefined)
|
|
57
|
-
return false;
|
|
58
|
-
if (typeof a !== typeof b)
|
|
59
|
-
return false;
|
|
60
|
-
if (typeof a !== 'object')
|
|
61
|
-
return false;
|
|
62
|
-
// Handle Date objects
|
|
63
|
-
if (a instanceof Date && b instanceof Date) {
|
|
64
|
-
return a.getTime() === b.getTime();
|
|
65
|
-
}
|
|
66
|
-
// Handle RegExp objects
|
|
67
|
-
if (a instanceof RegExp && b instanceof RegExp) {
|
|
68
|
-
return a.toString() === b.toString();
|
|
69
|
-
}
|
|
70
|
-
// Handle arrays
|
|
71
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
72
|
-
if (a.length !== b.length)
|
|
73
|
-
return false;
|
|
74
|
-
// Compare each element in the arrays
|
|
75
|
-
for (let i = 0; i < a.length; i++) {
|
|
76
|
-
if (!ObjectEquals(a[i], b[i]))
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
// If one is array and the other isn't, they're not equal
|
|
82
|
-
if (Array.isArray(a) !== Array.isArray(b))
|
|
83
|
-
return false;
|
|
84
|
-
// Compare object properties
|
|
85
|
-
const keysA = Object.keys(a);
|
|
86
|
-
const keysB = Object.keys(b);
|
|
87
|
-
if (keysA.length !== keysB.length)
|
|
88
|
-
return false;
|
|
89
|
-
// Also compare symbol properties
|
|
90
|
-
const symbolsA = Object.getOwnPropertySymbols(a);
|
|
91
|
-
const symbolsB = Object.getOwnPropertySymbols(b);
|
|
92
|
-
if (symbolsA.length !== symbolsB.length)
|
|
93
|
-
return false;
|
|
94
|
-
for (const key of keysA) {
|
|
95
|
-
if (!Object.hasOwn(b, key))
|
|
96
|
-
return false;
|
|
97
|
-
if (!ObjectEquals(a[key], b[key]))
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
for (const symbol of symbolsA) {
|
|
101
|
-
if (!Object.getOwnPropertySymbols(b).includes(symbol))
|
|
102
|
-
return false;
|
|
103
|
-
if (!ObjectEquals(a[symbol], b[symbol]))
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
4
|
+
// Single source of truth — the canonical implementation lives in the object module.
|
|
5
|
+
export { ObjectEquals } from '../object/equals.js';
|
|
108
6
|
//# sourceMappingURL=internal-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-utils.js","sourceRoot":"","sources":["../../src/asserts/internal-utils.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"internal-utils.js","sourceRoot":"","sources":["../../src/asserts/internal-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,oFAAoF;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { IAssertException } from '../asserts/types.js';
|
|
2
|
+
import { SimpleError } from '../asserts/errors.js';
|
|
2
3
|
/**
|
|
3
4
|
* Error thrown when a value is not a valid boolean or fails a boolean assertion.
|
|
4
5
|
*
|
|
5
6
|
* @example
|
|
6
7
|
* throw new BooleanError('Value is not a valid boolean');
|
|
7
8
|
*/
|
|
8
|
-
export declare class BooleanError extends
|
|
9
|
+
export declare class BooleanError extends SimpleError {
|
|
9
10
|
constructor(message?: string);
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/boolean/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/boolean/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,WAAW;gBAChC,OAAO,CAAC,EAAE,MAAM;CAG5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAMxG"}
|
package/build/boolean/assert.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { SetExceptionClass, SetExceptionMessage, ThrowException } from '../asserts/utils.js';
|
|
2
|
+
import { SimpleError } from '../asserts/errors.js';
|
|
2
3
|
/**
|
|
3
4
|
* Error thrown when a value is not a valid boolean or fails a boolean assertion.
|
|
4
5
|
*
|
|
5
6
|
* @example
|
|
6
7
|
* throw new BooleanError('Value is not a valid boolean');
|
|
7
8
|
*/
|
|
8
|
-
export class BooleanError extends
|
|
9
|
+
export class BooleanError extends SimpleError {
|
|
9
10
|
constructor(message) {
|
|
10
11
|
super(message ?? 'Invalid Boolean');
|
|
11
|
-
this.name = 'BooleanError';
|
|
12
|
-
Object.setPrototypeOf(this, BooleanError.prototype);
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
@@ -1 +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;
|
|
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;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC5C,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,iBAAiB,CAAC,CAAC;IACrC,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"}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Only suitable for **pure functions** with serialisable arguments.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Uses an LRU (Least Recently Used) eviction policy: when the cache reaches
|
|
8
|
+
* `maxCacheSize`, the entry that was accessed least recently is evicted.
|
|
8
9
|
*
|
|
9
10
|
* @template T - The wrapped function type
|
|
10
11
|
* @param fn - The function to memoize
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/function/memoize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/function/memoize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,EAE1C,YAAY,SAAO,GACjB,CAAC,CAcH"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { LRUCache } from '../lru-cache.js';
|
|
1
2
|
/**
|
|
2
3
|
* Returns a memoized version of `fn` that caches results by serialising its
|
|
3
4
|
* arguments with `JSON.stringify` (or a custom `keyFn`).
|
|
4
5
|
*
|
|
5
6
|
* Only suitable for **pure functions** with serialisable arguments.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
+
* Uses an LRU (Least Recently Used) eviction policy: when the cache reaches
|
|
9
|
+
* `maxCacheSize`, the entry that was accessed least recently is evicted.
|
|
8
10
|
*
|
|
9
11
|
* @template T - The wrapped function type
|
|
10
12
|
* @param fn - The function to memoize
|
|
@@ -28,18 +30,13 @@
|
|
|
28
30
|
export function Memoize(fn, keyFn,
|
|
29
31
|
// eslint-disable-next-line no-magic-numbers
|
|
30
32
|
maxCacheSize = 1000) {
|
|
31
|
-
const cache = new
|
|
33
|
+
const cache = new LRUCache(maxCacheSize);
|
|
32
34
|
return function memoized(...args) {
|
|
33
35
|
const key = keyFn ? keyFn(...args) : JSON.stringify(args);
|
|
34
36
|
if (cache.has(key)) {
|
|
35
37
|
return cache.get(key);
|
|
36
38
|
}
|
|
37
39
|
const result = fn(...args);
|
|
38
|
-
// Implement LRU eviction: if cache is full, remove oldest entry before adding new one
|
|
39
|
-
if (cache.size >= maxCacheSize) {
|
|
40
|
-
const oldestKey = cache.keys().next().value;
|
|
41
|
-
cache.delete(oldestKey);
|
|
42
|
-
}
|
|
43
40
|
cache.set(key, result);
|
|
44
41
|
return result;
|
|
45
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/function/memoize.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/function/memoize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,OAAO,CACtB,EAAK,EACL,KAA0C;AAC1C,4CAA4C;AAC5C,YAAY,GAAG,IAAI;IAEnB,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAwB,YAAY,CAAC,CAAC;IAEhE,OAAO,SAAS,QAAQ,CAAC,GAAG,IAAmB;QAC9C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAE1D,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAkB,CAAC;QACxC,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAkB,CAAC;QAC5C,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACvB,OAAO,MAAM,CAAC;IACf,CAAM,CAAC;AACR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.d.ts","sourceRoot":"","sources":["../../src/function/once.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"once.d.ts","sourceRoot":"","sources":["../../src/function/once.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAsBhE"}
|