UNPKG

@leismore/unknown2error

Version:

The function converts anything into an object of Error (or subclasses) class. If `error` is an object of Error (or subclasses) class, it returns the original `error` object. With any other type, it will convert it into a string first and then an Error obj

16 lines (15 loc) 423 B
"use strict"; /** * Function unknown2error - Convert anything into an Error (or subclasses of Error) object. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.unknown2error = void 0; function unknown2error(anything) { if (anything instanceof Error === true) { return anything; } else { return new Error(String(anything)); } } exports.unknown2error = unknown2error;