aggregate-error
Advanced tools
Comparing version 3.1.0 to 4.0.0
/** | ||
Create an error from multiple errors. | ||
*/ | ||
declare class AggregateError<T extends Error = Error> extends Error implements Iterable<T> { | ||
export default class AggregateError<T extends Error = Error> extends Error { | ||
readonly name: 'AggregateError'; | ||
readonly errors: readonly [T]; | ||
/** | ||
@param errors - If a string, a new `Error` is created with the string as the error message. If a non-Error object, a new `Error` is created with all properties from the object copied over. | ||
@returns An Error that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors. | ||
@example | ||
``` | ||
import AggregateError = require('aggregate-error'); | ||
import AggregateError from 'aggregate-error'; | ||
@@ -37,4 +38,3 @@ const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]); | ||
for (const individualError of error) { | ||
for (const individualError of error.errors) { | ||
console.log(individualError); | ||
@@ -47,7 +47,3 @@ } | ||
*/ | ||
constructor(errors: ReadonlyArray<T | {[key: string]: any} | string>); | ||
[Symbol.iterator](): IterableIterator<T>; | ||
constructor(errors: ReadonlyArray<T | Record<string, any> | string>); | ||
} | ||
export = AggregateError; |
25
index.js
@@ -1,8 +0,11 @@ | ||
'use strict'; | ||
const indentString = require('indent-string'); | ||
const cleanStack = require('clean-stack'); | ||
import indentString from 'indent-string'; | ||
import cleanStack from 'clean-stack'; | ||
const cleanInternalStack = stack => stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, ''); | ||
class AggregateError extends Error { | ||
export default class AggregateError extends Error { | ||
#errors; | ||
name = 'AggregateError'; | ||
constructor(errors) { | ||
@@ -13,3 +16,3 @@ if (!Array.isArray(errors)) { | ||
errors = [...errors].map(error => { | ||
errors = errors.map(error => { | ||
if (error instanceof Error) { | ||
@@ -36,14 +39,8 @@ return error; | ||
this.name = 'AggregateError'; | ||
Object.defineProperty(this, '_errors', {value: errors}); | ||
this.#errors = errors; | ||
} | ||
* [Symbol.iterator]() { | ||
for (const error of this._errors) { | ||
yield error; | ||
} | ||
get errors() { | ||
return this.#errors.slice(); | ||
} | ||
} | ||
module.exports = AggregateError; |
{ | ||
"name": "aggregate-error", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Create an error from multiple errors", | ||
"license": "MIT", | ||
"repository": "sindresorhus/aggregate-error", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
"//test": "xo && ava && tsd", | ||
"test": "ava && tsd" | ||
}, | ||
@@ -33,10 +37,10 @@ "files": [ | ||
"dependencies": { | ||
"clean-stack": "^2.0.0", | ||
"indent-string": "^4.0.0" | ||
"clean-stack": "^4.0.0", | ||
"indent-string": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tsd": "^0.7.1", | ||
"xo": "^0.25.3" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -1,5 +0,6 @@ | ||
# aggregate-error [![Build Status](https://travis-ci.org/sindresorhus/aggregate-error.svg?branch=master)](https://travis-ci.org/sindresorhus/aggregate-error) | ||
# aggregate-error | ||
> Create an error from multiple errors | ||
*Note: With [Node.js 15](https://medium.com/@nodejs/node-js-v15-0-0-is-here-deb00750f278), there's now a built-in [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) type.* | ||
@@ -12,7 +13,6 @@ ## Install | ||
## Usage | ||
```js | ||
const AggregateError = require('aggregate-error'); | ||
import AggregateError from 'aggregate-error'; | ||
@@ -42,3 +42,3 @@ const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]); | ||
for (const individualError of error) { | ||
for (const individualError of error.errors) { | ||
console.log(individualError); | ||
@@ -51,3 +51,2 @@ } | ||
## API | ||
@@ -57,9 +56,9 @@ | ||
Returns an `Error` that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors. | ||
Returns an `Error`. | ||
#### errors | ||
Type: `Array<Error|Object|string>` | ||
Type: `Array<Error|object|string>` | ||
If a string, a new `Error` is created with the string as the error message.<br> | ||
If a string, a new `Error` is created with the string as the error message.\ | ||
If a non-Error object, a new `Error` is created with all properties from the object copied over. |
Sorry, the diff of this file is not supported yet
Yes
6437
74
61
+ Addedclean-stack@4.2.0(transitive)
+ Addedescape-string-regexp@5.0.0(transitive)
+ Addedindent-string@5.0.0(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedindent-string@4.0.0(transitive)
Updatedclean-stack@^4.0.0
Updatedindent-string@^5.0.0