Skip to main content

@terascope/utils / numbers

numbers

Index

Interfaces

InterfaceDescription
InNumberRangeArg-

Functions

bigIntToJSON()

bigIntToJSON(int): string | number

Convert a BigInt to either a number or a string

Parameters

ParameterType
intbigint

Returns

string | number

Source

packages/utils/src/numbers.ts:106


inNumberRange()

inNumberRange(input, args): input is number

Returns true if number is between min or max value provided

Parameters

ParameterType
inputunknown
argsInNumberRangeArg

Returns

input is number

Example

inNumberRange(42, { min: 0, max: 100}); // true
inNumberRange(-42, { min:0 , max: 100 }); // false
inNumberRange(42, { min: 0, max: 42 }); // false
inNumberRange(42, { min: 0, max: 42, inclusive: true }) // true

Source

packages/utils/src/numbers.ts:257


inNumberRangeFP()

inNumberRangeFP(args): (input) => input is number

Parameters

ParameterType
argsInNumberRangeArg

Returns

Function

Parameters
ParameterType
inputunknown
Returns

input is number

Source

packages/utils/src/numbers.ts:270


isBigInt()

isBigInt(input): input is bigint

Check if value is a bigint

Parameters

ParameterType
inputunknown

Returns

input is bigint

Source

packages/utils/src/numbers.ts:43


isFloat()

isFloat(val): val is number

Verify the input is a finite number (and float like)

Parameters

ParameterType
valunknown

Returns

val is number

Source

packages/utils/src/numbers.ts:171


isInteger()

isInteger(val): val is number

A simplified implementation of lodash isInteger

Parameters

ParameterType
valunknown

Returns

val is number

Source

packages/utils/src/numbers.ts:129


isNumber()

isNumber(input): input is number

Check if an input is a number

Parameters

ParameterType
inputunknown

Returns

input is number

Source

packages/utils/src/numbers.ts:21


isNumberLike()

isNumberLike(input): boolean

A stricter check for verifying a number string

Parameters

ParameterType
inputunknown

Returns

boolean

Todo

this needs to be smarter

Source

packages/utils/src/numbers.ts:119


isValidateNumberType()

isValidateNumberType(type): (input) => boolean

Parameters

ParameterType
typeFieldType

Returns

Function

Parameters
ParameterType
inputunknown
Returns

boolean

Source

packages/utils/src/numbers.ts:400


parseNumberList()

parseNumberList(input): number[]

Like parseList, except it returns numbers

Parameters

ParameterType
inputunknown

Returns

number[]

Source

packages/utils/src/numbers.ts:215


random()

random(min, max): number

A native implementation of lodash random

Parameters

ParameterType
minnumber
maxnumber

Returns

number

Source

packages/utils/src/numbers.ts:16


setPrecision()

setPrecision(input, fractionDigits, truncate): number

Returns a truncated number to nth decimal places.

Parameters

ParameterTypeDefault valueDescription
inputunknownundefined-
fractionDigitsnumberundefinedThe number of decimal points to round to.
truncatebooleanfalseIf this is true the number will not be rounded

Returns

number

Source

packages/utils/src/numbers.ts:282


setPrecisionFP()

setPrecisionFP(fractionDigits, truncate): (input) => number

A functional programming version of setPrecision

Parameters

ParameterTypeDefault valueDescription
fractionDigitsnumberundefinedThe number of decimal points to round to.
truncatebooleanfalseIf this is true the number will not be rounded

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/numbers.ts:308


toBigInt()

toBigInt(input): bigint | false

Convert any input to a bigint

Parameters

ParameterType
inputunknown

Returns

bigint | false

Source

packages/utils/src/numbers.ts:48


toBigIntOrThrow()

toBigIntOrThrow(input): bigint

Convert any input to a bigint

Parameters

ParameterType
inputunknown

Returns

bigint

Source

packages/utils/src/numbers.ts:65


toCelsius()

toCelsius(input): number

Convert a fahrenheit value to celsius, this will return a precision of 2 decimal points

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:336


toFahrenheit()

toFahrenheit(input): number

Convert a celsius value to fahrenheit, this will return a precision of 2 decimal points

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:347


toFloat()

toFloat(input): number | false

Convert an input to a float, return false if unable to convert input

Parameters

ParameterType
inputunknown

Returns

number | false

Source

packages/utils/src/numbers.ts:179


toFloatOrThrow()

toFloatOrThrow(input): number

Convert an input to a float or throw

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:188


toInteger()

toInteger(input): number | false

Convert an input to a integer, return false if unable to convert input

Parameters

ParameterType
inputunknown

Returns

number | false

Source

packages/utils/src/numbers.ts:135


toIntegerOrThrow()

toIntegerOrThrow(input): number

Convert an input to a integer or throw

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:144


toNumber()

toNumber(input): number

Convert any input to a number, return Number.NaN if unable to convert input

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:26


toNumberOrThrow()

toNumberOrThrow(input): number

Will throw if converted number is NaN

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:33


validateByteNumber()

validateByteNumber(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:382


validateIntegerNumber()

validateIntegerNumber(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:390


validateNumberType()

validateNumberType(type): (input) => number

Parameters

ParameterType
typeFieldType

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/numbers.ts:394


validateShortNumber()

validateShortNumber(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/numbers.ts:386