Skip to content

Commit f4e6bf2

Browse files
committed
Update version to 4.7.1, rename countDecimalPlaces function to countDecimals, and add corresponding tests. Document changes in CHANGELOG.md and README.md.
1 parent a2a46ab commit f4e6bf2

7 files changed

Lines changed: 51 additions & 45 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# deverything
22

3+
## 4.7.1
4+
5+
### Patch Changes
6+
7+
- count decimals rename
8+
39
## 4.7.0
410

511
### Minor Changes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Contributions always welcome!
7777
### Math
7878

7979
- `average()`
80-
- `countDecimalPlaces()` count the number of decimal places in a number
80+
- `countDecimals()` count the number of decimal places in a number
8181
- `isBetween()`
8282
- `isOutside()`
8383
- `isStrictlyBetween()`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deverything",
3-
"version": "4.7.0",
3+
"version": "4.7.1",
44
"description": "Everything you need for Dev",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/math/countDecimalPlaces.test.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/math/countDecimals.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expect, test } from "vitest";
2+
import { countDecimals } from "./countDecimals";
3+
4+
describe("countDecimals", () => {
5+
test("integers", () => {
6+
expect(countDecimals(0)).toBe(0);
7+
expect(countDecimals(1)).toBe(0);
8+
expect(countDecimals(100)).toBe(0);
9+
expect(countDecimals(-5)).toBe(0);
10+
});
11+
12+
test("decimals", () => {
13+
expect(countDecimals(1.5)).toBe(1);
14+
expect(countDecimals(1.23)).toBe(2);
15+
expect(countDecimals(1.234567)).toBe(6);
16+
expect(countDecimals(0.1)).toBe(1);
17+
expect(countDecimals(0.123456789)).toBe(9);
18+
});
19+
20+
test("negative decimals", () => {
21+
expect(countDecimals(-1.5)).toBe(1);
22+
expect(countDecimals(-1.23)).toBe(2);
23+
expect(countDecimals(-0.123)).toBe(3);
24+
});
25+
26+
test("scientific notation", () => {
27+
expect(countDecimals(1e-5)).toBe(5);
28+
expect(countDecimals(1.23e-2)).toBe(4);
29+
expect(countDecimals(1.5e2)).toBe(0);
30+
});
31+
32+
test("edge cases", () => {
33+
expect(countDecimals(Infinity)).toBe(0);
34+
expect(countDecimals(-Infinity)).toBe(0);
35+
expect(countDecimals(NaN)).toBe(0);
36+
});
37+
});
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Counts the number of decimal places in a number.
33
* @example
4-
* countDecimalPlaces(1.23); // 2
5-
* countDecimalPlaces(1.234567); // 6
6-
* countDecimalPlaces(5); // 0
7-
* countDecimalPlaces(0.1); // 1
4+
* countDecimals(1.23); // 2
5+
* countDecimals(1.234567); // 6
6+
* countDecimals(5); // 0
7+
* countDecimals(0.1); // 1
88
*/
9-
export const countDecimalPlaces = (num: number): number => {
9+
export const countDecimals = (num: number): number => {
1010
if (!Number.isFinite(num)) return 0;
1111

1212
const numStr = num.toString();

src/math/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from "./average";
2-
export * from "./countDecimalPlaces";
2+
export * from "./countDecimals";
33
export * from "./isBetween";
44
export * from "./isOutside";
55
export * from "./isStrictlyBetween";

0 commit comments

Comments
 (0)