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