@leaderty/utils 3.2.0 → 3.3.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 +20 -1
- package/dist/format.d.ts +13 -0
- package/dist/format.js +16 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @leaderty/utils
|
|
2
2
|
|
|
3
|
-
Argentine number and date formatting. Every
|
|
3
|
+
Argentine number and date formatting. Every formatter returns the same output on any system: none of them uses `Intl`, `toLocaleString()` or the system time zone, so a WebView in English still shows `350.000` and `dd/mm/aaaa`. `parseLocalDate` is the exception: it returns a `Date` at local midnight.
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
6
|
|
|
@@ -121,6 +121,25 @@ dateToMonthYearLong('2026-10-11') // "octubre de 2026"
|
|
|
121
121
|
dateToMonthYearLong('2026-10-01') // "octubre de 2026" (not September)
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
### `parseLocalDate(value)`
|
|
125
|
+
|
|
126
|
+
Lee una fecha del API como fecha local. `new Date('aaaa-mm-dd')` es medianoche UTC: en Argentina es el día anterior, y el día 1 cae en el mes anterior.
|
|
127
|
+
|
|
128
|
+
**Comportamiento:**
|
|
129
|
+
- `'aaaa-mm-dd'` da la medianoche de ese día en la zona horaria del sistema.
|
|
130
|
+
- Cualquier otro string se lee con `new Date(value)`: `'aaaa-mm-ddThh:mm:ss'` (sin zona, ya local) y las fechas con zona quedan igual.
|
|
131
|
+
|
|
132
|
+
**Parámetros:**
|
|
133
|
+
- `value` - `string`
|
|
134
|
+
|
|
135
|
+
**Devuelve:** `Date`
|
|
136
|
+
|
|
137
|
+
**Ejemplos:**
|
|
138
|
+
```typescript
|
|
139
|
+
parseLocalDate('2026-10-01') // 1 de octubre, 00:00 locales (no el 30/9)
|
|
140
|
+
parseLocalDate('2026-10-22T22:05:36Z') // igual que new Date('2026-10-22T22:05:36Z')
|
|
141
|
+
```
|
|
142
|
+
|
|
124
143
|
### `numberToDecimalString(numero)`
|
|
125
144
|
|
|
126
145
|
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.
|
package/dist/format.d.ts
CHANGED
|
@@ -93,3 +93,16 @@ export declare function dateToYMD(value: Date | string | null | undefined): stri
|
|
|
93
93
|
* dateToMonthYearLong(new Date(2027, 0, 11)) // "enero de 2027"
|
|
94
94
|
*/
|
|
95
95
|
export declare function dateToMonthYearLong(value: Date | string | null | undefined): string;
|
|
96
|
+
/**
|
|
97
|
+
* Reads an API date as a local date. `new Date('aaaa-mm-dd')` is midnight UTC: in Argentina that is
|
|
98
|
+
* the previous day, and the 1st falls in the previous month.
|
|
99
|
+
* Only that format changes; `'aaaa-mm-ddThh:mm:ss'` (no zone, already local) and zoned dates are read by `new Date`.
|
|
100
|
+
*
|
|
101
|
+
* @param value - Date string from the API
|
|
102
|
+
* @returns Local midnight of that day for `'aaaa-mm-dd'`, otherwise `new Date(value)`
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* parseLocalDate('2026-10-01') // October 1, 00:00 in the system time zone
|
|
106
|
+
* parseLocalDate('2026-10-22T22:05:36Z') // same as new Date('2026-10-22T22:05:36Z')
|
|
107
|
+
*/
|
|
108
|
+
export declare function parseLocalDate(value: string): Date;
|
package/dist/format.js
CHANGED
|
@@ -139,6 +139,22 @@ export function dateToMonthYearLong(value) {
|
|
|
139
139
|
return PLACEHOLDER;
|
|
140
140
|
return `${MONTH_NAMES[parts.month - 1]} de ${parts.year}`;
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Reads an API date as a local date. `new Date('aaaa-mm-dd')` is midnight UTC: in Argentina that is
|
|
144
|
+
* the previous day, and the 1st falls in the previous month.
|
|
145
|
+
* Only that format changes; `'aaaa-mm-ddThh:mm:ss'` (no zone, already local) and zoned dates are read by `new Date`.
|
|
146
|
+
*
|
|
147
|
+
* @param value - Date string from the API
|
|
148
|
+
* @returns Local midnight of that day for `'aaaa-mm-dd'`, otherwise `new Date(value)`
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* parseLocalDate('2026-10-01') // October 1, 00:00 in the system time zone
|
|
152
|
+
* parseLocalDate('2026-10-22T22:05:36Z') // same as new Date('2026-10-22T22:05:36Z')
|
|
153
|
+
*/
|
|
154
|
+
export function parseLocalDate(value) {
|
|
155
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
156
|
+
return match ? new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3])) : new Date(value);
|
|
157
|
+
}
|
|
142
158
|
function toDateParts(value) {
|
|
143
159
|
if (value === null || value === undefined)
|
|
144
160
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
export declare function numberToDecimalString(numero: number): string;
|
|
6
6
|
/** @deprecated Renamed to {@link numberToDecimalString}. */
|
|
7
7
|
export declare const numberToStringWithDecimals: typeof numberToDecimalString;
|
|
8
|
-
export { numberToMoney, moneyToNumber, dateToShort, dateToYMD, dateToMonthYearLong, type Currency, type NumberToMoneyOptions, type DateToShortOptions, } from './format.js';
|
|
8
|
+
export { numberToMoney, moneyToNumber, dateToShort, dateToYMD, dateToMonthYearLong, parseLocalDate, type Currency, type NumberToMoneyOptions, type DateToShortOptions, } from './format.js';
|
|
9
9
|
export { isAlias, isCbu } from './bank.js';
|
package/dist/index.js
CHANGED
|
@@ -8,5 +8,5 @@ export function numberToDecimalString(numero) {
|
|
|
8
8
|
}
|
|
9
9
|
/** @deprecated Renamed to {@link numberToDecimalString}. */
|
|
10
10
|
export const numberToStringWithDecimals = numberToDecimalString;
|
|
11
|
-
export { numberToMoney, moneyToNumber, dateToShort, dateToYMD, dateToMonthYearLong, } from './format.js';
|
|
11
|
+
export { numberToMoney, moneyToNumber, dateToShort, dateToYMD, dateToMonthYearLong, parseLocalDate, } from './format.js';
|
|
12
12
|
export { isAlias, isCbu } from './bank.js';
|