io-ts-extra
Version:
Adds pattern matching, optional properties, and several other helpers and types, to io-ts.
27 lines • 909 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.funcLabel = exports.RichError = void 0;
const secret = Symbol('secret');
class RichError extends Error {
constructor(details) {
super(JSON.stringify(details, null, 2));
this.details = details;
}
static thrower(context) {
return (info) => RichError.throw({ context, details: info });
}
static throw(details) {
const resolvedDetails = details || { details: 'none!' };
throw Object.assign(new RichError(resolvedDetails), { details: resolvedDetails });
}
}
exports.RichError = RichError;
const funcLabel = (func) => func.name ||
func
.toString()
.split('\n')
.filter((_, i, arr) => i === 0 || i === arr.length - 1)
.map(line => line.trim())
.join(' ... ');
exports.funcLabel = funcLabel;
//# sourceMappingURL=util.js.map