@leaderty/utils 3.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @leaderty/utils
2
2
 
3
- Argentine number and date formatting. Every function 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`.
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.
@@ -135,6 +154,38 @@ Formats a number with two decimals and thousands separators. Rounds like `number
135
154
  numberToDecimalString(1234.56) // "1.234,56"
136
155
  ```
137
156
 
157
+ ### `isCbu(value)`
158
+
159
+ Indica si `value` es un CBU o una CVU válido: 22 dígitos con sus dos dígitos verificadores, calculados con la clave del BCRA (Com. "A" 8303). No dice si la cuenta existe.
160
+
161
+ **Parámetros:**
162
+ - `value` - `string`, solo dígitos (sin espacios ni guiones)
163
+
164
+ **Devuelve:** `boolean`
165
+
166
+ **Ejemplos:**
167
+ ```typescript
168
+ isCbu('2850590940090418135201') // true
169
+ isCbu('2850590940090418135202') // false: verificador de cuenta incorrecto
170
+ isCbu('28505909 40090418135201') // false
171
+ ```
172
+
173
+ ### `isAlias(value)`
174
+
175
+ Indica si `value` tiene la forma de un alias de CBU o CVU: de 6 a 20 caracteres entre letras sin ñ ni acentos, números, punto y guion. No dice si el alias existe.
176
+
177
+ **Parámetros:**
178
+ - `value` - `string`
179
+
180
+ **Devuelve:** `boolean`
181
+
182
+ **Ejemplos:**
183
+ ```typescript
184
+ isAlias('casa.sol.azul') // true
185
+ isAlias('año.casa') // false
186
+ isAlias('casa') // false: menos de 6 caracteres
187
+ ```
188
+
138
189
  ## Types
139
190
 
140
191
  `Currency`, `NumberToMoneyOptions` and `DateToShortOptions` are exported for consumers.
package/dist/bank.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Indica si `value` es un CBU o una CVU: 22 dígitos con sus dos dígitos verificadores
3
+ * (el de banco y sucursal, y el de cuenta).
4
+ */
5
+ export declare function isCbu(value: string): boolean;
6
+ /**
7
+ * Indica si `value` puede ser un alias de CBU o CVU: de 6 a 20 caracteres entre letras sin ñ ni acentos,
8
+ * números, punto y guion. No dice si el alias existe.
9
+ */
10
+ export declare function isAlias(value: string): boolean;
package/dist/bank.js ADDED
@@ -0,0 +1,27 @@
1
+ // Clave de verificación del BCRA (Com. "A" 8303, puntos 1.1 y 2.3): pesos 7139 repetidos, alineados a la
2
+ // derecha (de derecha a izquierda, 3 1 7 9); el verificador completa la suma hasta la decena siguiente.
3
+ const WEIGHTS = [3, 1, 7, 9];
4
+ function checkDigit(digits) {
5
+ let sum = 0;
6
+ for (let i = 0; i < digits.length; i++) {
7
+ sum += Number(digits[digits.length - 1 - i]) * WEIGHTS[i % WEIGHTS.length];
8
+ }
9
+ return (10 - (sum % 10)) % 10;
10
+ }
11
+ /**
12
+ * Indica si `value` es un CBU o una CVU: 22 dígitos con sus dos dígitos verificadores
13
+ * (el de banco y sucursal, y el de cuenta).
14
+ */
15
+ export function isCbu(value) {
16
+ if (!/^\d{22}$/.test(value))
17
+ return false;
18
+ return (checkDigit(value.slice(0, 7)) === Number(value[7]) &&
19
+ checkDigit(value.slice(8, 21)) === Number(value[21]));
20
+ }
21
+ /**
22
+ * Indica si `value` puede ser un alias de CBU o CVU: de 6 a 20 caracteres entre letras sin ñ ni acentos,
23
+ * números, punto y guion. No dice si el alias existe.
24
+ */
25
+ export function isAlias(value) {
26
+ return /^[A-Za-z0-9.-]{6,20}$/.test(value);
27
+ }
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,4 +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
+ export { isAlias, isCbu } from './bank.js';
package/dist/index.js CHANGED
@@ -8,4 +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
+ export { isAlias, isCbu } from './bank.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leaderty/utils",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",