Socket
Book a DemoInstallSign in
Socket

@donutteam/number-utilities

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@donutteam/number-utilities

A collection of various number-related utility functions.

unpublished
latest
Source
npmnpm
Version
1.4.0
Version published
Maintainers
1
Created
Source

Number Utilities

A collection of various number-related utility functions.

Installation

Install the package with NPM:

npm install @donutteam/number-utilities

Usage

centsToUSD

Takes an amount of cents and formats it as an amount of US dollars.

import { centsToUSD } from "@donutteam/number-utilities";

// Returns $43.20
const myDollars = centsToUSD(4320); 

clamp

Clamps a number between the given minimum and maximums.

import { clamp } from "@donutteam/number-utilities";

// 50
const clamped1 = clamp(127, 25, 50);

// 130
const clamped2 = clamp(127, 130, 150);

// 127
const clamped3 = clamp(127, 25, 150);

dollarsToUSD

Takes an amount of dollars and formats it as an amount of US dollars.

import { dollarsToUSD } from "@donutteam/number-utilities";

// Returns $43.20
const myDollars = dollarsToUSD(43.20); 

randomInt

Generates a random integer between the minimum (inclusive) and the maximum (exclusive) values given to it:

import { randomInt } from "@donutteam/number-utilities";

// Will be some number from 0 to 9
const myRandomInteger = randomInt(0, 10);

roundToNearestMultiple

Rounds a number to the nearest multiple of the other number.

import { roundToNearestMultiple } from "@donutteam/number-utilities";

// Returns 450
const myRoundedNumber = roundToNearestMultiple(457, 50);

roundDownToNearestMultiple

Rounds a number down to the nearest multiple of the other number.

import { roundDownToNearestMultiple } from "@donutteam/number-utilities";

// Returns 450
const myRoundedNumber = roundDownToNearestMultiple(499, 50);

roundUpToNearestMultiple

Rounds a number up to the nearest multiple of the other number.

import { roundUpToNearestMultiple } from "@donutteam/number-utilities";

// Returns 500
const myRoundedNumber = roundUpToNearestMultiple(457, 50);

License

MIT

Keywords

number

FAQs

Package last updated on 11 Apr 2023

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