Gathering detailed insights and metrics for @safelytyped/math-rounding
Gathering detailed insights and metrics for @safelytyped/math-rounding
npm install @safelytyped/math-rounding
Typescript
Module System
Node Version
NPM Version
71.5
Supply Chain
97.7
Quality
75.9
Maintenance
100
Vulnerability
98.9
License
Total Downloads
896
Last Day
1
Last Week
27
Last Month
95
Last Year
896
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
@safelytyped/math-rounding@1.0.1
Unpacked Size
129.02 kB
Size
35.17 kB
File Count
45
NPM Version
10.5.0
Node Version
20.12.0
Publised On
05 Apr 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
68.8%
27
Compared to previous week
Last month
2,275%
95
Compared to previous month
Last year
0%
896
Compared to previous year
1
This TypeScript library adds missing math rounding utilities, in a type-safe manner.
# run this from your Terminal
npm install @safelytyped/math-rounding
1// add this import to your Typescript code 2import { roundDown } from "@safelytyped/math-rounding";
VS Code users: once you've added a single import anywhere in your project, you'll then be able to auto-import anything else that this library exports.
Use roundDown()
to round a number down to the precision you require.
1import { roundDown } from "@safelytyped/math-rounding"; 2 3// res == 1.99 4const res = roundDown(2, 1.9999);
Use roundUp()
to round a number up to the precision you require.
1import { roundUp } from "@safelytyped/math-rounding"; 2 3// res == 2 4const res = roundUp(2, 1.99999);
Use roundTo()
if you want to inject your own rounding function.
1import { roundTo } from "@safelytyped/math-rounding"; 2 3// roundedDownRes == 1.99 4const roundedDownRes = roundDown( 5 Math.trunc, 6 2, 7 1.99999 8); 9 10// roundedUpRes == 2 11const roundedDownRes = roundDown( 12 Math.ceil, 13 2, 14 1.99999 15);
I found myself needing rounding functions in CSS Color that Javascript's stock Math
module doesn't provide. I've published them as a separate package so that I can reuse them in other packages in the future.
But this isn't the world's first package to add missing Math
rounding functions to Javascript / Typescript ... so why have I built it?
The main reason is that it follows the SafelyTyped philosophy of function parameter order:
I find that this makes partial functions a little more readable, such as:
1import { roundDown } from "@safelytyped/ts-math-rounding"; 2 3const roundDown2 = (x: number) => roundDown(2, x);
Here's a link to all the documentation about this project.
Follow us on Twitter!
No vulnerabilities found.
No security vulnerabilities found.