Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

number-helper-functions

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

number-helper-functions

Helper with multiple number-related methods

  • 4.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132
decreased by-52%
Maintainers
1
Weekly downloads
 
Created
Source

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

  • checkDecimals
  • convertToNumber
  • enforceNumber
  • getRandom
  • isEven
  • isFloat
  • isInt
  • isNumber
  • isOdd
  • isPrime
  • prefixWithZeros
  • processNumber
  • rangeBetween

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

FAQs

Package last updated on 30 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc