Options
All
  • Public
  • Public/Protected
  • All
Menu

Module - Number

Type aliases

ArrayOrSetNumbers: number[] | Set<number>

An Array-like interface that is an array of items or a set of items

internal
typeparam

The type of the value from the input source

Functions

  • add(input: number | ObservableInput<number>): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits a number that is the addition of the source number with input number

    example

    Returns a number that is the addition of source and input

    const input = [2, 3, 4, 5, 6];
    from(input).pipe(add(3)).subscribe();

    Output: 5, 6, 7, 8, 9

    Parameters

    • input: number | ObservableInput<number>

      The number to add to the source value

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that is the addition of source and input

  • div(input: number | ObservableInput<number>): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits a number that is the division of the source number with input number

    remarks

    If the input value is 0 this operator will throw an error

    example

    Returns a number that is the division of source and input

    const input = [4, 10, 12, 18, 20];
    from(input).pipe(div(2)).subscribe();

    Output: 2, 5, 6, 9, 10

    Parameters

    • input: number | ObservableInput<number>

      The number to divide to the source value

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that is the division of source and input

  • filterInRange(min: ObservableInput<number> | number, max: ObservableInput<number> | number, excludeBoundingValues?: ObservableInput<boolean> | boolean): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits numbers, where that number falls between the provided min and max values. When filtering in range, the range numbers are included in the filter - to exclude them set excludeBoundingValues to true.

    see

    The inRange operator returns a boolean value instead of the number

    see

    The filterOutOfRange can be used to get numbers that fall outside the min and max range

    example

    Return only numbers in and including the range of 0 to 10

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(filterInRange(0, 10)).subscribe();

    Output: 0, 1, 2, 3.4, 4.2, 10

    example

    Return only numbers in the range of 0 to 10 and also filter the min and max

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(filterInRange(0, 10, true)).subscribe();

    Output: 1, 2, 3.14, 4.2

    Parameters

    • min: ObservableInput<number> | number

      The minimum range value

    • max: ObservableInput<number> | number

      The maximum range value

    • Optional excludeBoundingValues: ObservableInput<boolean> | boolean

      Also filter the min and max values from the Observable

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that falls within the passed min and max range

  • filterIsFinite(): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits numbers from a source where they pass the check of Number.isFinite.

    remarks

    Certain operations such as dividing by zero or multiplying passed Number.MAX_VALUE in JavaScript can cause Infinity to be generated, this operator can help avoid those values

    see

    The isFinite operator returns a boolean value instead of the number

    example

    Return only finite values

    const input = [-Infinity, -2.3, 0, 1, Infinity, 3.14, 4.2, 10, 11, Number.MAX_VALUE * 2];
    from(input).pipe(filterIsFinite()).subscribe();

    Output: -2.3, 0, 2, 3.14, 4.2, 10, 11

    Returns MonoTypeOperatorFunction<number>

    Observable that emits numbers that are finite

  • filterIsFloat(): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits only valid finite floating point numbers from a source

    see

    The isFloat operator returns a boolean value instead of the number

    example

    Return only values that are floating point numbers

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(filterIsFloat()).subscribe();

    Output: -2.3, 3.14, 4.2

    Returns MonoTypeOperatorFunction<number>

    Observable that emits valid finite floating point numbers

  • filterIsInteger(): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits only integer numbers from a source that pass the check of Number.isInteger.

    see

    The isInteger operator returns a boolean value instead of the number

    example

    Return only values that are integer values

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(filterIsInteger()).subscribe()

    Output: -10, 0, 1, 2, 10, 11, 42

    Returns MonoTypeOperatorFunction<number>

    Observable that emits integer numbers

  • filterIsNotNaN(): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits number values from a source filtering out any NaN values.

    see

    The isNotNaN operator returns a boolean value instead of the number

    example

    Returns only valid numbers where the source may contain NaN values

    const input = [NaN, -2.3, 0, NaN, 2, 3.14, 4.2, NaN, 11, 42];
    from(input).pipe(filterIsNotNaN()).subscribe()

    Output: -2.3, 0, 2, 3.14, 4.2, 11, 42

    Returns MonoTypeOperatorFunction<number>

    Observable that emits valid numbers and excludes NaN values

  • filterIsSafeInteger(): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits numbers that are within the safe number range for JavaScript number precision using Number.isSafeInteger

    see

    The isSafeInteger operator returns a boolean value instead of the number

    example

    Returns only integers within safe precision range

    // `Math.pow(2, 53)` is not within the safe integer range
    const input = [-10, -2.3, 0, 1, 2, 3.14, Math.pow(2, 53) - 1, Math.pow(2, 53), Infinity];
    from(input).pipe(filterIsSafeInteger()).subscribe()

    Output: -10, 0, 1, 2, 9007199254740991

    Returns MonoTypeOperatorFunction<number>

    Observable that emits integer numbers within Number.isSafeInteger equality check

  • filterOutOfRange(min: ObservableInput<number> | number, max: ObservableInput<number> | number, includeBounds?: ObservableInput<boolean> | boolean): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits numbers, where that number falls outside the provided min and max values. When filtering in range, the range numbers are excluded in the filter - to include them set includeBounds to true.

    see

    The inRange operator returns a boolean value instead of the number

    see

    The filterOutOfRange can be used to get numbers that fall outside the min and max range

    example

    Returns values outside the min and max range

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(filterOutOfRange(0, 10)).subscribe();

    Output: -10, -2.3, 11, 42

    example

    Returns values outside and including the min and max range

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(filterOutOfRange(0, 10, true)).subscribe();

    Output: -10, -2.3, 0, 10, 11, 42

    Parameters

    • min: ObservableInput<number> | number

      The minimum range value

    • max: ObservableInput<number> | number

      The maximum range value

    • Optional includeBounds: ObservableInput<boolean> | boolean

      Optionally include the min and max values in the Observable

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that falls outside the min and max ranges

  • fromFibonacci(iterations: number, emitDelay?: number): Observable<number>
  • Returns an Observable that emits a sequence of numbers in the Fibonacci sequence, starting from 0

    example

    Emit the first 5 numbers of the Fibonacci sequence immediately

    fromFibonacci(5).subscribe();

    Output: 0, 1, 1, 2, 3

    example

    Emit the first 10 numbers of the Fibonacci sequence once per second, and skip 0

    fromFibonacci(10, 1000).pipe(skip(1)).subscribe();

    Output: 1, 1, 2, 3, 5, 8, 13, 21, 34

    Parameters

    • iterations: number

      The number of iterations to do, must be greater than 0

    • Default value emitDelay: number = 0

      If set the observable will emit per millisecond set, by default this is 0

    Returns Observable<number>

    Observable of a Fibonacci sequence of numbers starting from 0

  • Returns an Observable that emits numbers from an an arguments list or array of number values

    remarks

    This is a type-safe version of the RxJS from operator that only accepts numbers as input

    example

    Returns an observable from a single number and multiply the value

    fromNumber(6).pipe(map(val => val * 7)).subscribe();

    Output: 42

    example

    Returns an Observable from an argument list of numbers and reduce the values

    fromNumber(1, 2, 3, 4).pipe(reduce((acc, val) => acc + val)).subscribe();

    Output: 10

    example

    Returns an Observable from an array of numbers and reduce the values

    const input = [1, 2, 3, 4];
    fromNumber(input).pipe(reduce((acc, val) => acc + val)).subscribe();

    Output: 10

    Parameters

    Returns Observable<number>

    Observable that emits numbers passed from arguments or array

  • inRange(min: ObservableInput<number> | number, max: ObservableInput<number> | number, excludeBoundingValues?: ObservableInput<boolean> | boolean): OperatorFunction<number, boolean>
  • Returns an Observable that emits booleans about values from a source that fall within the passed min and max range, including the range numbers. To emit a boolean for numbers only between the min and max set excludeBoundingValues to true.

    see

    The filterInRange operator returns the number value

    example

    Returns a boolean value if the number is in the range

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(inRange(0, 10)).subscribe();

    Output: false, false, true, true, true, true, true, true, false, false

    example

    Returns a boolean value if the number is in the range excluding the min and max

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(inRange(0, 10, true)).subscribe();

    Output: false, false, false, true, true, true, true, false, false, false

    Parameters

    • min: ObservableInput<number> | number

      The minimum number for the range

    • max: ObservableInput<number> | number

      The maximum number for the range

    • Optional excludeBoundingValues: ObservableInput<boolean> | boolean

      Optionally filter the min and max values from the Observable

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean if the source number falls within the passed min and max range

  • isFinite(): OperatorFunction<number, boolean>
  • Returns an Observable that emits a boolean value when a source number is a finite number using Number.isFinite

    see

    The filterIsFinite operator returns the number value

    example

    Return boolean for finite values

    const input = [-Infinity, -2.3, 0, 1, Infinity, 3.14, 4.2, 10, 11, Number.MAX_VALUE * 2];
    from(input).pipe(isFinite()).subscribe();

    Output: false, true, true, true, false, true, true, true, true, false

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean of a source number being finite

  • isFloat(): OperatorFunction<number, boolean>
  • Returns an Observable that emits a boolean value when a source number is a a valid finite floating point

    see

    The filterIsFloat operator returns the number value

    example

    Return boolean for floating point numbers

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(isFloat()).subscribe();

    Output: false, true, false, false, false, true, true, false, false, false

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean of a source number is a valid finite floating point

  • isInteger(): OperatorFunction<number, boolean>
  • Returns an Observable that emits a boolean value when a source number is an integer checked with Number.isInteger

    see

    The filterIsInteger operator returns the number value

    example

    Return booleans for values that are integer values

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(filterIsInteger()).subscribe()

    Output: true, false, true, true, true, false, false, true, true, true

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean of a source number being an integer

  • isNaN(): OperatorFunction<number, boolean>
  • Returns an Observable that emits a boolean value when a source number is a NaN value from Number.isNaN.

    see

    The filterIsNotNaN operator returns the number value

    example

    Return a boolean if a number is a NaN value

    const input = ['Ninja', 1, 2, NaN, 3.14, undefined];
    from(input).pipe(isNaN()).subscribe();

    Output: true, false, false, true, false, true

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean value of a number being valid or NaN

  • isNotNaN(): OperatorFunction<number, boolean>
  • Returns an Observable that emits a boolean value when a source number is valid and not NaN, checked using Number.isNaN

    remarks

    This is mostly for convenience of getting truthy values that are valid for numbers without flipping the value os isNaN

    see

    The filterIsNotNaN operator returns the number value

    example

    Return a boolean if a number is not NaN value

    const input = ['Ninja', 1, 2, NaN, 3.14, undefined];
    from(input).pipe(isNotNaN()).subscribe();

    Output: false, true, true, false, true, false

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean value of a number being valid or NaN

  • isSafeInteger(): OperatorFunction<number, boolean>
  • Returns an Observable that emits a boolean value when a source number has precision safety using Number.isSafeInteger

    see

    The filterIsSafeInteger operator returns the number value

    example

    Return a boolean if a number does not have percision safety

    // `Math.pow(2, 53)` is not within the safe integer range
    const input = [-10, -2.3, 0, 1, 2, 3.14, Math.pow(2, 53) - 1, Math.pow(2, 53), Infinity];
    from(input).pipe(isSafeInteger()).subscribe()

    Output: true, false, true, true, true, false, true, false, false

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean value of a number has precision safety

  • mod(modulus: number | ObservableInput<number>): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits a number that is the remainder of the Modulo operation of the source number by the divider

    example

    Return the remainder of modulus 3

    const input = [2, 3, 4, 5, 6];
    from(input).pipe(mod(3)).subscribe();

    Output: 2, 0, 1, 2, 6

    Parameters

    • modulus: number | ObservableInput<number>

      The dividing number for the Modulo operation

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that is reminder of a Modulo operation

  • mul(input: number | ObservableInput<number>): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits a number that is the multiplication of the source number with input number

    example

    Returns a number that is the multiplication of source and input

    const input = [2, 3, 4, 5, 6];
    from(input).pipe(mul(2)).subscribe();

    Output: 4, 6, 8, 10, 12

    Parameters

    • input: number | ObservableInput<number>

      The number to multiply to the source value

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that is the multiplication of source and input

  • outOfRange(min: ObservableInput<number> | number, max: ObservableInput<number> | number, includeBounds?: ObservableInput<boolean> | boolean): OperatorFunction<number, boolean>
  • Returns an Observable that emits booleans about values from a source that fall outside the passed min and max range, excluding the range numbers. To emit a boolean for numbers including the min and max set includeBoundingParameters to true.

    see

    To get numbers outside of a range use filterOutOfRange

    example

    Returns a boolean value if the number is out the range including the min and max

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(outOfRange(0, 10)).subscribe();

    Output: true, true, true, false, false, false, false, true, true, true

    example

    Returns a boolean value if the number is out the range excluding the min and max

    const input = [-10, -2.3, 0, 1, 2, 3.14, 4.2, 10, 11, 42];
    from(input).pipe(outOfRange(0, 10, true)).subscribe();

    Output: true, true, false, false, false, false, false, false, true, true

    Parameters

    • min: ObservableInput<number> | number

      The minimum number for the range

    • max: ObservableInput<number> | number

      The maximum number for the range

    • Optional includeBounds: ObservableInput<boolean> | boolean

      Optionally include the min and max values in the Observable

    Returns OperatorFunction<number, boolean>

    Observable that emits a boolean if the source number falls outside the passed min and max range

  • parseFloat(returnNaN?: undefined | false | true): OperatorFunction<string, number>
  • Returns an Observable that emits a number from a source string using Number.parseFloat. By default this operator removes NaN values but can optionally be set to return them

    example

    Return only parsed number values using base 10

    const input = ['RxJS', '-2.3', '0', '1', '2', '3.14', 'Infinity'];
    from(input).pipe(parseFloat()).subscribe();

    Output: -2.3, 0, 1, 2, 3.14

    example

    Return parsed number values and NaN values using base 10

    const input = ['RxJS', '-2.3', '0', '1', '2', '3.14', 'Infinity'];
    from(input).pipe(parseFloat(10, true)).subscribe();

    Output: NaN, -2.3, 0, 1, 2, 3.14, NaN

    Parameters

    • Optional returnNaN: undefined | false | true

      Optionally return NaN values instead of filtering

    Returns OperatorFunction<string, number>

    Observable that emits a number from source parsed string, optionally returns NaN values

  • parseHex(returnNaN?: undefined | false | true): OperatorFunction<string, number>
  • Returns an Observable that emits a number from a source hex using Number.parseInt. By default this operator removes NaN values but can optionally be set to return them

    example

    Return only parsed hex values

    const input = ['RxJS', 'ff', '00', '1b', '23', 'c89bb'];
    from(input).pipe(parseHex()).subscribe();

    Output: 255, 0, 27, 25, 821691

    example

    Return parsed integer values and NaN values using base 10

    const input = ['RxJS', 'ff', '00', '1b', '23', 'c89bb'];
    from(input).pipe(parseHex(true)).subscribe();

    Output: NaN, 255, 0, 27, 25, 821691

    Parameters

    • Optional returnNaN: undefined | false | true

      Optionally return NaN values instead of filtering

    Returns OperatorFunction<string, number>

    Observable that emits a number from source hex value, optionally returns NaN values

  • parseInt(radix?: ObservableInput<number> | number, returnNaN?: ObservableInput<boolean> | boolean): OperatorFunction<string, number>
  • Returns an Observable that emits a number from a source string using Number.parseInt. By default this operator removes NaN values but can optionally be set to return them

    example

    Return only parsed integer values using base 10

    const input = ['RxJS', '-2.3', '0', '1', '2', '3.14', 'Infinity'];
    from(input).pipe(parseInt()).subscribe();

    Output: -2, 0, 1, 2, 3

    example

    Return parsed integer values and NaN values using base 10

    const input = ['RxJS', '-2.3', '0', '1', '2', '3.14', 'Infinity'];
    from(input).pipe(parseInt(10, true)).subscribe();

    Output: NaN, -2, 0, 1, 2, 3, NaN

    example

    Return parsed integer values using base 16

    const input = ['1', 'ff', '40'];
    from(input).pipe(parseInt(16)).subscribe();

    Output: 1, 255, 64

    Parameters

    • Default value radix: ObservableInput<number> | number = 10

      The number base to convert from. Default is base 10

    • Optional returnNaN: ObservableInput<boolean> | boolean

      Optionally return NaN values instead of filtering

    Returns OperatorFunction<string, number>

    Observable that emits a number from source parsed string, optionally returns NaN values

  • pow(power: number | ObservableInput<number>): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits a number from a source number that is raised by the passed power using the exponentiation operator **

    example

    Return values raised to the power 2

    const input = [2, 4, 10, 16, 256];
    from(input).pipe(raiseBy(2)).subscribe();

    Output: 4, 25, 100, 256, 655356

    Parameters

    • power: number | ObservableInput<number>

      The number to raise the value by

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that is the raised source value by the power

  • sub(input: number | ObservableInput<number>): MonoTypeOperatorFunction<number>
  • Returns an Observable that emits a number that is the subtraction of the source number with input number

    example

    Returns a number that is the subtract of source and input

    const input = [2, 3, 4, 5, 6];
    from(input).pipe(sub(3)).subscribe();

    Output: -1, 0, 1, 2, 3

    Parameters

    • input: number | ObservableInput<number>

      The number to subtract to the source value

    Returns MonoTypeOperatorFunction<number>

    Observable that emits a number that is the subtraction of source and input

  • toExponential(exponential: number | ObservableInput<number>): OperatorFunction<number, string>
  • Returns an Observable that emits a formatted string of a number raised to an exponential power using Number.toExponential.

    example

    Return a string passed numbers to the exponential of 2

    const input = [-1, 0, 1, 2, 3.4];
    from(input).pipe(toExponential(2)).subscribe();

    Output: '-1.00e+0', '0.00e+0', '1.00e+0', '2.30e+0', '3.14e+0'

    Parameters

    • exponential: number | ObservableInput<number>

      The exponential value to raise the number by

    Returns OperatorFunction<number, string>

    Observable that emits a formatted string of the exponential number

  • toFixed(digits?: number | ObservableInput<number>): OperatorFunction<number, string>
  • Returns an Observable that emits a formatted string value from a source number using Number.toFixed.

    example

    Return a string of a number to fixed position of 2

    const input = [1.8372, 2.12353, 3.14, 42.2];
    from(input).pipe(toString()).subscribe();

    Output: '1.834', '2.12', '3.14', '42.20'

    Parameters

    • Optional digits: number | ObservableInput<number>

      Optional number of digits to fix to, if not passed treated as 0

    Returns OperatorFunction<number, string>

    Observable that emits a formatted string from a source number to a fixed decimal value

  • toHex(): OperatorFunction<number, string>
  • Returns an Observable that emits a string that is the hex value of a source number *

    example

    Return a hex value of source number

    const input = [2, 16, 32, 75, 255];
    from(input).pipe(toHex()).subscribe();

    Output: '2', '10', '20', '4b', 'ff'

    Returns OperatorFunction<number, string>

    Observable that emits the hex value of a source number

  • toLocaleString(locales?: ObservableInput<string | string[]> | string | string[], format?: ObservableInput<NumberFormatOptions> | NumberFormatOptions): OperatorFunction<number, string>
  • Returns an Observable that emits a formatted string value from a source number using Number.toLocaleString with optional formatting options provided by Intl.NumberFormat.

    example

    Return a string with Dutch number formatting

    of(1000000).pipe(toLocaleString('nl-NL')).subscribe();

    Output: '1.000.000'

    example

    Return a string with UK English number formatting

    of(1000000).pipe(toLocaleString('en-GB')).subscribe();

    Output: '1,000,000'

    example

    Return a string with UK English number formatting and Euro currency style

    of(1000000).pipe(toLocaleString('en-GB', { currency: 'EUR', style: 'currency' })).subscribe();

    Output: '€1,000,000.00'

    Parameters

    • Optional locales: ObservableInput<string | string[]> | string | string[]

      The locale or locales that the number is being formatted for

    • Optional format: ObservableInput<NumberFormatOptions> | NumberFormatOptions

      Formatting of the string based on Intl.NumberFormat

    Returns OperatorFunction<number, string>

    Observable that emits a formatted string from a source number

  • toPrecision(precision: number | ObservableInput<number>): OperatorFunction<number, string>
  • Returns an Observable that emits a formatted string value from a source number using Number.toPrecision.

    example

    Return a string of numbers formatted to a precision of 4 places

    const input = [123.456, 0.004, 1.23e5];
    from(input).pipe(toPrecision(4)).subscribe();

    Output: '123.5', '0.004000', '1.230e+5'

    Parameters

    • precision: number | ObservableInput<number>

      The number of decimal places to format the precision to.

    Returns OperatorFunction<number, string>

    Observable that emits a formatted string from a source number

  • toString(radix?: number | ObservableInput<number>): OperatorFunction<number, string>
  • Returns an Observable that emits a formatted string value from a source number using Number.toString.

    example

    Return string values of numbers using base 10 conversion

    const input = [1, 2, 3.14, 42];
    from(input).pipe(toString()).subscribe();

    Output: '1', '2', '3.14', '42'

    example

    Return string values of numbers using base 16 conversion

    const input = [8, 16, 32, 64];
    from(input).pipe(toString(16)).subscribe();

    Output: '8', '10', '20', '40'

    Parameters

    • Default value radix: number | ObservableInput<number> = 10

      The base number to format to. Default is 10.

    Returns OperatorFunction<number, string>

    Observable that emits a formatted string from a source number and passed radix value

Generated using TypeDoc, the 1/19/2021 at 12:42:11 AM