Operators for RxJS for filtering with boolean logic
npm install @rxjs-ninja/rxjs-boolean
Website
|
API Documentation
|
Changelog
@rxjs-ninja/rxjs-boolean provides operators for querying, filtering and modifying boolean values, and Observable for
generating boolean emitters.
Functions and Operators for creating Observable boolean values
``ts
const numbers = [0, 1, 0, 0, 1, 0, 1];
const strings = ['RxJS', '', '', 'Ninja', 'TypeScript'];
// Generate a boolean array from numbers
fromBoolean(numbers).subscribe();
// Output: false, true, false, false, true, false, true
// Generate a boolean array from numbers
fromBoolean(strings).subscribe();
// Output: true, false, false, true, true`
Operators for filtering Observable sources for truthy values
`ts
const strings$ = from(['RxJS', '', '', 'Ninja', 'TypeScript', '', 'Angular']);
// Get the first truthy value
strings$.pipe(firstTruthy()).subscribe();
// Output: RxJS
// Get the first truthy value that is over length of 6
strings$.pipe(firstTruthy((v) => v.length > 5)).subscribe();
// Output: TypeScript
// Get the last truthy value
strings$.pipe(lastTruthy()).subscribe();
// Output: Angular
// Get the last truthy value of less than 5 characters
strings$.pipe(lastTruthy((v) => v.length < 5)).subscribe();
// Output: RxJS`
Operators for modifying boolean values
`ts
const source$ = from([false, true, true, false]);
// Flip the boolean value
source$.pipe(flip()).subscribe();
// Output: true, false, false, true`
Operators that provide boolean output based on checks against source values
`ts[true, true, false]
const input = ['4485275742308327', '1111222233334444', '111133332224444'];
from(input).pipe(luhnCheck()).subscribe();
// Output: ``