UNPKG

nani

Version:

Better error handling for Node

29 lines 985 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.filterByPredicate = exports.findByPredicate = exports.normalizePredicate = void 0; const is_1 = require("./is"); const iterate_external_1 = require("./iterate-external"); function normalizePredicate(predicate) { if ((0, is_1.is)(predicate, Error)) return cause => (0, is_1.is)(cause, predicate); return predicate; } exports.normalizePredicate = normalizePredicate; function findByPredicate(err, predicate) { for (const e of (0, iterate_external_1.iterate)(err)) { if (predicate(e)) return e; } return null; } exports.findByPredicate = findByPredicate; function filterByPredicate(err, predicate) { const results = []; for (const e of (0, iterate_external_1.iterate)(err)) { if (predicate(e)) results.push(e); } return results; } exports.filterByPredicate = filterByPredicate; //# sourceMappingURL=find-internal.js.map