A collection of modern utility functions for handling numbers in JavaScript and TypeScript .
You can install modern-number-utils using npm:
npm install modern-number-utils
Converts the input to an integer. Validates that the input is a valid number.
import { convertToInt } from 'modern-number-utils';
const result = convertToInt('42');
console.log(result); // 42
Converts the input to a number with two decimal places. Validates that the input is a valid number.
import { convertToTwoDecimalInt } from 'modern-number-utils';
const result = convertToTwoDecimalInt('42.123');
console.log(result); // 42.12
Generates a random number with the specified length (number of digits).
import { randomNumberWithFixedLength } from 'modern-number-utils';
const result = randomNumberWithFixedLength(5);
console.log(result); // Random number with 5 digits
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.