@leaderty/utils 2.1.0 → 3.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/README.md +6 -5
- package/dist/format.d.ts +5 -4
- package/dist/format.js +16 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,8 @@ Formats a date as `dd/mm/aaaa`, or `dd/mm/aaaa hh:mm` (24-hour) with `time: true
|
|
|
44
44
|
|
|
45
45
|
**Behavior:**
|
|
46
46
|
- `'aaaa-mm-dd'` strings, and date-time strings without a time zone (`'2026-10-01T00:00:00'`), are read as written. `'2026-10-11'` gives `11/10/2026`, even though `new Date('2026-10-11')` is midnight UTC, which is still October 10 in Argentina.
|
|
47
|
-
- `Date` objects
|
|
47
|
+
- `Date` objects are read in the system time zone, as their own getters do: `new Date(2026, 10, 1)` is November 1 in any system time zone.
|
|
48
|
+
- ISO strings with a time zone (`Z` or `±hh:mm`, as in `'2026-10-22T22:05:36.036Z'`) are shown in `America/Argentina/Buenos_Aires` time (UTC-3, no daylight saving time).
|
|
48
49
|
- Any other string gives `'-'` (`'11/10/2026'`, `'2026-10'`, `'Oct 11 2026'`): `new Date()` would read it in the system time zone or guess the day/month order.
|
|
49
50
|
- Also returns `'-'` for `null`, `undefined`, invalid dates and impossible dates such as `'2026-02-30'`.
|
|
50
51
|
|
|
@@ -58,14 +59,14 @@ Formats a date as `dd/mm/aaaa`, or `dd/mm/aaaa hh:mm` (24-hour) with `time: true
|
|
|
58
59
|
```typescript
|
|
59
60
|
dateToShort('2026-10-11') // "11/10/2026"
|
|
60
61
|
dateToShort('2026-10-01T00:00:00') // "01/10/2026"
|
|
61
|
-
dateToShort(new Date(
|
|
62
|
+
dateToShort(new Date(2026, 9, 22)) // "22/10/2026"
|
|
62
63
|
dateToShort('2026-10-22T02:05:36Z', { time: true }) // "21/10/2026 23:05"
|
|
63
64
|
dateToShort('11/10/2026') // "-"
|
|
64
65
|
```
|
|
65
66
|
|
|
66
67
|
### `dateToYMD(value)`
|
|
67
68
|
|
|
68
|
-
Formats a date as `aaaa-mm-dd`, the value of an `<input type="date">`. Reads `value` like `dateToShort`, so `'2026-10-11'` stays the 11th and a `Date` is taken in
|
|
69
|
+
Formats a date as `aaaa-mm-dd`, the value of an `<input type="date">`. Reads `value` like `dateToShort`, so `'2026-10-11'` stays the 11th and a `Date` is taken in the system time zone.
|
|
69
70
|
|
|
70
71
|
**Parameters:**
|
|
71
72
|
- `value` - `Date | string | null | undefined`
|
|
@@ -75,7 +76,7 @@ Formats a date as `aaaa-mm-dd`, the value of an `<input type="date">`. Reads `va
|
|
|
75
76
|
**Examples:**
|
|
76
77
|
```typescript
|
|
77
78
|
dateToYMD('2026-10-11') // "2026-10-11"
|
|
78
|
-
dateToYMD(new Date(
|
|
79
|
+
dateToYMD(new Date(2026, 9, 21)) // "2026-10-21"
|
|
79
80
|
dateToYMD('11/10/2026') // ""
|
|
80
81
|
```
|
|
81
82
|
|
|
@@ -97,7 +98,7 @@ dateToMonthYearLong('2026-10-01') // "octubre de 2026" (not September)
|
|
|
97
98
|
|
|
98
99
|
### `numberToDecimalString(numero)`
|
|
99
100
|
|
|
100
|
-
Formats a number with two decimals and thousands separators. Rounds
|
|
101
|
+
Formats a number with two decimals and thousands separators. Rounds like `numberToMoney(n, { decimals: 2 })`, so `1.005` gives `1,01`. Formerly `numberToStringWithDecimals`, which stays as a deprecated alias.
|
|
101
102
|
|
|
102
103
|
**Parameters:**
|
|
103
104
|
- `numero` - `number`
|
package/dist/format.d.ts
CHANGED
|
@@ -38,8 +38,9 @@ export declare function numberToMoney(amount: number | null | undefined, options
|
|
|
38
38
|
* - `'aaaa-mm-dd'` strings, and date-time strings without a time zone (`'2026-10-01T00:00:00'`),
|
|
39
39
|
* are read as written: `'2026-10-11'` is the 11th, never the 10th
|
|
40
40
|
* (`new Date('2026-10-11')` is midnight UTC, which is still the 10th in Argentina).
|
|
41
|
-
* - `Date` objects
|
|
42
|
-
*
|
|
41
|
+
* - `Date` objects are read in the system time zone, as their own getters do: `new Date(2026, 10, 1)` is
|
|
42
|
+
* November 1 in any system time zone.
|
|
43
|
+
* - ISO strings with a time zone (`'2026-10-22T22:05:36.036Z'`) are shown in `America/Argentina/Buenos_Aires` time.
|
|
43
44
|
* - Any other string (`'11/10/2026'`, `'2026-10'`, `'Oct 11 2026'`) gives `'-'`: the engine would parse it
|
|
44
45
|
* in the system time zone, or guess the day/month order.
|
|
45
46
|
*
|
|
@@ -49,7 +50,7 @@ export declare function numberToMoney(amount: number | null | undefined, options
|
|
|
49
50
|
*
|
|
50
51
|
* @example
|
|
51
52
|
* dateToShort('2026-10-11') // "11/10/2026"
|
|
52
|
-
* dateToShort(new Date(
|
|
53
|
+
* dateToShort(new Date(2026, 9, 22)) // "22/10/2026"
|
|
53
54
|
* dateToShort('2026-10-22T02:05:36Z', { time: true }) // "21/10/2026 23:05"
|
|
54
55
|
*/
|
|
55
56
|
export declare function dateToShort(value: Date | string | null | undefined, options?: DateToShortOptions): string;
|
|
@@ -62,7 +63,7 @@ export declare function dateToShort(value: Date | string | null | undefined, opt
|
|
|
62
63
|
* @example
|
|
63
64
|
* dateToYMD('2026-10-11') // "2026-10-11"
|
|
64
65
|
* dateToYMD('2026-10-11T00:00:00') // "2026-10-11"
|
|
65
|
-
* dateToYMD(new Date(
|
|
66
|
+
* dateToYMD(new Date(2026, 9, 21)) // "2026-10-21"
|
|
66
67
|
* dateToYMD('11/10/2026') // ""
|
|
67
68
|
*/
|
|
68
69
|
export declare function dateToYMD(value: Date | string | null | undefined): string;
|
package/dist/format.js
CHANGED
|
@@ -59,8 +59,9 @@ export function numberToMoney(amount, options = {}) {
|
|
|
59
59
|
* - `'aaaa-mm-dd'` strings, and date-time strings without a time zone (`'2026-10-01T00:00:00'`),
|
|
60
60
|
* are read as written: `'2026-10-11'` is the 11th, never the 10th
|
|
61
61
|
* (`new Date('2026-10-11')` is midnight UTC, which is still the 10th in Argentina).
|
|
62
|
-
* - `Date` objects
|
|
63
|
-
*
|
|
62
|
+
* - `Date` objects are read in the system time zone, as their own getters do: `new Date(2026, 10, 1)` is
|
|
63
|
+
* November 1 in any system time zone.
|
|
64
|
+
* - ISO strings with a time zone (`'2026-10-22T22:05:36.036Z'`) are shown in `America/Argentina/Buenos_Aires` time.
|
|
64
65
|
* - Any other string (`'11/10/2026'`, `'2026-10'`, `'Oct 11 2026'`) gives `'-'`: the engine would parse it
|
|
65
66
|
* in the system time zone, or guess the day/month order.
|
|
66
67
|
*
|
|
@@ -70,7 +71,7 @@ export function numberToMoney(amount, options = {}) {
|
|
|
70
71
|
*
|
|
71
72
|
* @example
|
|
72
73
|
* dateToShort('2026-10-11') // "11/10/2026"
|
|
73
|
-
* dateToShort(new Date(
|
|
74
|
+
* dateToShort(new Date(2026, 9, 22)) // "22/10/2026"
|
|
74
75
|
* dateToShort('2026-10-22T02:05:36Z', { time: true }) // "21/10/2026 23:05"
|
|
75
76
|
*/
|
|
76
77
|
export function dateToShort(value, options = {}) {
|
|
@@ -89,7 +90,7 @@ export function dateToShort(value, options = {}) {
|
|
|
89
90
|
* @example
|
|
90
91
|
* dateToYMD('2026-10-11') // "2026-10-11"
|
|
91
92
|
* dateToYMD('2026-10-11T00:00:00') // "2026-10-11"
|
|
92
|
-
* dateToYMD(new Date(
|
|
93
|
+
* dateToYMD(new Date(2026, 9, 21)) // "2026-10-21"
|
|
93
94
|
* dateToYMD('11/10/2026') // ""
|
|
94
95
|
*/
|
|
95
96
|
export function dateToYMD(value) {
|
|
@@ -120,6 +121,17 @@ export function dateToMonthYearLong(value) {
|
|
|
120
121
|
function toDateParts(value) {
|
|
121
122
|
if (value === null || value === undefined)
|
|
122
123
|
return null;
|
|
124
|
+
if (value instanceof Date) {
|
|
125
|
+
if (Number.isNaN(value.getTime()))
|
|
126
|
+
return null;
|
|
127
|
+
return {
|
|
128
|
+
year: value.getFullYear(),
|
|
129
|
+
month: value.getMonth() + 1,
|
|
130
|
+
day: value.getDate(),
|
|
131
|
+
hours: value.getHours(),
|
|
132
|
+
minutes: value.getMinutes(),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
123
135
|
if (typeof value === 'string') {
|
|
124
136
|
const match = WALL_CLOCK_PATTERN.exec(value);
|
|
125
137
|
if (match) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Formatea un número a una cadena con dos decimales y separadores de miles.
|
|
3
|
+
* Redondea igual que `numberToMoney(numero, { decimals: 2 })`: `1.005` da `1,01`.
|
|
3
4
|
*/
|
|
4
5
|
export declare function numberToDecimalString(numero: number): string;
|
|
5
6
|
/** @deprecated Renamed to {@link numberToDecimalString}. */
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { numberToMoney } from './format.js';
|
|
1
2
|
/**
|
|
2
3
|
* Formatea un número a una cadena con dos decimales y separadores de miles.
|
|
4
|
+
* Redondea igual que `numberToMoney(numero, { decimals: 2 })`: `1.005` da `1,01`.
|
|
3
5
|
*/
|
|
4
6
|
export function numberToDecimalString(numero) {
|
|
5
|
-
|
|
6
|
-
const [integerPart, decimalPart] = formatted.split('.');
|
|
7
|
-
const withThousandsSeparator = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
8
|
-
return `${withThousandsSeparator},${decimalPart}`;
|
|
7
|
+
return numberToMoney(numero, { decimals: 2 });
|
|
9
8
|
}
|
|
10
9
|
/** @deprecated Renamed to {@link numberToDecimalString}. */
|
|
11
10
|
export const numberToStringWithDecimals = numberToDecimalString;
|