@alextheman/utility 5.15.0 → 5.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +88 -46
- package/dist/index.d.cts +246 -217
- package/dist/index.d.ts +245 -216
- package/dist/index.js +88 -47
- package/dist/internal/index.cjs +26 -3
- package/dist/internal/index.d.cts +15 -2
- package/dist/internal/index.d.ts +15 -2
- package/dist/internal/index.js +26 -3
- package/dist/node/index.cjs +26 -3
- package/dist/node/index.js +26 -3
- package/dist/v6/index.cjs +146 -3
- package/dist/v6/index.d.cts +123 -6
- package/dist/v6/index.d.ts +123 -6
- package/dist/v6/index.js +145 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -14,6 +14,51 @@ const UUID_REGEX = new RegExp(`^${UUID_PATTERN}$`);
|
|
|
14
14
|
const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
|
|
15
15
|
const VERSION_NUMBER_REGEX = RegExp(`^${VERSION_NUMBER_PATTERN}$`);
|
|
16
16
|
//#endregion
|
|
17
|
+
//#region src/root/deprecated/APIError.ts
|
|
18
|
+
const httpErrorCodeLookup = {
|
|
19
|
+
400: "BAD_REQUEST",
|
|
20
|
+
401: "UNAUTHORISED",
|
|
21
|
+
403: "FORBIDDEN",
|
|
22
|
+
404: "NOT_FOUND",
|
|
23
|
+
418: "I_AM_A_TEAPOT",
|
|
24
|
+
500: "INTERNAL_SERVER_ERROR"
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Represents common errors you may get from a HTTP API request.
|
|
28
|
+
*
|
|
29
|
+
* @category Types
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Please use `APIError` from `@alextheman/utility/v6` instead.
|
|
32
|
+
*/
|
|
33
|
+
var APIError = class APIError extends Error {
|
|
34
|
+
status;
|
|
35
|
+
/**
|
|
36
|
+
* @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
|
|
37
|
+
* @param message - An error message to display alongside the status code.
|
|
38
|
+
* @param options - Extra options to be passed to super Error constructor.
|
|
39
|
+
*/
|
|
40
|
+
constructor(status = 500, message, options) {
|
|
41
|
+
super(message, options);
|
|
42
|
+
this.status = status;
|
|
43
|
+
if (message) this.message = message;
|
|
44
|
+
else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
|
|
45
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
46
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether the given input may have been caused by an APIError.
|
|
50
|
+
*
|
|
51
|
+
* @param input - The input to check.
|
|
52
|
+
*
|
|
53
|
+
* @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
|
|
54
|
+
*/
|
|
55
|
+
static check(input) {
|
|
56
|
+
if (input instanceof APIError) return true;
|
|
57
|
+
const data = input;
|
|
58
|
+
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
17
62
|
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
18
63
|
/**
|
|
19
64
|
* Creates a new array where each element is the result of the provided callback.
|
|
@@ -161,6 +206,17 @@ var CodeError = class CodeError extends Error {
|
|
|
161
206
|
}
|
|
162
207
|
throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
|
|
163
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Converts the `CodeError` instance to a serialised JSON payload.
|
|
211
|
+
*
|
|
212
|
+
* @returns A JSON serialised version of the current `CodeError` instance.
|
|
213
|
+
*/
|
|
214
|
+
toJSON() {
|
|
215
|
+
return {
|
|
216
|
+
code: this.code,
|
|
217
|
+
message: this.message
|
|
218
|
+
};
|
|
219
|
+
}
|
|
164
220
|
};
|
|
165
221
|
//#endregion
|
|
166
222
|
//#region src/v6/DataError.ts
|
|
@@ -169,14 +225,15 @@ var CodeError = class CodeError extends Error {
|
|
|
169
225
|
*
|
|
170
226
|
* @category Types
|
|
171
227
|
*
|
|
172
|
-
* @template DataType
|
|
228
|
+
* @template DataType The type of the data that caused the error.
|
|
229
|
+
* @template ErrorCode The type of the standardised error code.
|
|
173
230
|
*/
|
|
174
231
|
var DataError$1 = class DataError$1 extends CodeError {
|
|
175
232
|
data;
|
|
176
233
|
/**
|
|
177
234
|
* @param data - The data that caused the error.
|
|
178
235
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
179
|
-
* @param message
|
|
236
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
180
237
|
* @param options - Extra options to pass to super Error constructor.
|
|
181
238
|
*/
|
|
182
239
|
constructor(data, code, message = "The data provided is invalid", options) {
|
|
@@ -196,7 +253,7 @@ var DataError$1 = class DataError$1 extends CodeError {
|
|
|
196
253
|
*/
|
|
197
254
|
static check(input) {
|
|
198
255
|
if (input instanceof DataError$1) return true;
|
|
199
|
-
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
|
|
256
|
+
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
|
|
200
257
|
}
|
|
201
258
|
/**
|
|
202
259
|
* Check a `DataError` against its error code
|
|
@@ -241,6 +298,17 @@ var DataError$1 = class DataError$1 extends CodeError {
|
|
|
241
298
|
static async expectErrorAsync(errorFunction, options) {
|
|
242
299
|
return await super.expectErrorAsync(errorFunction, options);
|
|
243
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Converts the `DataError` instance to a serialised JSON payload.
|
|
303
|
+
*
|
|
304
|
+
* @returns A JSON serialised version of the current `DataError` instance.
|
|
305
|
+
*/
|
|
306
|
+
toJSON() {
|
|
307
|
+
return {
|
|
308
|
+
...super.toJSON(),
|
|
309
|
+
data: this.data
|
|
310
|
+
};
|
|
311
|
+
}
|
|
244
312
|
};
|
|
245
313
|
//#endregion
|
|
246
314
|
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
@@ -898,49 +966,6 @@ function parseBoolean(inputString) {
|
|
|
898
966
|
return normalisedString === "true";
|
|
899
967
|
}
|
|
900
968
|
//#endregion
|
|
901
|
-
//#region src/root/types/APIError.ts
|
|
902
|
-
const httpErrorCodeLookup = {
|
|
903
|
-
400: "BAD_REQUEST",
|
|
904
|
-
401: "UNAUTHORISED",
|
|
905
|
-
403: "FORBIDDEN",
|
|
906
|
-
404: "NOT_FOUND",
|
|
907
|
-
418: "I_AM_A_TEAPOT",
|
|
908
|
-
500: "INTERNAL_SERVER_ERROR"
|
|
909
|
-
};
|
|
910
|
-
/**
|
|
911
|
-
* Represents common errors you may get from a HTTP API request.
|
|
912
|
-
*
|
|
913
|
-
* @category Types
|
|
914
|
-
*/
|
|
915
|
-
var APIError = class APIError extends Error {
|
|
916
|
-
status;
|
|
917
|
-
/**
|
|
918
|
-
* @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
|
|
919
|
-
* @param message - An error message to display alongside the status code.
|
|
920
|
-
* @param options - Extra options to be passed to super Error constructor.
|
|
921
|
-
*/
|
|
922
|
-
constructor(status = 500, message, options) {
|
|
923
|
-
super(message, options);
|
|
924
|
-
this.status = status;
|
|
925
|
-
if (message) this.message = message;
|
|
926
|
-
else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
|
|
927
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
928
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* Checks whether the given input may have been caused by an APIError.
|
|
932
|
-
*
|
|
933
|
-
* @param input - The input to check.
|
|
934
|
-
*
|
|
935
|
-
* @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
|
|
936
|
-
*/
|
|
937
|
-
static check(input) {
|
|
938
|
-
if (input instanceof APIError) return true;
|
|
939
|
-
const data = input;
|
|
940
|
-
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
//#endregion
|
|
944
969
|
//#region src/root/types/VersionNumber.ts
|
|
945
970
|
/**
|
|
946
971
|
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
@@ -1806,4 +1831,20 @@ var DataError = class DataError extends Error {
|
|
|
1806
1831
|
}
|
|
1807
1832
|
};
|
|
1808
1833
|
//#endregion
|
|
1809
|
-
|
|
1834
|
+
//#region src/root/errors/assertNotNull.ts
|
|
1835
|
+
/**
|
|
1836
|
+
* Asserts that a given input is not `null`, and throws a DataError if it does.
|
|
1837
|
+
*
|
|
1838
|
+
* If no error is thrown from this, the input type gets narrowed down to not include `null`.
|
|
1839
|
+
*
|
|
1840
|
+
* @template InputType The type of the input.
|
|
1841
|
+
*
|
|
1842
|
+
* @param input - The input to assert against
|
|
1843
|
+
*
|
|
1844
|
+
* @throws {DataError} If the input is `null`.
|
|
1845
|
+
*/
|
|
1846
|
+
function assertNotNull(input) {
|
|
1847
|
+
if (input === null) throw new DataError$1({ input }, "NULL_INPUT", "Expected the input not to be null");
|
|
1848
|
+
}
|
|
1849
|
+
//#endregion
|
|
1850
|
+
export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, assertNotNull, az, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
package/dist/internal/index.cjs
CHANGED
|
@@ -184,6 +184,17 @@ var CodeError = class CodeError extends Error {
|
|
|
184
184
|
}
|
|
185
185
|
throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Converts the `CodeError` instance to a serialised JSON payload.
|
|
189
|
+
*
|
|
190
|
+
* @returns A JSON serialised version of the current `CodeError` instance.
|
|
191
|
+
*/
|
|
192
|
+
toJSON() {
|
|
193
|
+
return {
|
|
194
|
+
code: this.code,
|
|
195
|
+
message: this.message
|
|
196
|
+
};
|
|
197
|
+
}
|
|
187
198
|
};
|
|
188
199
|
//#endregion
|
|
189
200
|
//#region src/v6/DataError.ts
|
|
@@ -192,14 +203,15 @@ var CodeError = class CodeError extends Error {
|
|
|
192
203
|
*
|
|
193
204
|
* @category Types
|
|
194
205
|
*
|
|
195
|
-
* @template DataType
|
|
206
|
+
* @template DataType The type of the data that caused the error.
|
|
207
|
+
* @template ErrorCode The type of the standardised error code.
|
|
196
208
|
*/
|
|
197
209
|
var DataError = class DataError extends CodeError {
|
|
198
210
|
data;
|
|
199
211
|
/**
|
|
200
212
|
* @param data - The data that caused the error.
|
|
201
213
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
202
|
-
* @param message
|
|
214
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
203
215
|
* @param options - Extra options to pass to super Error constructor.
|
|
204
216
|
*/
|
|
205
217
|
constructor(data, code, message = "The data provided is invalid", options) {
|
|
@@ -219,7 +231,7 @@ var DataError = class DataError extends CodeError {
|
|
|
219
231
|
*/
|
|
220
232
|
static check(input) {
|
|
221
233
|
if (input instanceof DataError) return true;
|
|
222
|
-
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
|
|
234
|
+
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
|
|
223
235
|
}
|
|
224
236
|
/**
|
|
225
237
|
* Check a `DataError` against its error code
|
|
@@ -264,6 +276,17 @@ var DataError = class DataError extends CodeError {
|
|
|
264
276
|
static async expectErrorAsync(errorFunction, options) {
|
|
265
277
|
return await super.expectErrorAsync(errorFunction, options);
|
|
266
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Converts the `DataError` instance to a serialised JSON payload.
|
|
281
|
+
*
|
|
282
|
+
* @returns A JSON serialised version of the current `DataError` instance.
|
|
283
|
+
*/
|
|
284
|
+
toJSON() {
|
|
285
|
+
return {
|
|
286
|
+
...super.toJSON(),
|
|
287
|
+
data: this.data
|
|
288
|
+
};
|
|
289
|
+
}
|
|
267
290
|
};
|
|
268
291
|
//#endregion
|
|
269
292
|
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
@@ -89,6 +89,12 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
|
89
89
|
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
90
90
|
*/
|
|
91
91
|
static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<CodeError>;
|
|
92
|
+
/**
|
|
93
|
+
* Converts the `CodeError` instance to a serialised JSON payload.
|
|
94
|
+
*
|
|
95
|
+
* @returns A JSON serialised version of the current `CodeError` instance.
|
|
96
|
+
*/
|
|
97
|
+
toJSON(): Omit<CodeError<ErrorCode>, "toJSON" | "name">;
|
|
92
98
|
}
|
|
93
99
|
//#endregion
|
|
94
100
|
//#region src/v6/DataError.d.ts
|
|
@@ -97,14 +103,15 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
|
97
103
|
*
|
|
98
104
|
* @category Types
|
|
99
105
|
*
|
|
100
|
-
* @template DataType
|
|
106
|
+
* @template DataType The type of the data that caused the error.
|
|
107
|
+
* @template ErrorCode The type of the standardised error code.
|
|
101
108
|
*/
|
|
102
109
|
declare class DataError<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string> extends CodeError<ErrorCode> {
|
|
103
110
|
data: DataType;
|
|
104
111
|
/**
|
|
105
112
|
* @param data - The data that caused the error.
|
|
106
113
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
107
|
-
* @param message
|
|
114
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
108
115
|
* @param options - Extra options to pass to super Error constructor.
|
|
109
116
|
*/
|
|
110
117
|
constructor(data: DataType, code: ErrorCode, message?: string, options?: ErrorOptions);
|
|
@@ -153,6 +160,12 @@ declare class DataError<DataType extends object = Record<PropertyKey, unknown>,
|
|
|
153
160
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
154
161
|
*/
|
|
155
162
|
static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError<DataType, ErrorCode>>;
|
|
163
|
+
/**
|
|
164
|
+
* Converts the `DataError` instance to a serialised JSON payload.
|
|
165
|
+
*
|
|
166
|
+
* @returns A JSON serialised version of the current `DataError` instance.
|
|
167
|
+
*/
|
|
168
|
+
toJSON(): Omit<DataError<DataType, ErrorCode>, "toJSON" | "name">;
|
|
156
169
|
}
|
|
157
170
|
//#endregion
|
|
158
171
|
//#region src/internal/DependencyGroup.d.ts
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -89,6 +89,12 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
|
89
89
|
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
90
90
|
*/
|
|
91
91
|
static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<CodeError>;
|
|
92
|
+
/**
|
|
93
|
+
* Converts the `CodeError` instance to a serialised JSON payload.
|
|
94
|
+
*
|
|
95
|
+
* @returns A JSON serialised version of the current `CodeError` instance.
|
|
96
|
+
*/
|
|
97
|
+
toJSON(): Omit<CodeError<ErrorCode>, "toJSON" | "name">;
|
|
92
98
|
}
|
|
93
99
|
//#endregion
|
|
94
100
|
//#region src/v6/DataError.d.ts
|
|
@@ -97,14 +103,15 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
|
97
103
|
*
|
|
98
104
|
* @category Types
|
|
99
105
|
*
|
|
100
|
-
* @template DataType
|
|
106
|
+
* @template DataType The type of the data that caused the error.
|
|
107
|
+
* @template ErrorCode The type of the standardised error code.
|
|
101
108
|
*/
|
|
102
109
|
declare class DataError<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string> extends CodeError<ErrorCode> {
|
|
103
110
|
data: DataType;
|
|
104
111
|
/**
|
|
105
112
|
* @param data - The data that caused the error.
|
|
106
113
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
107
|
-
* @param message
|
|
114
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
108
115
|
* @param options - Extra options to pass to super Error constructor.
|
|
109
116
|
*/
|
|
110
117
|
constructor(data: DataType, code: ErrorCode, message?: string, options?: ErrorOptions);
|
|
@@ -153,6 +160,12 @@ declare class DataError<DataType extends object = Record<PropertyKey, unknown>,
|
|
|
153
160
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
154
161
|
*/
|
|
155
162
|
static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError<DataType, ErrorCode>>;
|
|
163
|
+
/**
|
|
164
|
+
* Converts the `DataError` instance to a serialised JSON payload.
|
|
165
|
+
*
|
|
166
|
+
* @returns A JSON serialised version of the current `DataError` instance.
|
|
167
|
+
*/
|
|
168
|
+
toJSON(): Omit<DataError<DataType, ErrorCode>, "toJSON" | "name">;
|
|
156
169
|
}
|
|
157
170
|
//#endregion
|
|
158
171
|
//#region src/internal/DependencyGroup.d.ts
|
package/dist/internal/index.js
CHANGED
|
@@ -159,6 +159,17 @@ var CodeError = class CodeError extends Error {
|
|
|
159
159
|
}
|
|
160
160
|
throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
|
|
161
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Converts the `CodeError` instance to a serialised JSON payload.
|
|
164
|
+
*
|
|
165
|
+
* @returns A JSON serialised version of the current `CodeError` instance.
|
|
166
|
+
*/
|
|
167
|
+
toJSON() {
|
|
168
|
+
return {
|
|
169
|
+
code: this.code,
|
|
170
|
+
message: this.message
|
|
171
|
+
};
|
|
172
|
+
}
|
|
162
173
|
};
|
|
163
174
|
//#endregion
|
|
164
175
|
//#region src/v6/DataError.ts
|
|
@@ -167,14 +178,15 @@ var CodeError = class CodeError extends Error {
|
|
|
167
178
|
*
|
|
168
179
|
* @category Types
|
|
169
180
|
*
|
|
170
|
-
* @template DataType
|
|
181
|
+
* @template DataType The type of the data that caused the error.
|
|
182
|
+
* @template ErrorCode The type of the standardised error code.
|
|
171
183
|
*/
|
|
172
184
|
var DataError = class DataError extends CodeError {
|
|
173
185
|
data;
|
|
174
186
|
/**
|
|
175
187
|
* @param data - The data that caused the error.
|
|
176
188
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
177
|
-
* @param message
|
|
189
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
178
190
|
* @param options - Extra options to pass to super Error constructor.
|
|
179
191
|
*/
|
|
180
192
|
constructor(data, code, message = "The data provided is invalid", options) {
|
|
@@ -194,7 +206,7 @@ var DataError = class DataError extends CodeError {
|
|
|
194
206
|
*/
|
|
195
207
|
static check(input) {
|
|
196
208
|
if (input instanceof DataError) return true;
|
|
197
|
-
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
|
|
209
|
+
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
|
|
198
210
|
}
|
|
199
211
|
/**
|
|
200
212
|
* Check a `DataError` against its error code
|
|
@@ -239,6 +251,17 @@ var DataError = class DataError extends CodeError {
|
|
|
239
251
|
static async expectErrorAsync(errorFunction, options) {
|
|
240
252
|
return await super.expectErrorAsync(errorFunction, options);
|
|
241
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Converts the `DataError` instance to a serialised JSON payload.
|
|
256
|
+
*
|
|
257
|
+
* @returns A JSON serialised version of the current `DataError` instance.
|
|
258
|
+
*/
|
|
259
|
+
toJSON() {
|
|
260
|
+
return {
|
|
261
|
+
...super.toJSON(),
|
|
262
|
+
data: this.data
|
|
263
|
+
};
|
|
264
|
+
}
|
|
242
265
|
};
|
|
243
266
|
//#endregion
|
|
244
267
|
//#region src/root/functions/parsers/parseIntStrict.ts
|
package/dist/node/index.cjs
CHANGED
|
@@ -300,6 +300,17 @@ var CodeError = class CodeError extends Error {
|
|
|
300
300
|
}
|
|
301
301
|
throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
|
|
302
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Converts the `CodeError` instance to a serialised JSON payload.
|
|
305
|
+
*
|
|
306
|
+
* @returns A JSON serialised version of the current `CodeError` instance.
|
|
307
|
+
*/
|
|
308
|
+
toJSON() {
|
|
309
|
+
return {
|
|
310
|
+
code: this.code,
|
|
311
|
+
message: this.message
|
|
312
|
+
};
|
|
313
|
+
}
|
|
303
314
|
};
|
|
304
315
|
//#endregion
|
|
305
316
|
//#region src/v6/DataError.ts
|
|
@@ -308,14 +319,15 @@ var CodeError = class CodeError extends Error {
|
|
|
308
319
|
*
|
|
309
320
|
* @category Types
|
|
310
321
|
*
|
|
311
|
-
* @template DataType
|
|
322
|
+
* @template DataType The type of the data that caused the error.
|
|
323
|
+
* @template ErrorCode The type of the standardised error code.
|
|
312
324
|
*/
|
|
313
325
|
var DataError = class DataError extends CodeError {
|
|
314
326
|
data;
|
|
315
327
|
/**
|
|
316
328
|
* @param data - The data that caused the error.
|
|
317
329
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
318
|
-
* @param message
|
|
330
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
319
331
|
* @param options - Extra options to pass to super Error constructor.
|
|
320
332
|
*/
|
|
321
333
|
constructor(data, code, message = "The data provided is invalid", options) {
|
|
@@ -335,7 +347,7 @@ var DataError = class DataError extends CodeError {
|
|
|
335
347
|
*/
|
|
336
348
|
static check(input) {
|
|
337
349
|
if (input instanceof DataError) return true;
|
|
338
|
-
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
|
|
350
|
+
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
|
|
339
351
|
}
|
|
340
352
|
/**
|
|
341
353
|
* Check a `DataError` against its error code
|
|
@@ -380,6 +392,17 @@ var DataError = class DataError extends CodeError {
|
|
|
380
392
|
static async expectErrorAsync(errorFunction, options) {
|
|
381
393
|
return await super.expectErrorAsync(errorFunction, options);
|
|
382
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Converts the `DataError` instance to a serialised JSON payload.
|
|
397
|
+
*
|
|
398
|
+
* @returns A JSON serialised version of the current `DataError` instance.
|
|
399
|
+
*/
|
|
400
|
+
toJSON() {
|
|
401
|
+
return {
|
|
402
|
+
...super.toJSON(),
|
|
403
|
+
data: this.data
|
|
404
|
+
};
|
|
405
|
+
}
|
|
383
406
|
};
|
|
384
407
|
//#endregion
|
|
385
408
|
//#region src/node/functions/parseFilePath.ts
|
package/dist/node/index.js
CHANGED
|
@@ -276,6 +276,17 @@ var CodeError = class CodeError extends Error {
|
|
|
276
276
|
}
|
|
277
277
|
throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
|
|
278
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Converts the `CodeError` instance to a serialised JSON payload.
|
|
281
|
+
*
|
|
282
|
+
* @returns A JSON serialised version of the current `CodeError` instance.
|
|
283
|
+
*/
|
|
284
|
+
toJSON() {
|
|
285
|
+
return {
|
|
286
|
+
code: this.code,
|
|
287
|
+
message: this.message
|
|
288
|
+
};
|
|
289
|
+
}
|
|
279
290
|
};
|
|
280
291
|
//#endregion
|
|
281
292
|
//#region src/v6/DataError.ts
|
|
@@ -284,14 +295,15 @@ var CodeError = class CodeError extends Error {
|
|
|
284
295
|
*
|
|
285
296
|
* @category Types
|
|
286
297
|
*
|
|
287
|
-
* @template DataType
|
|
298
|
+
* @template DataType The type of the data that caused the error.
|
|
299
|
+
* @template ErrorCode The type of the standardised error code.
|
|
288
300
|
*/
|
|
289
301
|
var DataError = class DataError extends CodeError {
|
|
290
302
|
data;
|
|
291
303
|
/**
|
|
292
304
|
* @param data - The data that caused the error.
|
|
293
305
|
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
294
|
-
* @param message
|
|
306
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
295
307
|
* @param options - Extra options to pass to super Error constructor.
|
|
296
308
|
*/
|
|
297
309
|
constructor(data, code, message = "The data provided is invalid", options) {
|
|
@@ -311,7 +323,7 @@ var DataError = class DataError extends CodeError {
|
|
|
311
323
|
*/
|
|
312
324
|
static check(input) {
|
|
313
325
|
if (input instanceof DataError) return true;
|
|
314
|
-
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
|
|
326
|
+
return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input && typeof input.data === "object" && input.data !== null;
|
|
315
327
|
}
|
|
316
328
|
/**
|
|
317
329
|
* Check a `DataError` against its error code
|
|
@@ -356,6 +368,17 @@ var DataError = class DataError extends CodeError {
|
|
|
356
368
|
static async expectErrorAsync(errorFunction, options) {
|
|
357
369
|
return await super.expectErrorAsync(errorFunction, options);
|
|
358
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Converts the `DataError` instance to a serialised JSON payload.
|
|
373
|
+
*
|
|
374
|
+
* @returns A JSON serialised version of the current `DataError` instance.
|
|
375
|
+
*/
|
|
376
|
+
toJSON() {
|
|
377
|
+
return {
|
|
378
|
+
...super.toJSON(),
|
|
379
|
+
data: this.data
|
|
380
|
+
};
|
|
381
|
+
}
|
|
359
382
|
};
|
|
360
383
|
//#endregion
|
|
361
384
|
//#region src/node/functions/parseFilePath.ts
|