UNPKG

@byloth/exceptions

Version:

Handle exceptions with ease, create better stacktraces and manage everything in the right place. ❌

1 lines 175 kB
{"version":3,"file":"exceptions.umd.cjs","sources":["../node_modules/.pnpm/@byloth+core@2.0.0/node_modules/@byloth/core/dist/core.js","../src/models/exceptions.ts","../src/models/handler-builder.ts","../src/helpers.ts","../src/index.ts"],"sourcesContent":["var ze = Object.defineProperty;\nvar De = (i, t, e) => t in i ? ze(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;\nvar a = (i, t, e) => De(i, typeof t != \"symbol\" ? t + \"\" : t, e);\nconst Oe = typeof window < \"u\" && typeof window.document < \"u\";\nvar I;\nconst Ze = typeof process < \"u\" && !!((I = process.versions) != null && I.node);\nvar A;\nconst We = typeof self == \"object\" && ((A = self.constructor) == null ? void 0 : A.name) === \"DedicatedWorkerGlobalScope\";\nvar N, O;\nclass c extends (O = Error, N = Symbol.toStringTag, O) {\n /**\n * Initializes a new instance of the {@link Exception} class.\n *\n * ```ts\n * throw new Exception(\"An error occurred while processing the request.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"Exception\"`.\n */\n constructor(e, n, s = \"Exception\") {\n super(e);\n a(this, N, \"Exception\");\n this.cause = n, this.name = s, n && (n instanceof Error ? this.stack += `\n\nCaused by ${n.stack}` : this.stack += `\n\nCaused by ${n}`);\n }\n /**\n * A static method to convert a generic caught error, ensuring it's an instance of the {@link Exception} class.\n *\n * ```ts\n * try { [...] }\n * catch (error)\n * {\n * const exc = Exception.FromUnknown(error);\n *\n * [...]\n * }\n * ```\n *\n * @param error The caught error to convert.\n *\n * @returns An instance of the {@link Exception} class.\n */\n static FromUnknown(e) {\n if (e instanceof c)\n return e;\n if (e instanceof Error) {\n const n = new c(e.message);\n return n.stack = e.stack, n.name = e.name, n;\n }\n return new c(`${e}`);\n }\n}\nvar $, q;\nclass x extends (q = c, $ = Symbol.toStringTag, q) {\n /**\n * Initializes a new instance of the {@link FatalErrorException} class.\n *\n * ```ts\n * throw new FatalErrorException(\"This error should never happen. Please, contact the support team.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"FatalErrorException\"`.\n */\n constructor(e, n, s = \"FatalErrorException\") {\n e === void 0 && (e = \"The program has encountered an unrecoverable error and cannot continue as expected. Please, try again later. If the problem persists, contact the support team.\");\n super(e, n, s);\n a(this, $, \"FatalErrorException\");\n }\n}\nvar z, D;\nclass Be extends (D = x, z = Symbol.toStringTag, D) {\n /**\n * Initializes a new instance of the {@link NotImplementedException} class.\n *\n * ```ts\n * throw new NotImplementedException(\"This method hasn't been implemented yet. Check back later.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"NotImplementedException\"`.\n */\n constructor(e, n, s = \"NotImplementedException\") {\n e === void 0 && (e = \"This feature isn't implemented yet. Please, try again later.\");\n super(e, n, s);\n a(this, z, \"NotImplementedException\");\n }\n}\nvar B, J;\nclass $e extends (J = c, B = Symbol.toStringTag, J) {\n /**\n * Initializes a new instance of the {@link FileException} class.\n *\n * ```ts\n * throw new FileException(\"An error occurred while trying to read the file.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"FileException\"`.\n */\n constructor(e, n, s = \"FileException\") {\n super(e, n, s);\n a(this, B, \"FileException\");\n }\n}\nvar Y, L;\nclass Ue extends (L = $e, Y = Symbol.toStringTag, L) {\n /**\n * Initializes a new instance of the {@link FileExistsException} class.\n *\n * ```ts\n * throw new FileExistsException(\"The file named 'data.json' already exists on the server.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"FileExistsException\"`.\n */\n constructor(e, n, s = \"FileExistsException\") {\n super(e, n, s);\n a(this, Y, \"FileExistsException\");\n }\n}\nvar G, K;\nclass et extends (K = $e, G = Symbol.toStringTag, K) {\n /**\n * Initializes a new instance of the {@link FileNotFoundException} class.\n *\n * ```ts\n * throw new FileNotFoundException(\"The file named 'data.json' wasn't found on the server.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"FileNotFoundException\"`.\n */\n constructor(e, n, s = \"FileNotFoundException\") {\n super(e, n, s);\n a(this, G, \"FileNotFoundException\");\n }\n}\nvar H, Q;\nclass b extends (Q = c, H = Symbol.toStringTag, Q) {\n /**\n * Initializes a new instance of the {@link KeyException} class.\n *\n * ```ts\n * throw new KeyException(\"The 'id' key wasn't found in the dictionary.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"KeyException\"`.\n */\n constructor(e, n, s = \"KeyException\") {\n super(e, n, s);\n a(this, H, \"KeyException\");\n }\n}\nvar V, X;\nclass tt extends (X = c, V = Symbol.toStringTag, X) {\n /**\n * Initializes a new instance of the {@link NetworkException} class.\n *\n * ```ts\n * throw new NetworkException(\"Couldn't connect to the server. Please, try again later.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"NetworkException\"`.\n */\n constructor(e, n, s = \"NetworkException\") {\n super(e, n, s);\n a(this, V, \"NetworkException\");\n }\n}\nvar Z, W;\nclass nt extends (W = c, Z = Symbol.toStringTag, W) {\n /**\n * Initializes a new instance of the {@link PermissionException} class.\n *\n * ```ts\n * throw new PermissionException(\"You don't have permission to access this resource.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"PermissionException\"`.\n */\n constructor(e, n, s = \"PermissionException\") {\n super(e, n, s);\n a(this, Z, \"PermissionException\");\n }\n}\nvar U, ee;\nclass C extends (ee = c, U = Symbol.toStringTag, ee) {\n /**\n * Initializes a new instance of the {@link ReferenceException} class.\n *\n * ```ts\n * throw new ReferenceException(\"The 'canvas' element wasn't found in the document.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"ReferenceException\"`.\n */\n constructor(e, n, s = \"ReferenceException\") {\n super(e, n, s);\n a(this, U, \"ReferenceException\");\n }\n}\nvar te, ne;\nclass y extends (ne = c, te = Symbol.toStringTag, ne) {\n /**\n * Initializes a new instance of the {@link RuntimeException} class.\n *\n * ```ts\n * throw new RuntimeException(\"The received input seems to be malformed or corrupted.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"RuntimeException\"`.\n */\n constructor(e, n, s = \"RuntimeException\") {\n super(e, n, s);\n a(this, te, \"RuntimeException\");\n }\n}\nvar se, re;\nclass Je extends (re = y, se = Symbol.toStringTag, re) {\n /**\n * Initializes a new instance of the {@link EnvironmentException} class.\n *\n * ```ts\n * throw new EnvironmentException(\"The required environment variable 'API_KEY' isn't set.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"EnvironmentException\"`.\n */\n constructor(e, n, s = \"EnvironmentException\") {\n super(e, n, s);\n a(this, se, \"EnvironmentException\");\n }\n}\nvar ie, oe;\nclass Ye extends (oe = c, ie = Symbol.toStringTag, oe) {\n /**\n * Initializes a new instance of the {@link TimeoutException} class.\n *\n * ```ts\n * throw new TimeoutException(\"The task took too long to complete.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"TimeoutException\"`.\n */\n constructor(e, n, s = \"TimeoutException\") {\n super(e, n, s);\n a(this, ie, \"TimeoutException\");\n }\n}\nvar ae, le;\nclass st extends (le = c, ae = Symbol.toStringTag, le) {\n /**\n * Initializes a new instance of the {@link TypeException} class.\n *\n * ```ts\n * throw new TypeException(\"The 'username' argument must be a valid string.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"TypeException\"`.\n */\n constructor(e, n, s = \"TypeException\") {\n super(e, n, s);\n a(this, ae, \"TypeException\");\n }\n}\nvar ue, ce;\nclass d extends (ce = c, ue = Symbol.toStringTag, ce) {\n /**\n * Initializes a new instance of the {@link ValueException} class.\n *\n * ```ts\n * throw new ValueException(\"The 'grade' argument cannot be negative.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"ValueException\"`.\n */\n constructor(e, n, s = \"ValueException\") {\n super(e, n, s);\n a(this, ue, \"ValueException\");\n }\n}\nvar he, fe;\nclass p extends (fe = d, he = Symbol.toStringTag, fe) {\n /**\n * Initializes a new instance of the {@link RangeException} class.\n *\n * ```ts\n * throw new RangeException(\"The 'percentage' argument must be between 0 and 100.\");\n * ```\n *\n * @param message The message that describes the error.\n * @param cause The previous caught error that caused this one, if any.\n * @param name The name of the exception. Default is `\"RangeException\"`.\n */\n constructor(e, n, s = \"RangeException\") {\n super(e, n, s);\n a(this, he, \"RangeException\");\n }\n}\nvar de;\nclass u {\n constructor(t) {\n /**\n * The native {@link Iterator} object that is being wrapped by this instance.\n */\n a(this, \"_iterator\");\n a(this, de, \"SmartIterator\");\n t instanceof Function ? this._iterator = t() : Symbol.iterator in t ? this._iterator = t[Symbol.iterator]() : this._iterator = t;\n }\n /**\n * Determines whether all elements of the iterator satisfy a given condition.\n * See also {@link SmartIterator.some}.\n *\n * This method will iterate over all elements of the iterator checking if they satisfy the condition. \n * Once a single element doesn't satisfy the condition, the method will return `false` immediately.\n *\n * This may lead to an unknown final state of the iterator, which may be entirely or partially consumed. \n * For this reason, it's recommended to consider it as consumed in any case and to not use it anymore. \n * Consider using {@link SmartIterator.find} instead.\n *\n * If the iterator is infinite and every element satisfies the condition, the method will never return.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);\n * const result = iterator.every((value) => value < 0);\n *\n * console.log(result); // false\n * ```\n *\n * @param predicate The condition to check for each element of the iterator.\n *\n * @returns `true` if all elements satisfy the condition, `false` otherwise.\n */\n every(t) {\n let e = 0;\n for (; ; ) {\n const n = this._iterator.next();\n if (n.done)\n return !0;\n if (!t(n.value, e))\n return !1;\n e += 1;\n }\n }\n /**\n * Determines whether any element of the iterator satisfies a given condition.\n * See also {@link SmartIterator.every}.\n *\n * This method will iterate over all elements of the iterator checking if they satisfy the condition. \n * Once a single element satisfies the condition, the method will return `true` immediately.\n *\n * This may lead to an unknown final state of the iterator, which may be entirely or partially consumed. \n * For this reason, it's recommended to consider it as consumed in any case and to not use it anymore. \n * Consider using {@link SmartIterator.find} instead.\n *\n * If the iterator is infinite and no element satisfies the condition, the method will never return.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);\n * const result = iterator.some((value) => value < 0);\n *\n * console.log(result); // true\n * ```\n *\n * @param predicate The condition to check for each element of the iterator.\n *\n * @returns `true` if any element satisfies the condition, `false` otherwise.\n */\n some(t) {\n let e = 0;\n for (; ; ) {\n const n = this._iterator.next();\n if (n.done)\n return !1;\n if (t(n.value, e))\n return !0;\n e += 1;\n }\n }\n filter(t) {\n const e = this._iterator;\n return new u(function* () {\n let n = 0;\n for (; ; ) {\n const s = e.next();\n if (s.done)\n return s.value;\n t(s.value, n) && (yield s.value), n += 1;\n }\n });\n }\n /**\n * Maps the elements of the iterator using a given transformation function.\n *\n * This method will iterate over all elements of the iterator applying the transformation function. \n * The result of each transformation will be included in the new iterator.\n *\n * Since the iterator is lazy, the mapping process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);\n * const result = iterator.map((value) => Math.abs(value));\n *\n * console.log(result.toArray()); // [2, 1, 0, 1, 2]\n * ```\n *\n * @template V The type of the elements after the transformation.\n *\n * @param iteratee The transformation function to apply to each element of the iterator.\n *\n * @returns A new {@link SmartIterator} containing the transformed elements.\n */\n map(t) {\n const e = this._iterator;\n return new u(function* () {\n let n = 0;\n for (; ; ) {\n const s = e.next();\n if (s.done)\n return s.value;\n yield t(s.value, n), n += 1;\n }\n });\n }\n reduce(t, e) {\n let n = 0, s = e;\n if (s === void 0) {\n const r = this._iterator.next();\n if (r.done)\n throw new d(\"Cannot reduce an empty iterator without an initial value.\");\n s = r.value, n += 1;\n }\n for (; ; ) {\n const r = this._iterator.next();\n if (r.done)\n return s;\n s = t(s, r.value, n), n += 1;\n }\n }\n /**\n * Flattens the elements of the iterator using a given transformation function.\n *\n * This method will iterate over all elements of the iterator applying the transformation function. \n * The result of each transformation will be flattened into the new iterator.\n *\n * Since the iterator is lazy, the flattening process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const iterator = new SmartIterator<number[]>([[-2, -1], 0, 1, 2, [3, 4, 5]]);\n * const result = iterator.flatMap((value) => value);\n *\n * console.log(result.toArray()); // [-2, -1, 0, 1, 2, 3, 4, 5]\n * ```\n *\n * @template V The type of the elements after the transformation.\n *\n * @param iteratee The transformation function to apply to each element of the iterator.\n *\n * @returns A new {@link SmartIterator} containing the flattened elements.\n */\n flatMap(t) {\n const e = this._iterator;\n return new u(function* () {\n let n = 0;\n for (; ; ) {\n const s = e.next();\n if (s.done)\n return s.value;\n const r = t(s.value, n);\n if (r instanceof Array)\n for (const o of r)\n yield o;\n else\n yield r;\n n += 1;\n }\n });\n }\n /**\n * Drops a given number of elements at the beginning of the iterator. \n * The remaining elements will be included in a new iterator.\n * See also {@link SmartIterator.take}.\n *\n * Since the iterator is lazy, the dropping process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * Only the dropped elements will be consumed in the process. \n * The rest of the iterator will be consumed only once the new one is.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);\n * const result = iterator.drop(3);\n *\n * console.log(result.toArray()); // [1, 2]\n * ```\n *\n * @param count The number of elements to drop.\n *\n * @returns A new {@link SmartIterator} containing the remaining elements.\n */\n drop(t) {\n const e = this._iterator;\n return new u(function* () {\n let n = 0;\n for (; n < t; ) {\n if (e.next().done)\n return;\n n += 1;\n }\n for (; ; ) {\n const s = e.next();\n if (s.done)\n return s.value;\n yield s.value;\n }\n });\n }\n /**\n * Takes a given number of elements at the beginning of the iterator. \n * These elements will be included in a new iterator.\n * See also {@link SmartIterator.drop}.\n *\n * Since the iterator is lazy, the taking process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * Only the taken elements will be consumed from the original iterator. \n * The rest of the original iterator will be available for further consumption.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([-2, -1, 0, 1, 2]);\n * const result = iterator.take(3);\n *\n * console.log(result.toArray()); // [-2, -1, 0]\n * console.log(iterator.toArray()); // [1, 2]\n * ```\n *\n * @param limit The number of elements to take.\n *\n * @returns A new {@link SmartIterator} containing the taken elements.\n */\n take(t) {\n const e = this._iterator;\n return new u(function* () {\n let n = 0;\n for (; n < t; ) {\n const s = e.next();\n if (s.done)\n return s.value;\n yield s.value, n += 1;\n }\n });\n }\n find(t) {\n let e = 0;\n for (; ; ) {\n const n = this._iterator.next();\n if (n.done)\n return;\n if (t(n.value, e))\n return n.value;\n e += 1;\n }\n }\n /**\n * Enumerates the elements of the iterator. \n * Each element is be paired with its index in a new iterator.\n *\n * Since the iterator is lazy, the enumeration process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const iterator = new SmartIterator<string>([\"A\", \"M\", \"N\", \"Z\"]);\n * const result = iterator.enumerate();\n *\n * console.log(result.toArray()); // [[0, \"A\"], [1, \"M\"], [2, \"N\"], [3, \"Z\"]]\n * ```\n *\n * @returns A new {@link SmartIterator} containing the enumerated elements.\n */\n enumerate() {\n return this.map((t, e) => [e, t]);\n }\n /**\n * Removes all duplicate elements from the iterator. \n * The first occurrence of each element will be kept.\n *\n * Since the iterator is lazy, the deduplication process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([1, 1, 2, 3, 2, 3, 4, 5, 5, 4]);\n * const result = iterator.unique();\n *\n * console.log(result.toArray()); // [1, 2, 3, 4, 5]\n * ```\n *\n * @returns A new {@link SmartIterator} containing only the unique elements.\n */\n unique() {\n const t = this._iterator;\n return new u(function* () {\n const e = /* @__PURE__ */ new Set();\n for (; ; ) {\n const n = t.next();\n if (n.done)\n return n.value;\n e.has(n.value) || (e.add(n.value), yield n.value);\n }\n });\n }\n /**\n * Counts the number of elements in the iterator. \n * This method will consume the entire iterator in the process.\n *\n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);\n * const result = iterator.count();\n *\n * console.log(result); // 5\n * ```\n *\n * @returns The number of elements in the iterator.\n */\n count() {\n let t = 0;\n for (; ; ) {\n if (this._iterator.next().done)\n return t;\n t += 1;\n }\n }\n /**\n * Iterates over all elements of the iterator. \n * The elements are passed to the function along with their index.\n *\n * This method will consume the entire iterator in the process. \n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([\"A\", \"M\", \"N\", \"Z\"]);\n * iterator.forEach((value, index) =>\n * {\n * console.log(`${index}: ${value}`); // \"0: A\", \"1: M\", \"2: N\", \"3: Z\"\n * }\n * ```\n *\n * @param iteratee The function to apply to each element of the iterator.\n */\n forEach(t) {\n let e = 0;\n for (; ; ) {\n const n = this._iterator.next();\n if (n.done)\n return;\n t(n.value, e), e += 1;\n }\n }\n /**\n * Advances the iterator to the next element and returns the result. \n * If the iterator requires it, a value must be provided to be passed to the next element.\n *\n * Once the iterator is done, the method will return an object with the `done` property set to `true`.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([1, 2, 3, 4, 5]);\n *\n * let result = iterator.next();\n * while (!result.done)\n * {\n * console.log(result.value); // 1, 2, 3, 4, 5\n *\n * result = iterator.next();\n * }\n *\n * console.log(result); // { done: true, value: undefined }\n * ```\n *\n * @param values The value to pass to the next element, if required.\n *\n * @returns The result of the iteration, containing the value of the operation.\n */\n next(...t) {\n return this._iterator.next(...t);\n }\n /**\n * An utility method that may be used to close the iterator gracefully,\n * free the resources and perform any cleanup operation. \n * It may also be used to signal the end or to compute a specific final result of the iteration process.\n *\n * ```ts\n * const iterator = new SmartIterator<number>({\n * _index: 0,\n * next: function()\n * {\n * return { done: false, value: this._index += 1 };\n * },\n * return: function() { console.log(\"Closing the iterator...\"); }\n * });\n *\n * for (const value of iterator)\n * {\n * if (value > 5) { break; } // Closing the iterator...\n *\n * console.log(value); // 1, 2, 3, 4, 5\n * }\n * ```\n *\n * @param value The final value of the iterator.\n *\n * @returns The result of the iterator.\n */\n return(t) {\n return this._iterator.return ? this._iterator.return(t) : { done: !0, value: t };\n }\n /**\n * An utility method that may be used to close the iterator due to an error,\n * free the resources and perform any cleanup operation. \n * It may also be used to signal that an error occurred during the iteration process or to handle it.\n *\n * ```ts\n * const iterator = new SmartIterator<number>({\n * _index: 0,\n * next: function()\n * {\n * return { done: this._index > 10, value: this._index += 1 };\n * },\n * throw: function(error)\n * {\n * console.warn(error.message);\n *\n * this._index = 0;\n * }\n * });\n *\n * for (const value of iterator) // 1, 2, 3, 4, 5, \"The index is too high.\", 1, 2, 3, 4, 5, ...\n * {\n * try\n * {\n * if (value > 5) { throw new Error(\"The index is too high.\"); }\n *\n * console.log(value); // 1, 2, 3, 4, 5\n * }\n * catch (error) { iterator.throw(error); }\n * }\n * ```\n *\n * @param error The error to throw into the iterator.\n *\n * @returns The final result of the iterator.\n */\n throw(t) {\n if (this._iterator.throw)\n return this._iterator.throw(t);\n throw t;\n }\n /**\n * An utility method that aggregates the elements of the iterator using a given key function. \n * The elements will be grouped by the resulting keys in a new specialized iterator.\n * See {@link AggregatedIterator}.\n *\n * Since the iterator is lazy, the grouping process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * the new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const iterator = new SmartIterator<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);\n * const result = iterator.groupBy<string>((value) => value % 2 === 0 ? \"even\" : \"odd\");\n *\n * console.log(result.toObject()); // { odd: [1, 3, 5, 7, 9], even: [2, 4, 6, 8, 10] }\n * ```\n *\n * @template K The type of the keys used to group the elements.\n *\n * @param iteratee The key function to apply to each element of the iterator.\n *\n * @returns A new instance of the {@link AggregatedIterator} class containing the grouped elements.\n */\n groupBy(t) {\n return new g(this.map((e, n) => [t(e, n), e]));\n }\n /**\n * Materializes the iterator into an array. \n * This method will consume the entire iterator in the process.\n *\n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const iterator = new SmartIterator(function* ()\n * {\n * for (let i = 0; i < 5; i += 1) { yield i; }\n * });\n * const result = iterator.toArray();\n *\n * console.log(result); // [0, 1, 2, 3, 4]\n * ```\n *\n * @returns The {@link Array} containing all elements of the iterator.\n */\n toArray() {\n return Array.from(this);\n }\n [(de = Symbol.toStringTag, Symbol.iterator)]() {\n return this;\n }\n}\nvar me;\nme = Symbol.toStringTag;\nconst _ = class _ {\n constructor(t) {\n /**\n * The internal {@link SmartIterator} object that holds the reduced elements.\n */\n a(this, \"_elements\");\n a(this, me, \"ReducedIterator\");\n this._elements = new u(t);\n }\n /**\n * Determines whether all elements of the reduced iterator satisfy the given condition.\n * See also {@link ReducedIterator.some}.\n *\n * This method will iterate over all the elements of the iterator checking if they satisfy the condition. \n * Once a single element doesn't satisfy the condition, the method will return `false` immediately.\n *\n * This may lead to an unknown final state of the iterator, which may be entirely or partially consumed. \n * For this reason, it's recommended to consider it as consumed in any case and to not use it anymore. \n * Consider using {@link ReducedIterator.find} instead.\n *\n * If the iterator is infinite and every element satisfies the condition, the method will never return.\n *\n * ```ts\n * const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .every((key, value) => value > 0);\n *\n * console.log(results); // true\n * ```\n *\n * @param predicate The condition to check for each element of the iterator.\n *\n * @returns `true` if all elements satisfy the condition, `false` otherwise.\n */\n every(t) {\n for (const [e, [n, s]] of this._elements.enumerate())\n if (!t(n, s, e))\n return !1;\n return !0;\n }\n /**\n * Determines whether any element of the reduced iterator satisfies the given condition.\n * See also {@link ReducedIterator.every}.\n *\n * This method will iterate over all the elements of the iterator checking if they satisfy the condition. \n * Once a single element satisfies the condition, the method will return `true` immediately.\n *\n * This may lead to an unknown final state of the iterator, which may be entirely or partially consumed. \n * For this reason, it's recommended to consider it as consumed in any case and to not use it anymore. \n * Consider using {@link ReducedIterator.find} instead.\n *\n * If the iterator is infinite and no element satisfies the condition, the method will never return.\n *\n * ```ts\n * const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .some((key, value) => value > 0);\n *\n * console.log(results); // true\n * ```\n *\n * @param predicate The condition to check for each element of the iterator.\n *\n * @returns `true` if any element satisfies the condition, `false` otherwise.\n */\n some(t) {\n for (const [e, [n, s]] of this._elements.enumerate())\n if (t(n, s, e))\n return !0;\n return !1;\n }\n filter(t) {\n const e = this._elements.enumerate();\n return new _(function* () {\n for (const [n, [s, r]] of e)\n t(s, r, n) && (yield [s, r]);\n });\n }\n /**\n * Maps the elements of the reduced iterator using a given transformation function.\n *\n * This method will iterate over all the elements of the iterator applying the transformation function. \n * The result of the transformation will be included in the new iterator.\n *\n * Since the iterator is lazy, the mapping process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .map((key, value) => value * 2);\n *\n * console.log(results.toObject()); // { odd: 8, even: 32 }\n * ```\n *\n * @template V The type of the elements after the transformation.\n *\n * @param iteratee The transformation function to apply to each element of the iterator.\n *\n * @returns A new {@link ReducedIterator} containing the transformed elements.\n */\n map(t) {\n const e = this._elements.enumerate();\n return new _(function* () {\n for (const [n, [s, r]] of e)\n yield [s, t(s, r, n)];\n });\n }\n reduce(t, e) {\n let n = 0, s = e;\n if (s === void 0) {\n const r = this._elements.next();\n if (r.done)\n throw new d(\"Cannot reduce an empty iterator without an initial value.\");\n s = r.value[1], n += 1;\n }\n for (const [r, o] of this._elements)\n s = t(r, s, o, n), n += 1;\n return s;\n }\n /**\n * Flattens the elements of the reduced iterator using a given transformation function.\n *\n * This method will iterate over all the elements of the iterator applying the transformation function. \n * The result of each transformation will be flattened into the new iterator.\n *\n * Since the iterator is lazy, the flattening process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator.concat([value]), () => [])\n * .flatMap((key, value) => value);\n *\n * console.log(results.toObject()); // { odd: [-3, -1, 3, 5], even: [0, 2, 6, 8] }\n * ```\n *\n * @template V The type of the elements after the transformation.\n *\n * @param iteratee The transformation function to apply to each element of the iterator.\n *\n * @returns A new {@link AggregatedIterator} containing the flattened elements.\n */\n flatMap(t) {\n const e = this._elements.enumerate();\n return new g(function* () {\n for (const [n, [s, r]] of e) {\n const o = t(s, r, n);\n if (o instanceof Array)\n for (const l of o)\n yield [s, l];\n else\n yield [s, o];\n }\n });\n }\n /**\n * Drops a given number of elements at the beginning of the reduced iterator. \n * The remaining elements will be included in the new iterator.\n * See also {@link ReducedIterator.take}.\n *\n * Since the iterator is lazy, the dropping process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * Only the dropped elements will be consumed in the process. \n * The rest of the iterator will be consumed once the new iterator is.\n *\n * ```ts\n * const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator.concat(value), () => [])\n * .drop(1);\n *\n * console.log(results.toObject()); // { even: [0, 2, 6, 8] }\n * ```\n * \n * @param count The number of elements to drop.\n *\n * @returns A new {@link ReducedIterator} containing the remaining elements.\n */\n drop(t) {\n const e = this._elements.enumerate();\n return new _(function* () {\n for (const [n, [s, r]] of e)\n n >= t && (yield [s, r]);\n });\n }\n /**\n * Takes a given number of elements at the beginning of the reduced iterator. \n * The elements will be included in the new iterator.\n * See also {@link ReducedIterator.drop}.\n *\n * Since the iterator is lazy, the taking process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * Only the taken elements will be consumed from the original reduced iterator. \n * The rest of the original reduced iterator will be available for further consumption.\n *\n * ```ts\n * const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator.concat(value), () => []);\n *\n * const results = iterator.take(1);\n *\n * console.log(results.toObject()); // { odd: [-3, -1, 3, 5] }\n * console.log(reduced.toObject()); // { even: [0, 2, 6, 8] }\n * ```\n *\n * @param count The number of elements to take.\n *\n * @returns A new {@link ReducedIterator} containing the taken elements.\n */\n take(t) {\n const e = this._elements.enumerate();\n return new _(function* () {\n for (const [n, [s, r]] of e) {\n if (n >= t)\n break;\n yield [s, r];\n }\n });\n }\n find(t) {\n for (const [e, [n, s]] of this._elements.enumerate())\n if (t(n, s, e))\n return s;\n }\n /**\n * Enumerates the elements of the reduced iterator. \n * Each element is paired with its index in a new iterator.\n *\n * Since the iterator is lazy, the enumeration process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const results = new ReducedIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .enumerate();\n *\n * console.log(results.toObject()); // [[0, 4], [1, 16]]\n * ```\n *\n * @returns A new {@link ReducedIterator} object containing the enumerated elements.\n */\n enumerate() {\n return this.map((t, e, n) => [n, e]);\n }\n /**\n * Removes all duplicate elements from the reduced iterator. \n * The first occurrence of each element will be kept.\n *\n * Since the iterator is lazy, the deduplication process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const results = new ReducedIterator<number>([-3, -1, 0, 2, 3, 6, -3, -1, 1, 5, 6, 8, 7, 2])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .map((key, value) => Math.abs(value))\n * .reduce((key, accumulator, value) => accumulator + value)\n * .unique();\n *\n * console.log(results.toObject()); // { odd: 24 }\n *\n * @returns A new {@link ReducedIterator} containing only the unique elements.\n */\n unique() {\n const t = this._elements;\n return new _(function* () {\n const e = /* @__PURE__ */ new Set();\n for (const [n, s] of t)\n e.has(s) || (e.add(s), yield [n, s]);\n });\n }\n /**\n * Counts the number of elements in the reduced iterator. \n * This method will consume the entire iterator in the process.\n *\n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .count();\n *\n * console.log(results); // 2\n * ```\n *\n * @returns The number of elements in the iterator.\n */\n count() {\n let t = 0;\n for (const e of this._elements)\n t += 1;\n return t;\n }\n /**\n * Iterates over all elements of the reduced iterator. \n * The elements are passed to the function along with their key and index.\n *\n * This method will consume the entire iterator in the process. \n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value);\n * \n * reduced.forEach((key, value, index) =>\n * {\n * console.log(`#${index} - ${key}: ${value}`); // \"#0 - odd: 4\", \"#1 - even: 16\"\n * });\n * ```\n *\n * @param iteratee The function to apply to each element of the reduced iterator.\n */\n forEach(t) {\n for (const [e, [n, s]] of this._elements.enumerate())\n t(n, s, e);\n }\n /**\n * Reaggregates the elements of the reduced iterator. \n * The elements are grouped by a new key computed by the given iteratee function.\n *\n * Since the iterator is lazy, the reorganizing process will\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const results = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, -6, -8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .reorganizeBy((key, value) => value > 0 ? \"positive\" : \"negative\");\n *\n * console.log(results.toObject()); // { positive: 4, negative: -12 }\n * ```\n *\n * @template J The type of the new keys used to group the elements.\n *\n * @param iteratee The function to determine the new key of each element of the iterator.\n *\n * @returns A new {@link AggregatedIterator} containing the elements reorganized by the new keys.\n */\n reorganizeBy(t) {\n const e = this._elements.enumerate();\n return new g(function* () {\n for (const [n, [s, r]] of e)\n yield [t(s, r, n), r];\n });\n }\n /**\n * An utility method that returns a new {@link SmartIterator}\n * object containing all the keys of the iterator.\n *\n * Since the iterator is lazy, the keys will be extracted\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const keys = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .keys();\n *\n * console.log(keys.toArray()); // [\"odd\", \"even\"]\n * ```\n *\n * @returns A new {@link SmartIterator} containing all the keys of the iterator.\n */\n keys() {\n const t = this._elements;\n return new u(function* () {\n for (const [e] of t)\n yield e;\n });\n }\n /**\n * An utility method that returns a new {@link SmartIterator}\n * object containing all the entries of the iterator. \n * Each entry is a tuple containing the key and the element.\n *\n * Since the iterator is lazy, the entries will be extracted\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const entries = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .entries();\n *\n * console.log(entries.toArray()); // [[\"odd\", 4], [\"even\", 16]]\n * ```\n *\n * @returns A new {@link SmartIterator} containing all the entries of the iterator.\n */\n entries() {\n return this._elements;\n }\n /**\n * An utility method that returns a new {@link SmartIterator}\n * object containing all the values of the iterator.\n *\n * Since the iterator is lazy, the values will be extracted\n * be executed once the resulting iterator is materialized.\n *\n * A new iterator will be created, holding the reference to the original one. \n * This means that the original iterator won't be consumed until the\n * new one is and that consuming one of them will consume the other as well.\n *\n * ```ts\n * const values = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value)\n * .values();\n *\n * console.log(values.toArray()); // [4, 16]\n * ```\n *\n * @returns A new {@link SmartIterator} containing all the values of the iterator.\n */\n values() {\n const t = this._elements;\n return new u(function* () {\n for (const [e, n] of t)\n yield n;\n });\n }\n /**\n * Materializes the iterator into an array. \n * This method will consume the entire iterator in the process.\n *\n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value);\n *\n * console.log(reduced.toArray()); // [4, 16]\n * ```\n *\n * @returns The {@link Array} containing all elements of the iterator.\n */\n toArray() {\n return Array.from(this.values());\n }\n /**\n * Materializes the iterator into a map. \n * This method will consume the entire iterator in the process.\n *\n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value);\n *\n * console.log(reduced.toMap()); // Map(2) { \"odd\" => 4, \"even\" => 16 }\n * ```\n *\n * @returns The {@link Map} containing all elements of the iterator.\n */\n toMap() {\n return new Map(this.entries());\n }\n /**\n * Materializes the iterator into an object. \n * This method will consume the entire iterator in the process.\n *\n * If the iterator is infinite, the method will never return.\n *\n * ```ts\n * const reduced = new SmartIterator<number>([-3, -1, 0, 2, 3, 5, 6, 8])\n * .groupBy((value) => value % 2 === 0 ? \"even\" : \"odd\")\n * .reduce((key, accumulator, value) => accumulator + value);\n *\n * console.log(reduced.toObject()); // { odd: 4, even: 16 }\n * ```\n *\n * @returns The {@link Object} containing all elements of the iterator.\n */\n toObject() {\n return Object.fromEntries(this.entries());\n }\n};\nlet h = _;\nvar we;\nwe = Symbol.toStringTag;\nconst m = class m {\n constructor(t) {\n /**\n * The internal {@link SmartAsyncIterator} object that holds the elements to aggregate.\n */\n a(this, \"_elements\");\n a(this, we, \"AggregatedAsyncIterator\");\n this._elements = new f(t);\n }\n /**\n * Determines whether all elements of each group of the iterator satisfy a given condition.\n * See also {@link AggregatedAsyncIterator.some}. \n * This method will consume the entire iterator in the process.\n *\n * It will iterate over all elements of the it