@leaderty/utils 1.0.1 → 2.0.1

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 CHANGED
@@ -1 +1,4 @@
1
- export declare function hello(name: string): string;
1
+ /**
2
+ * Formatea un número a una cadena con dos decimales y separadores de miles.
3
+ */
4
+ export declare function numberToStringWithDecimals(numero: number): string;
package/dist/index.js CHANGED
@@ -1,3 +1,9 @@
1
- export function hello(name) {
2
- return `Hola ${name}`;
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,7 @@
1
1
  {
2
2
  "name": "@leaderty/utils",
3
- "version": "1.0.1",
3
+ "version": "2.0.1",
4
+ "type": "module",
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
6
7
  "files": [
@@ -10,6 +11,7 @@
10
11
  "access": "public"
11
12
  },
12
13
  "scripts": {
13
- "build": "tsc -p tsconfig.json"
14
+ "build": "tsc -p tsconfig.json",
15
+ "test": "vitest run"
14
16
  }
15
17
  }