npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

number-helper-functions

v4.1.1

Published

Helper with multiple number-related methods

Downloads

985

Readme

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