array-to-error

Create an error from an array of error messages

MIT 4 个版本
安装
npm install array-to-error
yarn add array-to-error
pnpm add array-to-error
bun add array-to-error
README

array-to-error

NPM version Build Status Coverage Status Dependency Status devDependency Status

Create an error from an array of error messages

const arrayToError = require('array-to-error');

const error = arrayToError(['tranling comma on line 1', 'unexpected "(" on line 2']);
error.message; //=> 'tranling comma on line 1\nunexpected "(" on line 2'
error.reasons; //=> ['tranling comma on line 1', 'unexpected "(" on line 2']

Installation

npm

npm install array-to-error

Bower

bower install array-to-error

API

const arrayToError = require('array-to-error');

arrayToError(messages [, constructor])

messages: Array of strings
constructor: Object (One of the error constructors. Error by default)
Return: Object (error instance)

It returns an instance of error whose message is made from its first argument joined with \n, and has an additional reasons property, the same value as its first argument.

The second argument is used as an error constructor.

const arrayToError = require('array-to-error');

const error = arrayToError(['foo', 'bar'], TypeError);
error.message; //=> 'foo\nbar'
error.reasons; //=> ['foo', 'bar']
error.constructor; //=> TypeError

License

Copyright (c) 2015 - 2016 Shinnosuke Watanabe

Licensed under the MIT License.

版本列表
1.1.1 2016-06-21
1.1.0 2016-06-08
1.0.0 2015-10-06
0.0.2 2015-10-06