UNPKG

@rxjs-ninja/rxjs-utility

Version:
43 lines (42 loc) 1.73 kB
/** * @packageDocumentation * @module Utility */ import { MonoTypeOperatorFunction, Subscribable } from 'rxjs'; import { SupportedTemperatures } from '../types/temperature'; /** * Returns an Observable that emits a number based on the version of the source value through [[Temperatures]] * conversion * * @remarks This operator does not handle validation on temperature values (e.g. negative Kelvin values) * * @category Conversion * * @typeParam I String or [[Temperatures]] value for the input value * @typeParam O String or [[Temperatures]] value for the output value * * @param fromTemperature The temperature type to convert from * @param toTemperature The temperature type to convert from * @param precision The number of decimal places to return, default is `1` * * @example * Convert a source of numbers from Celsius to Fahrenheit * ```ts * const source$ = from([0, 100, 37.5, -42]); * * source$.pipe(temperature(Temperatures.CELSIUS, Temperatures.FAHRENHEIT)).subscribe() * ``` * Output: `32, 212, 99.5, -43.6` * * @example * Convert a source of numbers from Kelvin to Celsius with precision `2` * ```ts * const source$ = from([0, 100, 273.15, 10000]); * * source$.pipe(temperature('kelvin', 'celsius', 2)).subscribe() * ``` * Output: `-273,15, -173.15, 0, 9726.85` * * @returns Observable that emits a number that is the `from` [[Temperatures]] converted to the `to` [[Temperatures]] */ export declare function temperature<I extends SupportedTemperatures, O extends SupportedTemperatures>(fromTemperature: Subscribable<I> | I, toTemperature: Subscribable<O> | O, precision?: Subscribable<number> | number): MonoTypeOperatorFunction<number>;