@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
34 lines • 981 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.throwIf = throwIf;
const operators_1 = require("rxjs/operators");
// from https://github.com/NiklasPor/rxjs-boost (MIT)
/**
* Throws the error built by `errorFn` if `conditionFn` evaluates to be truthy.
*
* @param conditionFn Determines if an error should be thrown.
* @param errorFn Evaluates to the error which can be thrown.
*
* @example
* ```
* const input = cold(' ft', { f: false, t: true });
* const expected = cold('f#', { f: false }, 'error');
*
* const result = input.pipe(
* // will throw 'error' for values === true
* throwIf(
* (val) => val
* () => error
* )
* );
* ```
*/
function throwIf(conditionFn, errorFn) {
return (input) => input.pipe((0, operators_1.map)((value, index) => {
if (conditionFn(value, index)) {
throw errorFn(value, index);
}
return value;
}));
}
//# sourceMappingURL=throwIf.js.map