@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.
@@ -1,3 +1,101 @@
1
+ class _Error extends Error {
2
+ /**
3
+ * Creates and returns a 404 Not Found error instance with the given message.
4
+ * @param {string} message - The error message to include.
5
+ * @returns {_Error} A new Error instance with status code 404.
6
+ */
7
+ static notFound (message) {
8
+ return new _Error(`Not Found: ${message}`, 404)
9
+ }
10
+
11
+ static notImpled () {
12
+ return new _Error('Not Impled Yet', 501)
13
+ }
14
+
15
+ /**
16
+ * Creates and returns a new Error instance for not supported operations.
17
+ * @param {string} message - The error message to include.
18
+ * @returns {_Error} A new Error instance with "Not Supported:" prefix and 505 status code.
19
+ */
20
+ static notSupported (message) {
21
+ return new _Error('Not Supported:' + message, 505)
22
+ }
23
+
24
+ /**
25
+ * Checks if the given error is a "Not Supported" error.
26
+ * @param {Error|_Error|{[key:string]:any}|unknown} err - The error to check
27
+ * @returns {boolean} True if the error is a Not Supported error (code 505), false otherwise
28
+ */
29
+ static isNotSupported (err) {
30
+ // @ts-ignore
31
+ return err?.code === 505
32
+ }
33
+
34
+ /**
35
+ * Error constructor with custom message and code.
36
+ * @param {string} message - Error message
37
+ * @param {number|string} code - Error code
38
+ */
39
+ constructor (message, code) {
40
+ super(message);
41
+ this.code = code;
42
+ }
43
+ }
44
+
45
+ class AggregatedError extends Error {
46
+ /**
47
+ * Checks if the given error is an AggregatedErrorLike
48
+ * 1. have "message:string" property
49
+ * 2. have "errors:Error[]" property
50
+ * @param {any} err - The error to check
51
+ * @returns {boolean} True if the error is an AggregatedError, false otherwise
52
+ */
53
+ static isAggregatedErrorLike (err) {
54
+ return err && Array.isArray(err.errors)
55
+ }
56
+
57
+ /**
58
+ * Checks if the given error is an instance of AggregatedError.
59
+ * @param {Error} err - The error to check.
60
+ * @returns {boolean} True if the error is an AggregatedError, false otherwise.
61
+ */
62
+ static isAggregatedError (err) {
63
+ return err instanceof AggregatedError
64
+ }
65
+
66
+ /**
67
+ * Error constructor with custom message and code.
68
+ * @param {string} message - Error message
69
+ * @param {any[]} [errors] - Errors
70
+ */
71
+ constructor (message, errors) {
72
+ super(message);
73
+ this.errors = errors ?? [];
74
+ }
75
+
76
+ /**
77
+ * Adds an error to the errors collection.
78
+ * @param {any} err - The error object to be added.
79
+ */
80
+ addError (err) {
81
+ this.errors.push(err);
82
+ }
83
+
84
+ /**
85
+ * Removes a specific error from the errors array.
86
+ * @param {Error} err - The error instance to remove.
87
+ * @returns {boolean} True if the error was found and removed, false otherwise.
88
+ */
89
+ removeError (err) {
90
+ const index = this.errors.indexOf(err);
91
+ if (index === -1) {
92
+ return false
93
+ }
94
+ this.errors.splice(index, 1);
95
+ return true
96
+ }
97
+ }
98
+
1
99
  /**
2
100
  * @module LangUtils
3
101
  * @description Language utility functions
@@ -2567,8 +2665,9 @@ function chunk (array, size) {
2567
2665
  * @description Core language utilities for type checking, string manipulation, and common operations.
2568
2666
  */
2569
2667
 
2570
-
2571
2668
  var index = {
2669
+ _Error,
2670
+ AggregatedError,
2572
2671
  LangUtils,
2573
2672
  StringUtils,
2574
2673
  TypeUtils,
@@ -2587,5 +2686,5 @@ var index = {
2587
2686
  ArrayUtils
2588
2687
  };
2589
2688
 
2590
- export { ArrayBufferUtils, ArrayUtils, ClassProxyUtils, ExecUtils as Exec, ExecUtils, InstanceProxyUtils, LangUtils as Lang, LangUtils, PromiseUtils, ReflectUtils, StringUtils, TimeUtils, TypeUtils as Type, TypeAssert, TypeUtils, TypedArrayUtils, index as default };
2689
+ export { AggregatedError, ArrayBufferUtils, ArrayUtils, ClassProxyUtils, ExecUtils as Exec, ExecUtils, InstanceProxyUtils, LangUtils as Lang, LangUtils, PromiseUtils, ReflectUtils, StringUtils, TimeUtils, TypeUtils as Type, TypeAssert, TypeUtils, TypedArrayUtils, _Error, index as default };
2591
2690
  //# sourceMappingURL=index-dev.js.map