@terascope/utils / numbers
numbers
Index
Interfaces
Interface | Description |
---|---|
InNumberRangeArg | - |
Functions
bigIntToJSON()
bigIntToJSON(
int
):string
|number
Convert a BigInt to either a number or a string
Parameters
Parameter | Type |
---|---|
int | bigint |
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
Parameter | Type |
---|---|
input | unknown |
args | InNumberRangeArg |
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
Parameter | Type |
---|---|
args | InNumberRangeArg |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
input is number
Source
packages/utils/src/numbers.ts:270
isBigInt()
isBigInt(
input
):input is bigint
Check if value is a bigint
Parameters
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
val | unknown |
Returns
val is number
Source
packages/utils/src/numbers.ts:171
isInteger()
isInteger(
val
):val is number
A simplified implementation of lodash isInteger
Parameters
Parameter | Type |
---|---|
val | unknown |
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
Parameter | Type |
---|---|
input | unknown |
Returns
input is number
Source
packages/utils/src/numbers.ts:21
isNumberLike()
isNumberLike(
input
):boolean
A stricter check for verifying a number string
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
Todo
this needs to be smarter
Source
packages/utils/src/numbers.ts:119
isValidateNumberType()
isValidateNumberType(
type
): (input
) =>boolean
Parameters
Parameter | Type |
---|---|
type | FieldType |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
Source
packages/utils/src/numbers.ts:400
parseNumberList()
parseNumberList(
input
):number
[]
Like parseList, except it returns numbers
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
[]
Source
packages/utils/src/numbers.ts:215
random()
random(
min
,max
):number
A native implementation of lodash random
Parameters
Parameter | Type |
---|---|
min | number |
max | number |
Returns
number
Source
packages/utils/src/numbers.ts:16
setPrecision()
setPrecision(
input
,fractionDigits
,truncate
):number
Returns a truncated number to nth decimal places.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
input | unknown | undefined | - |
fractionDigits | number | undefined | The number of decimal points to round to. |
truncate | boolean | false | If 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
Parameter | Type | Default value | Description |
---|---|---|---|
fractionDigits | number | undefined | The number of decimal points to round to. |
truncate | boolean | false | If this is true the number will not be rounded |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
Source
packages/utils/src/numbers.ts:308
toBigInt()
toBigInt(
input
):bigint
|false
Convert any input to a bigint
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
bigint
| false
Source
packages/utils/src/numbers.ts:48
toBigIntOrThrow()
toBigIntOrThrow(
input
):bigint
Convert any input to a bigint
Parameters
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
input | unknown |
Returns
number
| false
Source
packages/utils/src/numbers.ts:179
toFloatOrThrow()
toFloatOrThrow(
input
):number
Convert an input to a float or throw
Parameters
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
input | unknown |
Returns
number
| false
Source
packages/utils/src/numbers.ts:135
toIntegerOrThrow()
toIntegerOrThrow(
input
):number
Convert an input to a integer or throw
Parameters
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
input | unknown |
Returns
number
Source
packages/utils/src/numbers.ts:26
toNumberOrThrow()
toNumberOrThrow(
input
):number
Will throw if converted number is NaN
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
Source
packages/utils/src/numbers.ts:33
validateByteNumber()
validateByteNumber(
input
):number
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
Source
packages/utils/src/numbers.ts:382
validateIntegerNumber()
validateIntegerNumber(
input
):number
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
Source
packages/utils/src/numbers.ts:390
validateNumberType()
validateNumberType(
type
): (input
) =>number
Parameters
Parameter | Type |
---|---|
type | FieldType |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
Source
packages/utils/src/numbers.ts:394
validateShortNumber()
validateShortNumber(
input
):number
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number