number-helper-functions
TypeScript icon, indicating that this package has built-in type declarations

4.1.1 • Public • Published

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:

Name Type Description
number NumberLike Number 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:

Name Type Default value Description
toCheck NumberLike - Number-like to convert
decimals number 2 -

Returns: number

Converted number

Defined in: modules/format.ts:38


enforceNumber

enforceNumber(n: NumberLike): number

Parameters:

Name Type
n NumberLike

Returns: number

Defined in: modules/base.ts:3


getRandom

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

Gets random integer number in a range

Parameters:

Name Type Description
min number Minimum number
max number Maximum 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:

Name Type Description
n NumberLike Number 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:

Name Type Description
n NumberLike Number 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:

Name Type Description
n NumberLike Number 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:

Name Type Description
n NumberLike The 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:

Name Type Description
n NumberLike Number 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:

Name Type Description
num number Number 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:

Name Type Description
number number Number to pad
length number Desired 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:

Name Type Default value Description
value NumberLike - String or number to process
decimals number 2 -

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:

Name Type Description
start number Starting value
end number End value
step number Step to use for the range

Returns: number[]

The range

Defined in: modules/utilities.ts:12

Readme

Keywords

none

Package Sidebar

Install

npm i number-helper-functions

Weekly Downloads

218

Version

4.1.1

License

MIT

Unpacked Size

26 kB

Total Files

20

Last publish

Collaborators

  • alrico88