Skip to main content

@terascope/utils / numbers

numbers

Interfaces

InterfaceDescription
InNumberRangeArg-

Functions

bigIntToJSON()

bigIntToJSON(int): string | number

Defined in: packages/utils/src/numbers.ts:106

Convert a BigInt to either a number or a string

Parameters

ParameterType
intbigint

Returns

string | number


inNumberRange()

inNumberRange(input, args): input is number

Defined in: packages/utils/src/numbers.ts:257

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

inNumberRangeFP()

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

Defined in: packages/utils/src/numbers.ts:270

Parameters

ParameterType
argsInNumberRangeArg

Returns

Function

Parameters
ParameterType
inputunknown
Returns

input is number


isBigInt()

isBigInt(input): input is bigint

Defined in: packages/utils/src/numbers.ts:43

Check if value is a bigint

Parameters

ParameterType
inputunknown

Returns

input is bigint


isFloat()

isFloat(val): val is number

Defined in: packages/utils/src/numbers.ts:171

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

Parameters

ParameterType
valunknown

Returns

val is number


isInteger()

isInteger(val): val is number

Defined in: packages/utils/src/numbers.ts:129

A simplified implementation of lodash isInteger

Parameters

ParameterType
valunknown

Returns

val is number


isNumber()

isNumber(input): input is number

Defined in: packages/utils/src/numbers.ts:21

Check if an input is a number

Parameters

ParameterType
inputunknown

Returns

input is number


isNumberLike()

isNumberLike(input): boolean

Defined in: packages/utils/src/numbers.ts:119

A stricter check for verifying a number string

Parameters

ParameterType
inputunknown

Returns

boolean

Todo

this needs to be smarter


isValidateNumberType()

isValidateNumberType(type): (input) => boolean

Defined in: packages/utils/src/numbers.ts:400

Parameters

ParameterType
typeFieldType

Returns

Function

Parameters
ParameterType
inputunknown
Returns

boolean


parseNumberList()

parseNumberList(input): number[]

Defined in: packages/utils/src/numbers.ts:215

Like parseList, except it returns numbers

Parameters

ParameterType
inputunknown

Returns

number[]


random()

random(min, max): number

Defined in: packages/utils/src/numbers.ts:16

A native implementation of lodash random

Parameters

ParameterType
minnumber
maxnumber

Returns

number


setPrecision()

setPrecision(input, fractionDigits, truncate): number

Defined in: packages/utils/src/numbers.ts:282

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


setPrecisionFP()

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

Defined in: packages/utils/src/numbers.ts:308

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


toBigInt()

toBigInt(input): bigint | false

Defined in: packages/utils/src/numbers.ts:48

Convert any input to a bigint

Parameters

ParameterType
inputunknown

Returns

bigint | false


toBigIntOrThrow()

toBigIntOrThrow(input): bigint

Defined in: packages/utils/src/numbers.ts:65

Convert any input to a bigint

Parameters

ParameterType
inputunknown

Returns

bigint


toCelsius()

toCelsius(input): number

Defined in: packages/utils/src/numbers.ts:336

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

Parameters

ParameterType
inputunknown

Returns

number


toFahrenheit()

toFahrenheit(input): number

Defined in: packages/utils/src/numbers.ts:347

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

Parameters

ParameterType
inputunknown

Returns

number


toFloat()

toFloat(input): number | false

Defined in: packages/utils/src/numbers.ts:179

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

Parameters

ParameterType
inputunknown

Returns

number | false


toFloatOrThrow()

toFloatOrThrow(input): number

Defined in: packages/utils/src/numbers.ts:188

Convert an input to a float or throw

Parameters

ParameterType
inputunknown

Returns

number


toInteger()

toInteger(input): number | false

Defined in: packages/utils/src/numbers.ts:135

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

Parameters

ParameterType
inputunknown

Returns

number | false


toIntegerOrThrow()

toIntegerOrThrow(input): number

Defined in: packages/utils/src/numbers.ts:144

Convert an input to a integer or throw

Parameters

ParameterType
inputunknown

Returns

number


toNumber()

toNumber(input): number

Defined in: packages/utils/src/numbers.ts:26

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

Parameters

ParameterType
inputunknown

Returns

number


toNumberOrThrow()

toNumberOrThrow(input): number

Defined in: packages/utils/src/numbers.ts:33

Will throw if converted number is NaN

Parameters

ParameterType
inputunknown

Returns

number


validateByteNumber()

validateByteNumber(input): number

Defined in: packages/utils/src/numbers.ts:382

Parameters

ParameterType
inputunknown

Returns

number


validateIntegerNumber()

validateIntegerNumber(input): number

Defined in: packages/utils/src/numbers.ts:390

Parameters

ParameterType
inputunknown

Returns

number


validateNumberType()

validateNumberType(type): (input) => number

Defined in: packages/utils/src/numbers.ts:394

Parameters

ParameterType
typeFieldType

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number


validateShortNumber()

validateShortNumber(input): number

Defined in: packages/utils/src/numbers.ts:386

Parameters

ParameterType
inputunknown

Returns

number