4.1.1 • Published 3 years ago

number-helper-functions v4.1.1

Weekly downloads
154
License
MIT
Repository
github
Last release
3 years ago

number-helper-functions

Library with multiple number-related methods.

Installation

Using npm

npm i number-helper-functions

Using yarn

yarn add number-helper-functions

Usage

In a CommonJS env

const NumberHelper = require('number-helper-functions');

NumberHelper.isInt(4); // returns true

or

const { isFinite } = require('number-helper-functions');

NumberHelper.isFinite(Infinity); // returns false

Using ES6 imports

import NumberHelper from 'number-helper-functions';

NumberHelper.isInt(4); // returns true

or

import { processNumber } from 'number-helper-functions';

NumberHelper.processNumber('4.5432', 2); // returns 4.54

Documentation

Table of contents

Functions

Functions

checkDecimals

checkDecimals(number: NumberLike): number

Checks the decimals of a number

Parameters:

NameTypeDescription
numberNumberLikeNumber to check the amount of decimals of

Returns: number

The number of decimals

Defined in: modules/format.ts:21


convertToNumber

convertToNumber(toCheck: NumberLike, decimals?: number): number

Converts string to number

Parameters:

NameTypeDefault valueDescription
toCheckNumberLike-Number-like to convert
decimalsnumber2-

Returns: number

Converted number

Defined in: modules/format.ts:38


enforceNumber

enforceNumber(n: NumberLike): number

Parameters:

NameType
nNumberLike

Returns: number

Defined in: modules/base.ts:3


getRandom

getRandom(min: number, max: number): number

Gets random integer number in a range

Parameters:

NameTypeDescription
minnumberMinimum number
maxnumberMaximum number

Returns: number

Random number in range

Defined in: modules/random.ts:8


isEven

isEven(n: NumberLike): boolean

Checks if number is even Any integer that can be divided exactly by 2 is an even number

Parameters:

NameTypeDescription
nNumberLikeNumber to check

Returns: boolean

Whether the number is even or not

Defined in: modules/checks.ts:49


isFloat

isFloat(n: NumberLike): boolean

Checks if element is a float number

Parameters:

NameTypeDescription
nNumberLikeNumber to check

Returns: boolean

Whether the number is a float or not

Defined in: modules/checks.ts:34


isInt

isInt(n: NumberLike): boolean

Checks if element is an integer

Parameters:

NameTypeDescription
nNumberLikeNumber to check

Returns: boolean

Whether the number is an integer or not

Defined in: modules/checks.ts:20


isNumber

isNumber(n: NumberLike): boolean

Checks if element is a number

Parameters:

NameTypeDescription
nNumberLikeThe element to check

Returns: boolean

Whether the element is a number or not

Defined in: modules/checks.ts:10


isOdd

isOdd(n: NumberLike): boolean

Checks if number is odd Any integer that cannot be divided exactly by 2 is an odd number.

Parameters:

NameTypeDescription
nNumberLikeNumber to check

Returns: boolean

Whether the number is odd or not

Defined in: modules/checks.ts:60


isPrime

isPrime(num: number): boolean

Checks if number is prime Natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers

Parameters:

NameTypeDescription
numnumberNumber to check

Returns: boolean

Whether the numbere is prime or not

Defined in: modules/checks.ts:71


prefixWithZeros

prefixWithZeros(number: number, length: number): string

Prefixes a number with zeros until desired length

Parameters:

NameTypeDescription
numbernumberNumber to pad
lengthnumberDesired number length

Returns: string

Padded number as a string

Defined in: modules/format.ts:12


processNumber

processNumber(value: NumberLike, decimals?: number): number

Processes number to get clean value

Parameters:

NameTypeDefault valueDescription
valueNumberLike-String or number to process
decimalsnumber2-

Returns: number

Parsed and processed number

Defined in: modules/format.ts:55


rangeBetween

rangeBetween(start: number, end: number, step: number): number[]

Creates a range between start and end, including them, according to step

Parameters:

NameTypeDescription
startnumberStarting value
endnumberEnd value
stepnumberStep to use for the range

Returns: number[]

The range

Defined in: modules/utilities.ts:12