@pawells/typescript-common 1.0.0 → 1.1.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 +177 -2
- 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/asserts/errors.d.ts +45 -0
- package/build/asserts/errors.d.ts.map +1 -0
- package/build/asserts/errors.js +65 -0
- package/build/asserts/errors.js.map +1 -0
- package/build/asserts/generic.d.ts +432 -0
- package/build/asserts/generic.d.ts.map +1 -0
- package/build/asserts/generic.js +539 -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/object.d.ts +138 -0
- package/build/asserts/object.d.ts.map +1 -0
- package/build/asserts/object.js +204 -0
- package/build/asserts/object.js.map +1 -0
- package/build/asserts/string.d.ts +100 -0
- package/build/asserts/string.d.ts.map +1 -0
- package/build/asserts/string.js +185 -0
- package/build/asserts/string.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/index.d.ts +4 -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/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/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/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 +14 -2
package/README.md
CHANGED
|
@@ -23,14 +23,189 @@ All utilities are available as namespace imports or as individual named exports
|
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
25
|
// Namespace import
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
ArrayUtils, BooleanUtils, NumberUtils,
|
|
28
|
+
ObjectUtils, StringUtils, TimeUtils,
|
|
29
|
+
EnumUtils, FunctionUtils, AssertsUtils,
|
|
30
|
+
} from '@pawells/typescript-common';
|
|
27
31
|
|
|
28
32
|
ArrayUtils.ArrayChunk([1, 2, 3, 4], 2); // [[1, 2], [3, 4]]
|
|
33
|
+
ArrayUtils.AssertArray(value); // throws if not an array
|
|
34
|
+
BooleanUtils.AssertBoolean(value); // throws if not a boolean
|
|
35
|
+
NumberUtils.AssertNumber(value, { gte: 0, integer: true });
|
|
29
36
|
|
|
30
37
|
// Direct named import (tree-shakeable)
|
|
31
|
-
import { ArrayChunk, ObjectPick, CamelCase, Sleep } from '@pawells/typescript-common';
|
|
38
|
+
import { ArrayChunk, ObjectPick, CamelCase, Sleep, AssertString } from '@pawells/typescript-common';
|
|
32
39
|
```
|
|
33
40
|
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### Array utilities — `ArrayUtils`
|
|
44
|
+
|
|
45
|
+
| Export | Description |
|
|
46
|
+
|--------|-------------|
|
|
47
|
+
| `ArrayChunk(array, size)` | Split an array into chunks of a given size |
|
|
48
|
+
| `ArrayContains(array, predicate)` | Check if any element satisfies a predicate |
|
|
49
|
+
| `ArrayFilter(array, predicate)` | Type-safe array filter |
|
|
50
|
+
| `ArrayGroupBy(array, keyFn)` | Group array elements by a key function |
|
|
51
|
+
| `ArrayIntersection(a, b)` | Return elements present in both arrays |
|
|
52
|
+
| `ArrayShuffle(array)` | Return a shuffled copy of an array |
|
|
53
|
+
| `Unique(array)` | Remove duplicate values |
|
|
54
|
+
| `ArrayDifference(a, b)` | Elements in `a` not present in `b` |
|
|
55
|
+
| `ArrayFlatten(array, depth?)` | Flatten a nested array to a given depth |
|
|
56
|
+
| `ArrayCompact(array)` | Remove `null`/`undefined`, narrowing the type |
|
|
57
|
+
| `ArrayPartition(array, predicate)` | Split into `[matches, rest]` |
|
|
58
|
+
| `ArrayZip(...arrays)` | Zip multiple arrays into tuples |
|
|
59
|
+
| `ArrayRange(start, end, step?)` | Generate a numeric sequence |
|
|
60
|
+
| `ArraySortBy(array, keyFn, direction?)` | Immutable sort by a computed key |
|
|
61
|
+
| `ArrayCountBy(array, keyFn)` | Count elements per group key |
|
|
62
|
+
| `ArraySample(array, n?)` | Random element or `n` random elements |
|
|
63
|
+
| `AssertArray(value, args?, exception?)` | Assert value is an array (with optional size constraints) |
|
|
64
|
+
| `AssertArray2D(value, args?, exception?)` | Assert value is a rectangular 2D array |
|
|
65
|
+
| `AssertArrayNotEmpty(value, exception?)` | Assert array has at least one element |
|
|
66
|
+
| `AssertArrayAll(array, predicate, exception?)` | Assert every element satisfies a predicate |
|
|
67
|
+
| `AssertArrayAny(array, predicate, exception?)` | Assert at least one element satisfies a predicate |
|
|
68
|
+
|
|
69
|
+
### Boolean utilities — `BooleanUtils`
|
|
70
|
+
|
|
71
|
+
| Export | Description |
|
|
72
|
+
|--------|-------------|
|
|
73
|
+
| `AssertBoolean(value, exception?)` | Assert value is a boolean primitive |
|
|
74
|
+
|
|
75
|
+
### Number utilities — `NumberUtils`
|
|
76
|
+
|
|
77
|
+
| Export | Description |
|
|
78
|
+
|--------|-------------|
|
|
79
|
+
| `AssertNumber(value, args?, exception?)` | Assert value is a number with optional range/type constraints (`finite`, `integer`, `gt`, `gte`, `lt`, `lte`, `eq`) |
|
|
80
|
+
|
|
81
|
+
### Object utilities — `ObjectUtils`
|
|
82
|
+
|
|
83
|
+
| Export | Description |
|
|
84
|
+
|--------|-------------|
|
|
85
|
+
| `AssertObject(value)` | Assert a value is a non-null plain object (type-guard, returns boolean) |
|
|
86
|
+
| `ObjectClone(obj)` | Deep-clone an object |
|
|
87
|
+
| `ObjectEquals(a, b)` | Deep equality check |
|
|
88
|
+
| `ObjectFilter(obj, predicate)` | Filter object entries by predicate |
|
|
89
|
+
| `FilterObject(obj, keys)` | Keep only specified keys |
|
|
90
|
+
| `ObjectPick(obj, keys)` | Pick a subset of keys |
|
|
91
|
+
| `ObjectOmit(obj, keys)` | Omit specified keys |
|
|
92
|
+
| `ObjectMerge(target, ...sources)` | Deep merge objects |
|
|
93
|
+
| `MapObject(obj, fn)` | Map over object values |
|
|
94
|
+
| `TransformObject(obj, fn)` | Transform object entries |
|
|
95
|
+
| `ObjectHash(obj)` | Compute a stable hash of an object |
|
|
96
|
+
| `ObjectSortKeys(obj)` | Return object with keys sorted |
|
|
97
|
+
| `ObjectFromKeyValuePairs(pairs)` | Build an object from `[key, value]` pairs |
|
|
98
|
+
| `ObjectToKeyValuePairs(obj)` | Convert an object to `[key, value]` pairs |
|
|
99
|
+
| `ObjectGetPropertyByPath(obj, path)` | Get a nested property by dot-path |
|
|
100
|
+
| `ObjectSetPropertyByPath(obj, path, value)` | Set a nested property by dot-path |
|
|
101
|
+
| `ObjectInvert(obj)` | Swap keys and values |
|
|
102
|
+
| `ObjectFlatten(obj, separator?)` | Flatten nested object to dot-separated keys |
|
|
103
|
+
| `ObjectDiff(objA, objB)` | Compute added/removed/changed keys between two objects |
|
|
104
|
+
| `AssertObjectHasProperty(value, property, exception?)` | Assert object has an inherited or own property |
|
|
105
|
+
| `AssertObjectHasOwnProperty(value, property, exception?)` | Assert object has a direct own property |
|
|
106
|
+
| `AssertObjectPropertyNotNull(value, property, exception?)` | Assert object property is not null/undefined |
|
|
107
|
+
|
|
108
|
+
### String utilities — `StringUtils`
|
|
109
|
+
|
|
110
|
+
| Export | Description |
|
|
111
|
+
|--------|-------------|
|
|
112
|
+
| `CamelCase(str)` | Convert a string to camelCase |
|
|
113
|
+
| `PASCAL_CASE(str)` | Convert a string to PascalCase |
|
|
114
|
+
| `KEBAB_CASE(str)` | Convert a string to kebab-case |
|
|
115
|
+
| `SNAKE_CASE(str)` | Convert a string to snake_case |
|
|
116
|
+
| `SCREAMING_SNAKE_CASE(str)` | Convert a string to SCREAMING_SNAKE_CASE |
|
|
117
|
+
| `FormatString(template, values)` | Simple string template formatting |
|
|
118
|
+
| `EscapeHTML(str)` | Escape HTML special characters |
|
|
119
|
+
| `StripHTML(str)` | Remove all HTML tags from a string |
|
|
120
|
+
| `Pluralize(word, count, plural?)` | Return singular or plural form based on count |
|
|
121
|
+
| `WordCount(str)` | Count the number of words in a string |
|
|
122
|
+
| `CountOccurrences(str, substr)` | Count non-overlapping occurrences of a substring |
|
|
123
|
+
| `AssertString(value, exception?)` | Assert value is a string primitive |
|
|
124
|
+
| `AssertStringNotEmpty(value, exception?)` | Assert value is a non-empty, non-whitespace string |
|
|
125
|
+
| `AssertStringMatches(value, regex, exception?)` | Assert string matches a regular expression |
|
|
126
|
+
|
|
127
|
+
### Time utilities — `TimeUtils`
|
|
128
|
+
|
|
129
|
+
| Export | Description |
|
|
130
|
+
|--------|-------------|
|
|
131
|
+
| `ElapsedTime` | Measure elapsed time with human-readable output |
|
|
132
|
+
| `Stopwatch` | Lap-based stopwatch for benchmarking |
|
|
133
|
+
|
|
134
|
+
### Enum utilities — `EnumUtils`
|
|
135
|
+
|
|
136
|
+
| Export | Description |
|
|
137
|
+
|--------|-------------|
|
|
138
|
+
| `EnumKeys(enumObj)` | Get keys of a TypeScript enum |
|
|
139
|
+
| `EnumValues(enumObj)` | Get values of a TypeScript enum |
|
|
140
|
+
| `EnumEntries(enumObj)` | Get key-value pairs of a TypeScript enum |
|
|
141
|
+
| `ValidateEnumValue(enumObj, value)` | Check if a value is a valid enum member |
|
|
142
|
+
| `EnumKeyByValue(enumObj, value)` | Look up an enum key by its value |
|
|
143
|
+
| `EnumSafeValue(enumObj, value)` | Return the value if valid, or `undefined` |
|
|
144
|
+
|
|
145
|
+
### Function utilities — `FunctionUtils`
|
|
146
|
+
|
|
147
|
+
| Export | Description |
|
|
148
|
+
|--------|-------------|
|
|
149
|
+
| `Debounce(fn, ms)` | Delay execution until `ms` ms after the last call |
|
|
150
|
+
| `Throttle(fn, ms)` | Limit execution to at most once per `ms` ms |
|
|
151
|
+
| `Memoize(fn, keyFn?)` | Cache results by serialised arguments |
|
|
152
|
+
| `Once(fn)` | Execute a function at most once, caching the result |
|
|
153
|
+
| `Pipe(...fns)` | Compose functions left-to-right |
|
|
154
|
+
| `Compose(...fns)` | Compose functions right-to-left |
|
|
155
|
+
| `Sleep(ms)` | Return a `Promise` that resolves after `ms` ms |
|
|
156
|
+
|
|
157
|
+
### Assertion utilities — `AssertsUtils`
|
|
158
|
+
|
|
159
|
+
Cross-cutting assertions not tied to a single type, plus the shared assertion infrastructure.
|
|
160
|
+
|
|
161
|
+
| Export | Description |
|
|
162
|
+
|--------|-------------|
|
|
163
|
+
| `AssertEquals(value, expected, exception?)` | Assert two values are deeply equal |
|
|
164
|
+
| `AssertNotEquals(value, expected, exception?)` | Assert two values are not deeply equal |
|
|
165
|
+
| `AssertNull(value, exception?)` | Assert value is `null` or `undefined` |
|
|
166
|
+
| `AssertNotNull(value, exception?)` | Assert value is neither `null` nor `undefined` |
|
|
167
|
+
| `AssertPredicate(value, predicate, exception?)` | Assert a custom predicate holds |
|
|
168
|
+
| `AssertIsType(value, typeGuard, exception?)` | Assert via a type-guard function |
|
|
169
|
+
| `AssertInstanceOf(value, constructor, exception?)` | Assert value is an instance of a constructor |
|
|
170
|
+
| `AssertFunction(value, exception?)` | Assert value is a function |
|
|
171
|
+
| `AssertSymbol(value, exception?)` | Assert value is a symbol |
|
|
172
|
+
| `AssertExtends(derived, base, exception?)` | Assert one class extends another |
|
|
173
|
+
| `ThrowException(exception)` | Throw using an `IAssertException` config object |
|
|
174
|
+
| `SetExceptionClass(exception, class, force?)` | Configure the error class for an assertion |
|
|
175
|
+
| `SetExceptionMessage(exception, message, force?)` | Configure the error message for an assertion |
|
|
176
|
+
|
|
177
|
+
**All type-specific assertions** (`AssertArray`, `AssertBoolean`, `AssertNumber`, `AssertObject` (throwing), `AssertString`, etc.) are also accessible through `AssertsUtils` as a single convenience namespace.
|
|
178
|
+
|
|
179
|
+
**Note:** `AssertsUtils.AssertObject` is the throwing assertion (narrows to `Record<string, unknown>`). `ObjectUtils.AssertObject` is the boolean predicate (returns `true`/`false`).
|
|
180
|
+
|
|
181
|
+
#### Error classes
|
|
182
|
+
|
|
183
|
+
`BaseError`, `ValidationError`, `AssertionError`, `InvalidArgumentError`, `NotFoundError`, `NotSupportedError`, `BufferOverflowError`, `ArrayError`, `BooleanError`, `NumberError`, `NumberRangeError`, `ObjectError`, `ObjectPropertyError`, `StringError`, `NullError`, `NotNullError`, `PredicateError`, `TypeGuardError`, `InstanceOfError`, `FunctionError`, `SymbolError`, `ExtendsError`.
|
|
184
|
+
|
|
185
|
+
## Development
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
yarn install # Install dependencies
|
|
189
|
+
yarn build # Compile TypeScript → ./build/
|
|
190
|
+
yarn dev # Build + run
|
|
191
|
+
yarn watch # Watch mode
|
|
192
|
+
yarn typecheck # Type check without building
|
|
193
|
+
yarn lint # ESLint
|
|
194
|
+
yarn lint:fix # ESLint with auto-fix
|
|
195
|
+
yarn test # Run tests
|
|
196
|
+
yarn test:ui # Interactive Vitest UI
|
|
197
|
+
yarn test:coverage # Tests with coverage report
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Requirements
|
|
201
|
+
|
|
202
|
+
- Node.js >= 24.0.0
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT — See [LICENSE](./LICENSE) for details.
|
|
207
|
+
|
|
208
|
+
|
|
34
209
|
## API
|
|
35
210
|
|
|
36
211
|
### Array utilities — `ArrayUtils`
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { IAssertException } from '../asserts/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type alias for size constraint properties.
|
|
4
|
+
* Represents constraints that can be applied to array dimensions.
|
|
5
|
+
*/
|
|
6
|
+
export type TSizeConstraint = {
|
|
7
|
+
/** Exact size requirement */
|
|
8
|
+
size?: number;
|
|
9
|
+
/** Minimum size requirement (inclusive) */
|
|
10
|
+
minSize?: number;
|
|
11
|
+
/** Maximum size requirement (inclusive) */
|
|
12
|
+
maxSize?: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Type alias for 2D dimension constraint properties.
|
|
16
|
+
* Represents constraints that can be applied to matrix dimensions.
|
|
17
|
+
*/
|
|
18
|
+
export type TDimensionConstraint = {
|
|
19
|
+
/** Exact dimension requirement */
|
|
20
|
+
exact?: number;
|
|
21
|
+
/** Minimum dimension requirement (inclusive) */
|
|
22
|
+
min?: number;
|
|
23
|
+
/** Maximum dimension requirement (inclusive) */
|
|
24
|
+
max?: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Error thrown when a value is not a valid array or fails an array assertion.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* throw new ArrayError('Value is not a valid array');
|
|
31
|
+
*/
|
|
32
|
+
export declare class ArrayError extends Error {
|
|
33
|
+
constructor(message?: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Configuration interface for array validation constraints.
|
|
37
|
+
*
|
|
38
|
+
* Provides flexible size constraints for array validation, allowing
|
|
39
|
+
* exact size matching or range-based validation with min/max bounds.
|
|
40
|
+
* All size constraints are inclusive.
|
|
41
|
+
*/
|
|
42
|
+
export interface IAssertArrayArgs {
|
|
43
|
+
/** Exact number of elements the array must contain */
|
|
44
|
+
size?: number;
|
|
45
|
+
/** Minimum number of elements the array must contain (inclusive) */
|
|
46
|
+
minSize?: number;
|
|
47
|
+
/** Maximum number of elements the array must contain (inclusive) */
|
|
48
|
+
maxSize?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Configuration interface for 2D array (matrix) validation constraints.
|
|
52
|
+
*
|
|
53
|
+
* Supports validation of rectangular matrices with configurable dimensions.
|
|
54
|
+
* Can validate exact dimensions or enforce minimum/maximum row and column counts.
|
|
55
|
+
* All dimension constraints are inclusive. Ensures all rows have uniform column count.
|
|
56
|
+
*/
|
|
57
|
+
export interface IAssertArray2DArgs {
|
|
58
|
+
/** Exact number of rows the 2D array must have */
|
|
59
|
+
rows?: number;
|
|
60
|
+
/** Exact number of columns each row must have */
|
|
61
|
+
columns?: number;
|
|
62
|
+
/** Minimum number of rows the 2D array must have (inclusive) */
|
|
63
|
+
minRows?: number;
|
|
64
|
+
/** Minimum number of columns each row must have (inclusive) */
|
|
65
|
+
minColumns?: number;
|
|
66
|
+
/** Maximum number of rows the 2D array must have (inclusive) */
|
|
67
|
+
maxRows?: number;
|
|
68
|
+
/** Maximum number of columns each row must have (inclusive) */
|
|
69
|
+
maxColumns?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Asserts that a value is an array, optionally validating its size.
|
|
73
|
+
* @template T The type of array elements.
|
|
74
|
+
* @param value The value to validate.
|
|
75
|
+
* @param args Optional size constraints.
|
|
76
|
+
* @param exception Optional custom exception to throw.
|
|
77
|
+
* @throws {ArrayError} If the value is not an array or fails size validation.
|
|
78
|
+
*/
|
|
79
|
+
export declare function AssertArray<T = unknown>(value: unknown, args?: IAssertArrayArgs, exceptionInput?: IAssertException): asserts value is T[];
|
|
80
|
+
/**
|
|
81
|
+
* Asserts that a value is a 2D array, optionally validating its dimensions.
|
|
82
|
+
* @template T The type of array elements.
|
|
83
|
+
* @param value The value to validate.
|
|
84
|
+
* @param args Optional dimension constraints.
|
|
85
|
+
* @param exception Optional custom exception to throw.
|
|
86
|
+
* @throws {ArrayError} If the value is not a 2D array or fails dimension validation.
|
|
87
|
+
*/
|
|
88
|
+
export declare function AssertArray2D<T = unknown>(value: unknown, args?: IAssertArray2DArgs, exception?: IAssertException): asserts value is T[][];
|
|
89
|
+
/**
|
|
90
|
+
* Asserts that an array is not empty.
|
|
91
|
+
* @template T The type of array elements.
|
|
92
|
+
* @param value The array to validate.
|
|
93
|
+
* @param exception Optional custom exception to throw.
|
|
94
|
+
* @throws {ArrayError} If the array is empty.
|
|
95
|
+
*/
|
|
96
|
+
export declare function AssertArrayNotEmpty<T>(value: T[] | unknown, exception?: IAssertException): asserts value is T[];
|
|
97
|
+
/**
|
|
98
|
+
* Asserts that all elements in an array satisfy a predicate.
|
|
99
|
+
* @template T The type of array elements.
|
|
100
|
+
* @param array The array to validate.
|
|
101
|
+
* @param predicate A function to test each element.
|
|
102
|
+
* @param exception Optional custom exception to throw.
|
|
103
|
+
* @throws {ArrayError} If any element fails the predicate test.
|
|
104
|
+
*/
|
|
105
|
+
export declare function AssertArrayAll<T>(array: T[], predicate: (el: T, idx: number, arr: T[]) => boolean, exception?: IAssertException): void;
|
|
106
|
+
/**
|
|
107
|
+
* Asserts that at least one element in an array satisfies a predicate.
|
|
108
|
+
* @template T The type of array elements.
|
|
109
|
+
* @param array The array to validate.
|
|
110
|
+
* @param predicate A function to test each element.
|
|
111
|
+
* @param exception Optional custom exception to throw.
|
|
112
|
+
* @throws {ArrayError} If no elements pass the predicate test.
|
|
113
|
+
*/
|
|
114
|
+
export declare function AssertArrayAny<T>(array: T[], predicate: (el: T, idx: number, arr: T[]) => boolean, exception?: IAssertException): void;
|
|
115
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/array/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAClC,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACxB,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACl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EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAe1I"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { SetExceptionClass, SetExceptionMessage, ThrowException } from '../asserts/utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when a value is not a valid array or fails an array assertion.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* throw new ArrayError('Value is not a valid array');
|
|
7
|
+
*/
|
|
8
|
+
export class ArrayError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message ?? 'Array assertion failed');
|
|
11
|
+
this.name = 'ArrayError';
|
|
12
|
+
Object.setPrototypeOf(this, ArrayError.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Asserts that a value is an array, optionally validating its size.
|
|
17
|
+
* @template T The type of array elements.
|
|
18
|
+
* @param value The value to validate.
|
|
19
|
+
* @param args Optional size constraints.
|
|
20
|
+
* @param exception Optional custom exception to throw.
|
|
21
|
+
* @throws {ArrayError} If the value is not an array or fails size validation.
|
|
22
|
+
*/
|
|
23
|
+
export function AssertArray(value, args, exceptionInput = {}) {
|
|
24
|
+
// Initialize exception configuration with defaults
|
|
25
|
+
const exception = exceptionInput ?? {};
|
|
26
|
+
SetExceptionClass(exception, ArrayError);
|
|
27
|
+
// Validate that the value is an array
|
|
28
|
+
if (!Array.isArray(value)) {
|
|
29
|
+
SetExceptionMessage(exception, `Expected array but received ${typeof value}: ${String(value)}`);
|
|
30
|
+
ThrowException(exception);
|
|
31
|
+
}
|
|
32
|
+
// Type cast is safe after array validation
|
|
33
|
+
const array = value;
|
|
34
|
+
// Validate exact size constraint if specified
|
|
35
|
+
if (args?.size !== undefined && array.length !== args.size) {
|
|
36
|
+
SetExceptionMessage(exception, `Expected array with size ${args.size} but received size ${array.length}`);
|
|
37
|
+
ThrowException(exception);
|
|
38
|
+
}
|
|
39
|
+
// Validate minimum size constraint if specified
|
|
40
|
+
if (args?.minSize !== undefined && array.length < args.minSize) {
|
|
41
|
+
SetExceptionMessage(exception, `Expected array with minimum size ${args.minSize} but received size ${array.length}`);
|
|
42
|
+
ThrowException(exception);
|
|
43
|
+
}
|
|
44
|
+
// Validate maximum size constraint if specified
|
|
45
|
+
if (args?.maxSize !== undefined && array.length > args.maxSize) {
|
|
46
|
+
SetExceptionMessage(exception, `Expected array with maximum size ${args.maxSize} but received size ${array.length}`);
|
|
47
|
+
ThrowException(exception);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Asserts that a value is a 2D array, optionally validating its dimensions.
|
|
52
|
+
* @template T The type of array elements.
|
|
53
|
+
* @param value The value to validate.
|
|
54
|
+
* @param args Optional dimension constraints.
|
|
55
|
+
* @param exception Optional custom exception to throw.
|
|
56
|
+
* @throws {ArrayError} If the value is not a 2D array or fails dimension validation.
|
|
57
|
+
*/
|
|
58
|
+
export function AssertArray2D(value, args = {}, exception = {}) {
|
|
59
|
+
// Initialize exception configuration with defaults
|
|
60
|
+
SetExceptionClass(exception, ArrayError);
|
|
61
|
+
// Validate that the value is an array
|
|
62
|
+
if (!Array.isArray(value)) {
|
|
63
|
+
SetExceptionMessage(exception, `Expected array but received ${typeof value}: ${String(value)}`);
|
|
64
|
+
ThrowException(exception);
|
|
65
|
+
}
|
|
66
|
+
// Type cast is safe after array validation
|
|
67
|
+
const array = value;
|
|
68
|
+
// Validate that all elements are arrays (making it 2D)
|
|
69
|
+
if (!array.every((row) => Array.isArray(row))) {
|
|
70
|
+
let invalidPositions = array.map((row, idx) => {
|
|
71
|
+
if (!Array.isArray(row))
|
|
72
|
+
return idx;
|
|
73
|
+
return null;
|
|
74
|
+
});
|
|
75
|
+
invalidPositions = invalidPositions.filter((idx) => idx !== null);
|
|
76
|
+
SetExceptionMessage(exception, `Expected 2D array but found non-array elements at positions: ${invalidPositions.join(', ')}`);
|
|
77
|
+
ThrowException(exception);
|
|
78
|
+
}
|
|
79
|
+
// Type cast is safe after 2D validation
|
|
80
|
+
const array2d = array;
|
|
81
|
+
const rows = array2d.length;
|
|
82
|
+
const [firstRow] = array2d;
|
|
83
|
+
const columns = firstRow ? firstRow.length : 0;
|
|
84
|
+
// Validate rectangular matrix structure (all rows have same column count)
|
|
85
|
+
if (!array2d.every((row) => row.length === columns)) {
|
|
86
|
+
SetExceptionMessage(exception, 'Array is not rectangular - rows have different column counts');
|
|
87
|
+
ThrowException(exception);
|
|
88
|
+
}
|
|
89
|
+
// Validate exact row count constraint if specified
|
|
90
|
+
if (args?.rows !== undefined && rows !== args.rows) {
|
|
91
|
+
SetExceptionMessage(exception, `Array has ${rows} rows, expected exactly ${args.rows}`);
|
|
92
|
+
ThrowException(exception);
|
|
93
|
+
}
|
|
94
|
+
// Validate exact column count constraint if specified
|
|
95
|
+
if (args?.columns !== undefined && columns !== args.columns) {
|
|
96
|
+
SetExceptionMessage(exception, `Array has ${columns} columns, expected exactly ${args.columns}`);
|
|
97
|
+
ThrowException(exception);
|
|
98
|
+
}
|
|
99
|
+
// Validate minimum row count constraint if specified
|
|
100
|
+
if (args?.minRows !== undefined && rows < args.minRows) {
|
|
101
|
+
SetExceptionMessage(exception, `Array has ${rows} rows, minimum required is ${args.minRows}`);
|
|
102
|
+
ThrowException(exception);
|
|
103
|
+
}
|
|
104
|
+
// Validate maximum row count constraint if specified
|
|
105
|
+
if (args?.maxRows !== undefined && rows > args.maxRows) {
|
|
106
|
+
SetExceptionMessage(exception, `Array has ${rows} rows, maximum allowed is ${args.maxRows}`);
|
|
107
|
+
ThrowException(exception);
|
|
108
|
+
}
|
|
109
|
+
// Validate minimum column count constraint if specified
|
|
110
|
+
if (args?.minColumns !== undefined && columns < args.minColumns) {
|
|
111
|
+
SetExceptionMessage(exception, `Array has ${columns} columns, minimum required is ${args.minColumns}`);
|
|
112
|
+
ThrowException(exception);
|
|
113
|
+
}
|
|
114
|
+
// Validate maximum column count constraint if specified
|
|
115
|
+
if (args?.maxColumns !== undefined && columns > args.maxColumns) {
|
|
116
|
+
SetExceptionMessage(exception, `Array has ${columns} columns, maximum allowed is ${args.maxColumns}`);
|
|
117
|
+
ThrowException(exception);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Asserts that an array is not empty.
|
|
122
|
+
* @template T The type of array elements.
|
|
123
|
+
* @param value The array to validate.
|
|
124
|
+
* @param exception Optional custom exception to throw.
|
|
125
|
+
* @throws {ArrayError} If the array is empty.
|
|
126
|
+
*/
|
|
127
|
+
export function AssertArrayNotEmpty(value, exception = {}) {
|
|
128
|
+
// Initialize exception configuration with defaults
|
|
129
|
+
SetExceptionClass(exception, ArrayError);
|
|
130
|
+
// First validate that it's an array using the base AssertArray function
|
|
131
|
+
AssertArray(value, undefined, exception);
|
|
132
|
+
// Then check if the array is empty
|
|
133
|
+
if (value.length === 0) {
|
|
134
|
+
SetExceptionMessage(exception, 'Array should not be empty');
|
|
135
|
+
ThrowException(exception);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Asserts that all elements in an array satisfy a predicate.
|
|
140
|
+
* @template T The type of array elements.
|
|
141
|
+
* @param array The array to validate.
|
|
142
|
+
* @param predicate A function to test each element.
|
|
143
|
+
* @param exception Optional custom exception to throw.
|
|
144
|
+
* @throws {ArrayError} If any element fails the predicate test.
|
|
145
|
+
*/
|
|
146
|
+
export function AssertArrayAll(array, predicate, exception = {}) {
|
|
147
|
+
// Initialize exception configuration with defaults
|
|
148
|
+
SetExceptionClass(exception, ArrayError);
|
|
149
|
+
// Validate that the value is an array
|
|
150
|
+
if (!Array.isArray(array)) {
|
|
151
|
+
SetExceptionMessage(exception, 'Value is not an array');
|
|
152
|
+
ThrowException(exception);
|
|
153
|
+
}
|
|
154
|
+
// Check if all elements satisfy the predicate
|
|
155
|
+
if (!array.every(predicate)) {
|
|
156
|
+
SetExceptionMessage(exception, 'Not all elements satisfy the predicate condition');
|
|
157
|
+
ThrowException(exception);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Asserts that at least one element in an array satisfies a predicate.
|
|
162
|
+
* @template T The type of array elements.
|
|
163
|
+
* @param array The array to validate.
|
|
164
|
+
* @param predicate A function to test each element.
|
|
165
|
+
* @param exception Optional custom exception to throw.
|
|
166
|
+
* @throws {ArrayError} If no elements pass the predicate test.
|
|
167
|
+
*/
|
|
168
|
+
export function AssertArrayAny(array, predicate, exception = {}) {
|
|
169
|
+
// Initialize exception configuration with defaults
|
|
170
|
+
SetExceptionClass(exception, ArrayError);
|
|
171
|
+
// Validate that the value is an array
|
|
172
|
+
if (!Array.isArray(array)) {
|
|
173
|
+
SetExceptionMessage(exception, 'Value is not an array');
|
|
174
|
+
ThrowException(exception);
|
|
175
|
+
}
|
|
176
|
+
// Check if any elements satisfy the predicate
|
|
177
|
+
if (!array.some(predicate)) {
|
|
178
|
+
SetExceptionMessage(exception, 'No elements satisfy the predicate condition');
|
|
179
|
+
ThrowException(exception);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/array/assert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA4B7F;;;;;GAKG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACpC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,wBAAwB,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;CACD;AAwCD;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAc,KAAc,EAAE,IAAuB,EA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C;QACxD,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,8CAA8C;IAC9C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,mBAAmB,CAAC,SAAS,EAAE,kDAAkD,CAAC,CAAC;QACnF,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAI,KAAU,EAAE,SAAoD,EAAE,YAA8B,EAAE;IACnI,mDAAmD;IACnD,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAEzC,sCAAsC;IACtC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,mBAAmB,CAAC,SAAS,EAAE,uBAAuB,CAAC,CAAC;QACxD,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,8CAA8C;IAC9C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,mBAAmB,CAAC,SAAS,EAAE,6CAA6C,CAAC,CAAC;QAC9E,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC"}
|
package/build/array/index.d.ts
CHANGED
|
@@ -24,4 +24,5 @@ export * from './array-count-by.js';
|
|
|
24
24
|
export * from './array-sample.js';
|
|
25
25
|
export type * from './array-element.js';
|
|
26
26
|
export type { TPredicate, TTransform, TComparator, TEqualityComparator } from './types.js';
|
|
27
|
+
export * from './assert.js';
|
|
27
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,mBAAmB,oBAAoB,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,mBAAmB,oBAAoB,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3F,cAAc,aAAa,CAAC"}
|
package/build/array/index.js
CHANGED
package/build/array/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all custom errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class BaseError extends Error {
|
|
5
|
+
readonly Code: string;
|
|
6
|
+
readonly Context: Record<string, unknown> | undefined;
|
|
7
|
+
constructor(message: string, code: string, context?: Record<string, unknown>);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when validation fails
|
|
11
|
+
*/
|
|
12
|
+
export declare class ValidationError extends BaseError {
|
|
13
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown when a type assertion fails
|
|
17
|
+
*/
|
|
18
|
+
export declare class AssertionError extends BaseError {
|
|
19
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Error thrown when an argument is invalid
|
|
23
|
+
*/
|
|
24
|
+
export declare class InvalidArgumentError extends BaseError {
|
|
25
|
+
constructor(argumentName: string, reason: string, context?: Record<string, unknown>);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when an operation is not supported
|
|
29
|
+
*/
|
|
30
|
+
export declare class NotSupportedError extends BaseError {
|
|
31
|
+
constructor(operation: string, context?: Record<string, unknown>);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when a required value is not found
|
|
35
|
+
*/
|
|
36
|
+
export declare class NotFoundError extends BaseError {
|
|
37
|
+
constructor(item: string, context?: Record<string, unknown>);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Error thrown when buffer overflow occurs
|
|
41
|
+
*/
|
|
42
|
+
export declare class BufferOverflowError extends BaseError {
|
|
43
|
+
constructor(maxSize: number, context?: Record<string, unknown>);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/asserts/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IACnC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;gBAEjD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAS5E;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG9D;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,SAAS;gBAChC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG9D;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;gBACtC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAGnF;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;gBACnC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAGhE;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,SAAS;gBAC/B,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG3D;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG9D"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all custom errors
|
|
3
|
+
*/
|
|
4
|
+
export class BaseError extends Error {
|
|
5
|
+
Code;
|
|
6
|
+
Context;
|
|
7
|
+
constructor(message, code, context) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = this.constructor.name;
|
|
10
|
+
this.Code = code;
|
|
11
|
+
this.Context = context;
|
|
12
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Error thrown when validation fails
|
|
19
|
+
*/
|
|
20
|
+
export class ValidationError extends BaseError {
|
|
21
|
+
constructor(message, context) {
|
|
22
|
+
super(message, 'VALIDATION_ERROR', context);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when a type assertion fails
|
|
27
|
+
*/
|
|
28
|
+
export class AssertionError extends BaseError {
|
|
29
|
+
constructor(message, context) {
|
|
30
|
+
super(message, 'ASSERTION_ERROR', context);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when an argument is invalid
|
|
35
|
+
*/
|
|
36
|
+
export class InvalidArgumentError extends BaseError {
|
|
37
|
+
constructor(argumentName, reason, context) {
|
|
38
|
+
super(`Invalid argument '${argumentName}': ${reason}`, 'INVALID_ARGUMENT', context);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Error thrown when an operation is not supported
|
|
43
|
+
*/
|
|
44
|
+
export class NotSupportedError extends BaseError {
|
|
45
|
+
constructor(operation, context) {
|
|
46
|
+
super(`Operation not supported: ${operation}`, 'NOT_SUPPORTED', context);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Error thrown when a required value is not found
|
|
51
|
+
*/
|
|
52
|
+
export class NotFoundError extends BaseError {
|
|
53
|
+
constructor(item, context) {
|
|
54
|
+
super(`Not found: ${item}`, 'NOT_FOUND', context);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when buffer overflow occurs
|
|
59
|
+
*/
|
|
60
|
+
export class BufferOverflowError extends BaseError {
|
|
61
|
+
constructor(maxSize, context) {
|
|
62
|
+
super(`Buffer overflow: maximum size ${maxSize} exceeded`, 'BUFFER_OVERFLOW', context);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/asserts/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IACnB,IAAI,CAAS;IAEb,OAAO,CAAsC;IAE7D,YAAY,OAAe,EAAE,IAAY,EAAE,OAAiC;QAC3E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;YACnD,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC7C,YAAY,OAAe,EAAE,OAAiC;QAC7D,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC5C,YAAY,OAAe,EAAE,OAAiC;QAC7D,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAClD,YAAY,YAAoB,EAAE,MAAc,EAAE,OAAiC;QAClF,KAAK,CAAC,qBAAqB,YAAY,MAAM,MAAM,EAAE,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;IACrF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,S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