@attrx/role-morphic 0.1.0 → 0.2.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/cast.d.ts ADDED
@@ -0,0 +1,678 @@
1
+ import { A as AreaUnit, L as LengthUnit, M as MassUnit, V as VolumeUnit, S as SpeedUnit, E as EnergyUnit, P as PowerUnit, b as PressureUnit, F as FrequencyUnit, a as AngleUnit, T as TimeUnit, D as DigitalUnit } from './constants-BZdBwuvJ.js';
2
+ import { T as TemperatureUnit, r as ColorVariant, o as DateVariant } from './types-mbeS1e-k.js';
3
+
4
+ /**
5
+ * Area Role - Cast Pillar
6
+ *
7
+ * Normaliza input sujo para número tipado.
8
+ * Detecta unidades em strings e converte se necessário.
9
+ *
10
+ * @example
11
+ * import { castArea, castAreaStrict, detectAreaUnit } from '@attrx/role-morphic/area/cast';
12
+ *
13
+ * castArea('100 ha', 'hectare'); // 100
14
+ * castArea('100 ha', 'acre'); // 247.105... (converte)
15
+ * castAreaStrict('100 ha'); // 100 (não converte)
16
+ * detectAreaUnit('100 hectares'); // 'hectare'
17
+ */
18
+
19
+ type Result$f<T> = {
20
+ ok: true;
21
+ value: T;
22
+ } | {
23
+ ok: false;
24
+ error: string;
25
+ };
26
+ /**
27
+ * Faz cast de input para número, detectando e convertendo unidade se presente
28
+ *
29
+ * @param input - Valor de entrada (number, string, etc)
30
+ * @param targetVariant - Unidade alvo para conversão
31
+ * @returns Número ou null se não puder converter
32
+ *
33
+ * @example
34
+ * castArea(100, 'hectare'); // 100
35
+ * castArea('100', 'hectare'); // 100
36
+ * castArea('100 ha', 'hectare'); // 100
37
+ * castArea('100 ha', 'acre'); // 247.105... (converte)
38
+ * castArea('100 acres', 'hectare'); // 40.4686... (converte)
39
+ * castArea('invalid', 'hectare'); // null
40
+ */
41
+ declare function castArea(input: unknown, targetVariant?: AreaUnit): number | null;
42
+ /**
43
+ * Versão safe de castArea que retorna Result
44
+ */
45
+ declare function tryCastArea(input: unknown, targetVariant?: AreaUnit): Result$f<number>;
46
+
47
+ /**
48
+ * Length Role - Cast Pillar
49
+ *
50
+ * Normaliza input sujo para número tipado.
51
+ * Detecta unidades em strings e converte se necessário.
52
+ *
53
+ * @example
54
+ * import { castLength, castLengthStrict, detectLengthUnit } from '@attrx/role-morphic/length/cast';
55
+ *
56
+ * castLength('100 km', 'kilometer'); // 100
57
+ * castLength('100 km', 'mile'); // 62.1371... (converte)
58
+ * castLengthStrict('100 km'); // 100 (não converte)
59
+ * detectLengthUnit('100 meters'); // 'meter'
60
+ */
61
+
62
+ type Result$e<T> = {
63
+ ok: true;
64
+ value: T;
65
+ } | {
66
+ ok: false;
67
+ error: string;
68
+ };
69
+ /**
70
+ * Faz cast de input para número, detectando e convertendo unidade se presente
71
+ *
72
+ * @param input - Valor de entrada (number, string, etc)
73
+ * @param targetVariant - Unidade alvo para conversão
74
+ * @returns Número ou null se não puder converter
75
+ *
76
+ * @example
77
+ * castLength(100, 'meter'); // 100
78
+ * castLength('100', 'meter'); // 100
79
+ * castLength('100 km', 'kilometer'); // 100
80
+ * castLength('100 km', 'mile'); // 62.1371... (converte)
81
+ * castLength('1 mile', 'kilometer'); // 1.609344 (converte)
82
+ * castLength('invalid', 'meter'); // null
83
+ */
84
+ declare function castLength(input: unknown, targetVariant?: LengthUnit): number | null;
85
+ /**
86
+ * Versão safe de castLength que retorna Result
87
+ */
88
+ declare function tryCastLength(input: unknown, targetVariant?: LengthUnit): Result$e<number>;
89
+
90
+ /**
91
+ * Mass Role - Cast Pillar
92
+ *
93
+ * Normaliza input sujo para número tipado.
94
+ * Detecta unidades em strings e converte se necessário.
95
+ *
96
+ * @example
97
+ * import { castMass, castMassStrict, detectMassUnit } from '@attrx/role-morphic/mass/cast';
98
+ *
99
+ * castMass('100 kg', 'kilogram'); // 100
100
+ * castMass('100 lb', 'kilogram'); // 45.359237 (converte)
101
+ * castMassStrict('100 kg'); // 100 (não converte)
102
+ * detectMassUnit('100 pounds'); // 'pound'
103
+ */
104
+
105
+ type Result$d<T> = {
106
+ ok: true;
107
+ value: T;
108
+ } | {
109
+ ok: false;
110
+ error: string;
111
+ };
112
+ /**
113
+ * Faz cast de input para número, detectando e convertendo unidade se presente
114
+ *
115
+ * @param input - Valor de entrada (number, string, etc)
116
+ * @param targetVariant - Unidade alvo para conversão
117
+ * @returns Número ou null se não puder converter
118
+ *
119
+ * @example
120
+ * castMass(100, 'kilogram'); // 100
121
+ * castMass('100', 'kilogram'); // 100
122
+ * castMass('100 kg', 'kilogram'); // 100
123
+ * castMass('100 lb', 'kilogram'); // 45.359237 (converte)
124
+ * castMass('100 pounds', 'gram'); // 45359.237 (converte)
125
+ * castMass('invalid', 'kilogram'); // null
126
+ */
127
+ declare function castMass(input: unknown, targetVariant?: MassUnit): number | null;
128
+ /**
129
+ * Versão safe de castMass que retorna Result
130
+ */
131
+ declare function tryCastMass(input: unknown, targetVariant?: MassUnit): Result$d<number>;
132
+
133
+ /**
134
+ * Temperature Role - Cast Pillar
135
+ *
136
+ * Normaliza input sujo para número tipado.
137
+ * Detecta unidades em strings e converte se necessário.
138
+ *
139
+ * @example
140
+ * import { castTemperature, castTemperatureStrict, detectTemperatureUnit } from '@attrx/role-morphic/temperature/cast';
141
+ *
142
+ * castTemperature('100 °C', 'celsius'); // 100
143
+ * castTemperature('32 °F', 'celsius'); // 0 (converte)
144
+ * castTemperatureStrict('100 °C'); // 100 (não converte)
145
+ * detectTemperatureUnit('100 degrees F'); // 'fahrenheit'
146
+ */
147
+
148
+ type Result$c<T> = {
149
+ ok: true;
150
+ value: T;
151
+ } | {
152
+ ok: false;
153
+ error: string;
154
+ };
155
+ /**
156
+ * Faz cast de input para número, detectando e convertendo unidade se presente
157
+ *
158
+ * @param input - Valor de entrada (number, string, etc)
159
+ * @param targetVariant - Unidade alvo para conversão
160
+ * @returns Número ou null se não puder converter
161
+ *
162
+ * @example
163
+ * castTemperature(100, 'celsius'); // 100
164
+ * castTemperature('100', 'celsius'); // 100
165
+ * castTemperature('100 °C', 'celsius'); // 100
166
+ * castTemperature('32 °F', 'celsius'); // 0 (converte F → C)
167
+ * castTemperature('273.15 K', 'celsius'); // 0 (converte K → C)
168
+ * castTemperature('invalid', 'celsius'); // null
169
+ */
170
+ declare function castTemperature(input: unknown, targetVariant?: TemperatureUnit): number | null;
171
+ /**
172
+ * Versão safe de castTemperature que retorna Result
173
+ */
174
+ declare function tryCastTemperature(input: unknown, targetVariant?: TemperatureUnit): Result$c<number>;
175
+
176
+ /**
177
+ * Volume Role - Cast Pillar
178
+ *
179
+ * Normaliza input sujo para número tipado.
180
+ * Detecta unidades em strings e converte se necessário.
181
+ *
182
+ * @example
183
+ * import { castVolume, castVolumeStrict, detectVolumeUnit } from '@attrx/role-morphic/volume/cast';
184
+ *
185
+ * castVolume('500 ml', 'liter'); // 0.5 (converte)
186
+ * castVolume('1 gal', 'liter'); // 3.785411784 (converte)
187
+ * castVolumeStrict('500 ml'); // 500 (não converte)
188
+ * detectVolumeUnit('2 gallons'); // 'gallon_us'
189
+ */
190
+
191
+ type Result$b<T> = {
192
+ ok: true;
193
+ value: T;
194
+ } | {
195
+ ok: false;
196
+ error: string;
197
+ };
198
+ /**
199
+ * Faz cast de input para número, detectando e convertendo unidade se presente
200
+ *
201
+ * @param input - Valor de entrada (number, string, etc)
202
+ * @param targetVariant - Unidade alvo para conversão
203
+ * @returns Número ou null se não puder converter
204
+ *
205
+ * @example
206
+ * castVolume(100, 'liter'); // 100
207
+ * castVolume('100', 'liter'); // 100
208
+ * castVolume('500 ml', 'liter'); // 0.5 (converte)
209
+ * castVolume('1 gal', 'liter'); // 3.785411784 (converte)
210
+ * castVolume('invalid', 'liter'); // null
211
+ */
212
+ declare function castVolume(input: unknown, targetVariant?: VolumeUnit): number | null;
213
+ /**
214
+ * Versão safe de castVolume que retorna Result
215
+ */
216
+ declare function tryCastVolume(input: unknown, targetVariant?: VolumeUnit): Result$b<number>;
217
+
218
+ /**
219
+ * Speed Role - Cast Pillar
220
+ *
221
+ * Normaliza input sujo para número tipado.
222
+ * Detecta unidades em strings e converte se necessário.
223
+ *
224
+ * @example
225
+ * import { castSpeed, castSpeedStrict, detectSpeedUnit } from '@attrx/role-morphic/speed/cast';
226
+ *
227
+ * castSpeed('100 km/h', 'meter_per_second'); // 27.7778... (converte)
228
+ * castSpeed('60 mph', 'kilometer_per_hour'); // 96.5606... (converte)
229
+ * castSpeedStrict('100 km/h'); // 100 (não converte)
230
+ * detectSpeedUnit('60 miles per hour'); // 'mile_per_hour'
231
+ */
232
+
233
+ type Result$a<T> = {
234
+ ok: true;
235
+ value: T;
236
+ } | {
237
+ ok: false;
238
+ error: string;
239
+ };
240
+ /**
241
+ * Faz cast de input para número, detectando e convertendo unidade se presente
242
+ *
243
+ * @param input - Valor de entrada (number, string, etc)
244
+ * @param targetVariant - Unidade alvo para conversão
245
+ * @returns Número ou null se não puder converter
246
+ *
247
+ * @example
248
+ * castSpeed(100, 'meter_per_second'); // 100
249
+ * castSpeed('100', 'meter_per_second'); // 100
250
+ * castSpeed('100 km/h', 'meter_per_second'); // 27.7778... (converte)
251
+ * castSpeed('60 mph', 'kilometer_per_hour'); // 96.5606... (converte)
252
+ * castSpeed('invalid', 'meter_per_second'); // null
253
+ */
254
+ declare function castSpeed(input: unknown, targetVariant?: SpeedUnit): number | null;
255
+ /**
256
+ * Versão safe de castSpeed que retorna Result
257
+ */
258
+ declare function tryCastSpeed(input: unknown, targetVariant?: SpeedUnit): Result$a<number>;
259
+
260
+ /**
261
+ * Energy Role - Cast Pillar
262
+ *
263
+ * Normaliza input sujo para número tipado.
264
+ * Detecta unidades em strings e converte se necessário.
265
+ *
266
+ * @example
267
+ * import { castEnergy, castEnergyStrict, detectEnergyUnit } from '@attrx/role-morphic/energy/cast';
268
+ *
269
+ * castEnergy('100 kWh', 'kilowatt_hour'); // 100
270
+ * castEnergy('100 BTU', 'joule'); // 105505.59 (converte)
271
+ * castEnergyStrict('100 kWh'); // 100 (não converte)
272
+ * detectEnergyUnit('100 kilocalories'); // 'kilocalorie'
273
+ */
274
+
275
+ type Result$9<T> = {
276
+ ok: true;
277
+ value: T;
278
+ } | {
279
+ ok: false;
280
+ error: string;
281
+ };
282
+ /**
283
+ * Faz cast de input para número, detectando e convertendo unidade se presente
284
+ *
285
+ * @param input - Valor de entrada (number, string, etc)
286
+ * @param targetVariant - Unidade alvo para conversão
287
+ * @returns Número ou null se não puder converter
288
+ *
289
+ * @example
290
+ * castEnergy(100, 'joule'); // 100
291
+ * castEnergy('100', 'joule'); // 100
292
+ * castEnergy('100 kWh', 'kilowatt_hour'); // 100
293
+ * castEnergy('100 BTU', 'joule'); // 105505.59 (converte)
294
+ * castEnergy('1 kcal', 'kilojoule'); // 4.1868 (converte)
295
+ * castEnergy('invalid', 'joule'); // null
296
+ */
297
+ declare function castEnergy(input: unknown, targetVariant?: EnergyUnit): number | null;
298
+ /**
299
+ * Versão safe de castEnergy que retorna Result
300
+ */
301
+ declare function tryCastEnergy(input: unknown, targetVariant?: EnergyUnit): Result$9<number>;
302
+
303
+ /**
304
+ * Power Role - Cast Pillar
305
+ *
306
+ * Normaliza input sujo para número, com detecção automática de unidade.
307
+ *
308
+ * @example
309
+ * import { castPower, castPowerStrict, detectPowerUnit } from '@attrx/role-morphic/power/cast';
310
+ *
311
+ * castPower('100 kW'); // 100000 (converted to watts)
312
+ * castPower('100 kW', 'kilowatt'); // 100 (kept as kilowatts)
313
+ * castPowerStrict('100'); // 100 (no conversion)
314
+ * detectPowerUnit('100 hp'); // 'horsepower_mechanical'
315
+ */
316
+
317
+ type Result$8<T> = {
318
+ ok: true;
319
+ value: T;
320
+ } | {
321
+ ok: false;
322
+ error: string;
323
+ };
324
+ /**
325
+ * Faz cast de input para número, com conversão opcional para unidade alvo
326
+ *
327
+ * @param input - Valor de entrada (number, string, etc)
328
+ * @param targetVariant - Unidade alvo (default: watt)
329
+ * @returns Número ou null se não puder converter
330
+ *
331
+ * @example
332
+ * castPower('100 kW'); // 100000 (watts)
333
+ * castPower('100 kW', 'kilowatt'); // 100
334
+ * castPower('100'); // 100
335
+ * castPower(100); // 100
336
+ * castPower('invalid'); // null
337
+ */
338
+ declare function castPower(input: unknown, targetVariant?: PowerUnit): number | null;
339
+ /**
340
+ * Versão safe de castPower que retorna Result
341
+ */
342
+ declare function tryCastPower(input: unknown, targetVariant?: PowerUnit): Result$8<number>;
343
+
344
+ /**
345
+ * Pressure Role - Cast Pillar
346
+ *
347
+ * Normaliza input sujo para número, com detecção automática de unidade.
348
+ *
349
+ * @example
350
+ * import { castPressure, castPressureStrict, detectPressureUnit } from '@attrx/role-morphic/pressure/cast';
351
+ *
352
+ * castPressure('1 bar'); // 100000 (converted to pascals)
353
+ * castPressure('1 bar', 'bar'); // 1 (kept as bar)
354
+ * castPressureStrict('100'); // 100 (no conversion)
355
+ * detectPressureUnit('14.7 psi'); // 'psi'
356
+ */
357
+
358
+ type Result$7<T> = {
359
+ ok: true;
360
+ value: T;
361
+ } | {
362
+ ok: false;
363
+ error: string;
364
+ };
365
+ /**
366
+ * Faz cast de input para número, com conversão opcional para unidade alvo
367
+ *
368
+ * @param input - Valor de entrada (number, string, etc)
369
+ * @param targetVariant - Unidade alvo (default: pascal)
370
+ * @returns Número ou null se não puder converter
371
+ *
372
+ * @example
373
+ * castPressure('1 bar'); // 100000 (pascals)
374
+ * castPressure('1 bar', 'bar'); // 1
375
+ * castPressure('100'); // 100
376
+ * castPressure(100); // 100
377
+ * castPressure('invalid'); // null
378
+ */
379
+ declare function castPressure(input: unknown, targetVariant?: PressureUnit): number | null;
380
+ /**
381
+ * Versão safe de castPressure que retorna Result
382
+ */
383
+ declare function tryCastPressure(input: unknown, targetVariant?: PressureUnit): Result$7<number>;
384
+
385
+ /**
386
+ * Frequency Role - Cast Pillar
387
+ *
388
+ * Normaliza input sujo para número, com detecção automática de unidade.
389
+ *
390
+ * @example
391
+ * import { castFrequency, castFrequencyStrict, detectFrequencyUnit } from '@attrx/role-morphic/frequency/cast';
392
+ *
393
+ * castFrequency('2.4 GHz'); // 2400000000 (converted to hertz)
394
+ * castFrequency('2.4 GHz', 'gigahertz'); // 2.4 (kept as gigahertz)
395
+ * castFrequencyStrict('100'); // 100 (no conversion)
396
+ * detectFrequencyUnit('3600 rpm'); // 'rpm'
397
+ */
398
+
399
+ type Result$6<T> = {
400
+ ok: true;
401
+ value: T;
402
+ } | {
403
+ ok: false;
404
+ error: string;
405
+ };
406
+ /**
407
+ * Faz cast de input para número, com conversão opcional para unidade alvo
408
+ *
409
+ * @param input - Valor de entrada (number, string, etc)
410
+ * @param targetVariant - Unidade alvo (default: hertz)
411
+ * @returns Número ou null se não puder converter
412
+ *
413
+ * @example
414
+ * castFrequency('2.4 GHz'); // 2400000000 (hertz)
415
+ * castFrequency('2.4 GHz', 'gigahertz'); // 2.4
416
+ * castFrequency('100'); // 100
417
+ * castFrequency(100); // 100
418
+ * castFrequency('invalid'); // null
419
+ */
420
+ declare function castFrequency(input: unknown, targetVariant?: FrequencyUnit): number | null;
421
+ /**
422
+ * Versão safe de castFrequency que retorna Result
423
+ */
424
+ declare function tryCastFrequency(input: unknown, targetVariant?: FrequencyUnit): Result$6<number>;
425
+
426
+ /**
427
+ * Angle Role - Cast Pillar
428
+ *
429
+ * Normaliza input sujo para número, com detecção automática de unidade.
430
+ *
431
+ * @example
432
+ * import { castAngle, castAngleStrict, detectAngleUnit } from '@attrx/role-morphic/angle/cast';
433
+ *
434
+ * castAngle('90°'); // 90 (degrees)
435
+ * castAngle('3.14159 rad', 'degree'); // ~180 (converted to degrees)
436
+ * castAngleStrict('90'); // 90 (no conversion)
437
+ * detectAngleUnit('45°'); // 'degree'
438
+ */
439
+
440
+ type Result$5<T> = {
441
+ ok: true;
442
+ value: T;
443
+ } | {
444
+ ok: false;
445
+ error: string;
446
+ };
447
+ /**
448
+ * Faz cast de input para número, com conversão opcional para unidade alvo
449
+ *
450
+ * @param input - Valor de entrada (number, string, etc)
451
+ * @param targetVariant - Unidade alvo (default: degree)
452
+ * @returns Número ou null se não puder converter
453
+ *
454
+ * @example
455
+ * castAngle('90°'); // 90
456
+ * castAngle('3.14159 rad', 'degree'); // ~180
457
+ * castAngle('100'); // 100
458
+ * castAngle(45); // 45
459
+ * castAngle('invalid'); // null
460
+ */
461
+ declare function castAngle(input: unknown, targetVariant?: AngleUnit): number | null;
462
+ /**
463
+ * Versão safe de castAngle que retorna Result
464
+ */
465
+ declare function tryCastAngle(input: unknown, targetVariant?: AngleUnit): Result$5<number>;
466
+
467
+ /**
468
+ * Time Role - Cast Pillar
469
+ *
470
+ * Normaliza input sujo para número, com detecção automática de unidade.
471
+ *
472
+ * @example
473
+ * import { castTime, castTimeStrict, detectTimeUnit } from '@attrx/role-morphic/time/cast';
474
+ *
475
+ * castTime('5 min'); // 300 (converted to seconds)
476
+ * castTime('5 min', 'minute'); // 5 (kept as minutes)
477
+ * castTimeStrict('100'); // 100 (no conversion)
478
+ * detectTimeUnit('2 hours'); // 'hour'
479
+ */
480
+
481
+ type Result$4<T> = {
482
+ ok: true;
483
+ value: T;
484
+ } | {
485
+ ok: false;
486
+ error: string;
487
+ };
488
+ /**
489
+ * Faz cast de input para número, com conversão opcional para unidade alvo
490
+ *
491
+ * @param input - Valor de entrada (number, string, etc)
492
+ * @param targetVariant - Unidade alvo (default: second)
493
+ * @returns Número ou null se não puder converter
494
+ *
495
+ * @example
496
+ * castTime('5 min'); // 300 (seconds)
497
+ * castTime('5 min', 'minute'); // 5
498
+ * castTime('100'); // 100
499
+ * castTime(100); // 100
500
+ * castTime('invalid'); // null
501
+ */
502
+ declare function castTime(input: unknown, targetVariant?: TimeUnit): number | null;
503
+ /**
504
+ * Versão safe de castTime que retorna Result
505
+ */
506
+ declare function tryCastTime(input: unknown, targetVariant?: TimeUnit): Result$4<number>;
507
+
508
+ /**
509
+ * Digital Role - Cast Pillar
510
+ *
511
+ * Normaliza input sujo para número, com detecção automática de unidade.
512
+ *
513
+ * @example
514
+ * import { castDigital, castDigitalStrict, detectDigitalUnit } from '@attrx/role-morphic/digital/cast';
515
+ *
516
+ * castDigital('1 MB'); // 1000000 (converted to bytes)
517
+ * castDigital('1 MB', 'megabyte'); // 1 (kept as megabytes)
518
+ * castDigitalStrict('100'); // 100 (no conversion)
519
+ * detectDigitalUnit('2 GiB'); // 'gibibyte'
520
+ */
521
+
522
+ type Result$3<T> = {
523
+ ok: true;
524
+ value: T;
525
+ } | {
526
+ ok: false;
527
+ error: string;
528
+ };
529
+ /**
530
+ * Faz cast de input para número, com conversão opcional para unidade alvo
531
+ *
532
+ * @param input - Valor de entrada (number, string, etc)
533
+ * @param targetVariant - Unidade alvo (default: byte)
534
+ * @returns Número ou null se não puder converter
535
+ *
536
+ * @example
537
+ * castDigital('1 MB'); // 1000000 (bytes)
538
+ * castDigital('1 MB', 'megabyte'); // 1
539
+ * castDigital('100'); // 100
540
+ * castDigital(100); // 100
541
+ * castDigital('invalid'); // null
542
+ */
543
+ declare function castDigital(input: unknown, targetVariant?: DigitalUnit): number | null;
544
+ /**
545
+ * Versão safe de castDigital que retorna Result
546
+ */
547
+ declare function tryCastDigital(input: unknown, targetVariant?: DigitalUnit): Result$3<number>;
548
+
549
+ /**
550
+ * Color Role - Cast Pillar
551
+ *
552
+ * Normaliza input sujo para uma variante de cor específica.
553
+ *
554
+ * @example
555
+ * import { castColor, tryCastColor, detectColorFormat } from '@attrx/role-morphic/color/cast';
556
+ *
557
+ * castColor('hex', 'red'); // '#ff0000'
558
+ * castColor('rgb_object', '#ff0000'); // { r: 255, g: 0, b: 0 }
559
+ * castColor('hsl_string', { r: 255, g: 0, b: 0 }); // 'hsl(0, 100%, 50%)'
560
+ */
561
+
562
+ type Result$2<T> = {
563
+ ok: true;
564
+ value: T;
565
+ } | {
566
+ ok: false;
567
+ error: string;
568
+ };
569
+ /**
570
+ * Faz cast de qualquer input para uma variante de cor
571
+ *
572
+ * @param variant - Variante de destino
573
+ * @param input - Valor de entrada (string, object, etc)
574
+ * @returns Valor na variante de destino ou null se não puder converter
575
+ *
576
+ * @example
577
+ * castColor('hex', 'red'); // '#ff0000'
578
+ * castColor('rgb_object', '#ff0000'); // { r: 255, g: 0, b: 0 }
579
+ * castColor('hsl_string', { r: 255, g: 0, b: 0 }); // 'hsl(0, 100%, 50%)'
580
+ * castColor('hex', 'invalid'); // null
581
+ */
582
+ declare function castColor<T = unknown>(variant: ColorVariant, input: unknown): T | null;
583
+ /**
584
+ * Versão safe de castColor que retorna Result
585
+ */
586
+ declare function tryCastColor<T = unknown>(variant: ColorVariant, input: unknown): Result$2<T>;
587
+
588
+ /**
589
+ * Date Role - Cast Pillar
590
+ *
591
+ * Normaliza input sujo para o tipo esperado de cada variante.
592
+ *
593
+ * @example
594
+ * import { castDate, castIso, castTimestamp, castEpoch } from '@attrx/role-morphic/date/cast';
595
+ *
596
+ * castDate('iso', '2024-12-05'); // '2024-12-05T00:00:00.000Z'
597
+ * castDate('timestamp', '2024-12-05'); // 1733356800000
598
+ * castDate('epoch', new Date()); // 1733425800
599
+ */
600
+
601
+ type Result$1<T> = {
602
+ ok: true;
603
+ value: T;
604
+ } | {
605
+ ok: false;
606
+ error: string;
607
+ };
608
+ /**
609
+ * Faz cast de input para uma variante de data
610
+ *
611
+ * @param variant - Variante de destino ("iso", "timestamp", "epoch")
612
+ * @param input - Valor de entrada
613
+ * @returns Valor convertido ou null se não for possível
614
+ *
615
+ * @example
616
+ * castDate('iso', '2024-12-05'); // '2024-12-05T00:00:00.000Z'
617
+ * castDate('timestamp', new Date()); // timestamp atual
618
+ * castDate('epoch', '2024-12-05'); // 1733356800
619
+ */
620
+ declare function castDate<T = unknown>(variant: DateVariant, input: unknown): T | null;
621
+ /**
622
+ * Versão safe de castDate que retorna Result
623
+ */
624
+ declare function tryCastDate<T = unknown>(variant: DateVariant, input: unknown): Result$1<T>;
625
+
626
+ /**
627
+ * Currency Role - Cast Pillar
628
+ *
629
+ * Normaliza input monetário sujo para número.
630
+ * Extrai o valor numérico de strings formatadas como moeda.
631
+ *
632
+ * NÃO infere a moeda - apenas extrai o valor numérico.
633
+ * A moeda deve ser conhecida via metadata.
634
+ *
635
+ * @example
636
+ * import { castCurrency, castCurrencyStrict } from '@attrx/role-morphic/currency/cast';
637
+ *
638
+ * castCurrency('R$ 1.500,50'); // 1500.50
639
+ * castCurrency('$1,000.00'); // 1000
640
+ * castCurrency('€ 99,99'); // 99.99
641
+ * castCurrency('1500'); // 1500
642
+ * castCurrency(1500.50); // 1500.50
643
+ */
644
+ type Result<T> = {
645
+ ok: true;
646
+ value: T;
647
+ } | {
648
+ ok: false;
649
+ error: string;
650
+ };
651
+ /**
652
+ * Faz cast de input monetário para número
653
+ *
654
+ * Suporta diversos formatos:
655
+ * - Brasileiro: R$ 1.500,50
656
+ * - Americano: $1,000.00
657
+ * - Europeu: € 99,99 ou 99,99 €
658
+ * - Sem símbolo: 1500.50 ou 1500,50
659
+ *
660
+ * @param input - Valor de entrada (number, string, etc)
661
+ * @returns Número ou null se não puder converter
662
+ *
663
+ * @example
664
+ * castCurrency('R$ 1.500,50'); // 1500.50
665
+ * castCurrency('$1,000.00'); // 1000
666
+ * castCurrency('€ 99,99'); // 99.99
667
+ * castCurrency('1.500,50'); // 1500.50 (brasileiro)
668
+ * castCurrency('1,500.50'); // 1500.50 (americano)
669
+ * castCurrency('-R$ 50,00'); // -50
670
+ * castCurrency('invalid'); // null
671
+ */
672
+ declare function castCurrency(input: unknown): number | null;
673
+ /**
674
+ * Versão safe de castCurrency que retorna Result
675
+ */
676
+ declare function tryCastCurrency(input: unknown): Result<number>;
677
+
678
+ export { castAngle, castArea, castColor, castCurrency, castDate, castDigital, castEnergy, castFrequency, castLength, castMass, castPower, castPressure, castSpeed, castTemperature, castTime, castVolume, tryCastAngle, tryCastArea, tryCastColor, tryCastCurrency, tryCastDate, tryCastDigital, tryCastEnergy, tryCastFrequency, tryCastLength, tryCastMass, tryCastPower, tryCastPressure, tryCastSpeed, tryCastTemperature, tryCastTime, tryCastVolume };