3.0.0 • Published 2 years ago

rxjs-throw-if v3.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
2 years ago

npm version

rxjsthrow-if
^7.0.0^3.0.0
^6.0.0^2.0.0

ThrowIf

RxJS operator which throws an error if the given predicate is met.

Example with simple error

import {throwIf} from 'rxjs-throw-if';
import {interval} from 'rxjs';

 interval(1000).pipe(
    throwIf(v => v === 5, 'Index should not exceed 4'),
).subscribe(console.log, console.error);
// Prints: 0, 1, 2, 3, 4 and then errors

Example of error based on last value

 interval(1000).pipe(
    throwIf(v => v === 5, errorValue => `Index should not exceed 4, got ${errorValue}`),
).subscribe(console.log, console.error);
// Prints: 0, 1, 2, 3, 4 and then errors with 'Index should not exceed 4, got 5'

The second argument of throwIf is optional and allows you to pass any value which will be thrown when the predicate is met. If the argument is a function, that function will be executed with the value that caused the predicate to be met and its result will be thrown.

If the predicate function throws, that error will be rethrown.

2.2.0

2 years ago

3.0.0

2 years ago

2.1.0

5 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago