@rxjs-ninja/rxjs-array
Version:
Operators for RxJS for filtering with boolean logic
44 lines (43 loc) • 1.7 kB
TypeScript
/**
* @packageDocumentation
* @module Array
*/
import { OperatorFunction, Subscribable } from 'rxjs';
/**
* Returns an Observable Number if the input is a single value, or Array of numbers in the input is an Array.
* These are the index numbers of first truthy value in the source array using Array.indexOf
*
* @category Query
*
* @typeParam T Item type contained in the Array or Set
*
* @param input A value or array of values to get the index of in the source array
* @param startIndex Optional index to start searching from in the array, starts from `0`
*
* @example
* Returns the first index of the word `RxJS` in the array
* ```ts
* const input = [ ['RxJS', 'Ninja' ], ['Learn', 'RxJS'], ['Foo', 'Bar'] ];
* from(input).pipe(indexOf('RxJS')).subscribe();
* ```
* Output: `0, 1, -1`
*
* @example
* Returns an array of the first index of the words `RxJS` and `Ninja` in the array
* ```ts
* const input = [ ['RxJS', 'Ninja' ], ['Learn', 'RxJS'], ['Foo', 'Bar'] ];
* of(input).pipe(indexOf(['RxJS', 'Ninja'])).subscribe()
* ```
* Output: `[0, 1], [1, -1], [-1, -1]`
*
* @example
* Returns the first index of the word `RxJS` in the array starting from index `1`
* ```ts
* const input = [ ['RxJS', 'Ninja' ], ['Learn', 'RxJS'], ['Foo', 'Bar'] ];
* of(input).pipe(indexOf('RxJS', 1)).subscribe()
* ```
* Output: `-1, 1, -1`
*
* @returns Observable number or array of numbers containing the index of the first found value
*/
export declare function indexOf<T extends unknown>(input: Subscribable<Iterable<T> | T> | Iterable<T> | T, startIndex?: Subscribable<number> | number): OperatorFunction<Iterable<T>, number[]>;