@leaderty/utils 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -1
- package/dist/index.js +8 -2
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +7 -0
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Formatea un número a una cadena con dos decimales y separadores de miles.
|
|
3
|
+
*/
|
|
4
|
+
export function numberToStringWithDecimals(numero) {
|
|
5
|
+
const formatted = numero.toFixed(2);
|
|
6
|
+
const [integerPart, decimalPart] = formatted.split('.');
|
|
7
|
+
const withThousandsSeparator = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
8
|
+
return `${withThousandsSeparator},${decimalPart}`;
|
|
3
9
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { numberToStringWithDecimals } from "./index";
|
|
3
|
+
describe("numberToStringWithDecimals", () => {
|
|
4
|
+
it("should format number with two decimals and thousand separators", () => {
|
|
5
|
+
expect(numberToStringWithDecimals(1234.56)).toBe("1.234,56");
|
|
6
|
+
});
|
|
7
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leaderty/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "tsc -p tsconfig.json"
|
|
13
|
+
"build": "tsc -p tsconfig.json",
|
|
14
|
+
"test": "vitest run"
|
|
14
15
|
}
|
|
15
16
|
}
|