@creejs/commons-lang 2.1.20 → 2.1.21
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/cjs/index-dev.cjs +102 -1
- package/dist/cjs/index-dev.cjs.map +1 -1
- package/dist/cjs/index-min.cjs +1 -1
- package/dist/cjs/index-min.cjs.map +1 -1
- package/dist/esm/index-dev.js +101 -2
- package/dist/esm/index-dev.js.map +1 -1
- package/dist/esm/index-min.js +1 -1
- package/dist/esm/index-min.js.map +1 -1
- package/dist/umd/index.dev.js +102 -1
- package/dist/umd/index.dev.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
- package/types/_error.d.ts +30 -0
- package/types/aggregated-error.d.ts +34 -0
- package/types/index.d.ts +5 -1
package/dist/cjs/index-dev.cjs
CHANGED
|
@@ -2,6 +2,104 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
class _Error extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* Creates and returns a 404 Not Found error instance with the given message.
|
|
8
|
+
* @param {string} message - The error message to include.
|
|
9
|
+
* @returns {_Error} A new Error instance with status code 404.
|
|
10
|
+
*/
|
|
11
|
+
static notFound (message) {
|
|
12
|
+
return new _Error(`Not Found: ${message}`, 404)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static notImpled () {
|
|
16
|
+
return new _Error('Not Impled Yet', 501)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates and returns a new Error instance for not supported operations.
|
|
21
|
+
* @param {string} message - The error message to include.
|
|
22
|
+
* @returns {_Error} A new Error instance with "Not Supported:" prefix and 505 status code.
|
|
23
|
+
*/
|
|
24
|
+
static notSupported (message) {
|
|
25
|
+
return new _Error('Not Supported:' + message, 505)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the given error is a "Not Supported" error.
|
|
30
|
+
* @param {Error|_Error|{[key:string]:any}|unknown} err - The error to check
|
|
31
|
+
* @returns {boolean} True if the error is a Not Supported error (code 505), false otherwise
|
|
32
|
+
*/
|
|
33
|
+
static isNotSupported (err) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
return err?.code === 505
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Error constructor with custom message and code.
|
|
40
|
+
* @param {string} message - Error message
|
|
41
|
+
* @param {number|string} code - Error code
|
|
42
|
+
*/
|
|
43
|
+
constructor (message, code) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.code = code;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class AggregatedError extends Error {
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the given error is an AggregatedErrorLike
|
|
52
|
+
* 1. have "message:string" property
|
|
53
|
+
* 2. have "errors:Error[]" property
|
|
54
|
+
* @param {any} err - The error to check
|
|
55
|
+
* @returns {boolean} True if the error is an AggregatedError, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
static isAggregatedErrorLike (err) {
|
|
58
|
+
return err && Array.isArray(err.errors)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the given error is an instance of AggregatedError.
|
|
63
|
+
* @param {Error} err - The error to check.
|
|
64
|
+
* @returns {boolean} True if the error is an AggregatedError, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
static isAggregatedError (err) {
|
|
67
|
+
return err instanceof AggregatedError
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Error constructor with custom message and code.
|
|
72
|
+
* @param {string} message - Error message
|
|
73
|
+
* @param {any[]} [errors] - Errors
|
|
74
|
+
*/
|
|
75
|
+
constructor (message, errors) {
|
|
76
|
+
super(message);
|
|
77
|
+
this.errors = errors ?? [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Adds an error to the errors collection.
|
|
82
|
+
* @param {any} err - The error object to be added.
|
|
83
|
+
*/
|
|
84
|
+
addError (err) {
|
|
85
|
+
this.errors.push(err);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Removes a specific error from the errors array.
|
|
90
|
+
* @param {Error} err - The error instance to remove.
|
|
91
|
+
* @returns {boolean} True if the error was found and removed, false otherwise.
|
|
92
|
+
*/
|
|
93
|
+
removeError (err) {
|
|
94
|
+
const index = this.errors.indexOf(err);
|
|
95
|
+
if (index === -1) {
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
this.errors.splice(index, 1);
|
|
99
|
+
return true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
5
103
|
/**
|
|
6
104
|
* @module LangUtils
|
|
7
105
|
* @description Language utility functions
|
|
@@ -2571,8 +2669,9 @@ function chunk (array, size) {
|
|
|
2571
2669
|
* @description Core language utilities for type checking, string manipulation, and common operations.
|
|
2572
2670
|
*/
|
|
2573
2671
|
|
|
2574
|
-
|
|
2575
2672
|
var index = {
|
|
2673
|
+
_Error,
|
|
2674
|
+
AggregatedError,
|
|
2576
2675
|
LangUtils,
|
|
2577
2676
|
StringUtils,
|
|
2578
2677
|
TypeUtils,
|
|
@@ -2591,6 +2690,7 @@ var index = {
|
|
|
2591
2690
|
ArrayUtils
|
|
2592
2691
|
};
|
|
2593
2692
|
|
|
2693
|
+
exports.AggregatedError = AggregatedError;
|
|
2594
2694
|
exports.ArrayBufferUtils = ArrayBufferUtils;
|
|
2595
2695
|
exports.ArrayUtils = ArrayUtils;
|
|
2596
2696
|
exports.ClassProxyUtils = ClassProxyUtils;
|
|
@@ -2607,5 +2707,6 @@ exports.Type = TypeUtils;
|
|
|
2607
2707
|
exports.TypeAssert = TypeAssert;
|
|
2608
2708
|
exports.TypeUtils = TypeUtils;
|
|
2609
2709
|
exports.TypedArrayUtils = TypedArrayUtils;
|
|
2710
|
+
exports._Error = _Error;
|
|
2610
2711
|
exports.default = index;
|
|
2611
2712
|
//# sourceMappingURL=index-dev.cjs.map
|