@vtex/country-forms 0.0.1 → 1.1.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +29 -1
  3. package/dist/BRA-JUHEOV7J.mjs +96 -0
  4. package/dist/BRA-JUHEOV7J.mjs.map +1 -0
  5. package/dist/BRA-PMVV6KOM.js +119 -0
  6. package/dist/BRA-PMVV6KOM.js.map +1 -0
  7. package/dist/BRA-VIVRV7X7.js +98 -0
  8. package/dist/BRA-VIVRV7X7.js.map +1 -0
  9. package/dist/BRA-ZBZXE5II.mjs +117 -0
  10. package/dist/BRA-ZBZXE5II.mjs.map +1 -0
  11. package/dist/CAN-HUMAGSIC.mjs +67 -0
  12. package/dist/CAN-HUMAGSIC.mjs.map +1 -0
  13. package/dist/CAN-NGS6AUBG.js +69 -0
  14. package/dist/CAN-NGS6AUBG.js.map +1 -0
  15. package/dist/MEX-3PMZHDQP.js +89 -0
  16. package/dist/MEX-3PMZHDQP.js.map +1 -0
  17. package/dist/MEX-QFS4JTN6.mjs +87 -0
  18. package/dist/MEX-QFS4JTN6.mjs.map +1 -0
  19. package/dist/USA-E5AZRBXA.mjs +67 -0
  20. package/dist/USA-E5AZRBXA.mjs.map +1 -0
  21. package/dist/USA-UBWW5NQB.js +69 -0
  22. package/dist/USA-UBWW5NQB.js.map +1 -0
  23. package/dist/bra-I5DOHE34.mjs +57 -0
  24. package/dist/bra-I5DOHE34.mjs.map +1 -0
  25. package/dist/bra-ILOTR4AN.mjs +90 -0
  26. package/dist/bra-ILOTR4AN.mjs.map +1 -0
  27. package/dist/bra-KEBYAD75.js +66 -0
  28. package/dist/bra-KEBYAD75.js.map +1 -0
  29. package/dist/bra-MHTXSNLA.js +96 -0
  30. package/dist/bra-MHTXSNLA.js.map +1 -0
  31. package/dist/bra-states-Q4H2TVQZ.mjs +4 -0
  32. package/dist/bra-states-Q4H2TVQZ.mjs.map +1 -0
  33. package/dist/bra-states-SQMU4WTB.js +17 -0
  34. package/dist/bra-states-SQMU4WTB.js.map +1 -0
  35. package/dist/can-7TMYDEJF.mjs +17 -0
  36. package/dist/can-7TMYDEJF.mjs.map +1 -0
  37. package/dist/can-B5ME2ZFN.js +20 -0
  38. package/dist/can-B5ME2ZFN.js.map +1 -0
  39. package/dist/can-FGNN5MZS.mjs +19 -0
  40. package/dist/can-FGNN5MZS.mjs.map +1 -0
  41. package/dist/can-LLJ4A5Y5.js +21 -0
  42. package/dist/can-LLJ4A5Y5.js.map +1 -0
  43. package/dist/can-provinces-5S5FSO6H.mjs +23 -0
  44. package/dist/can-provinces-5S5FSO6H.mjs.map +1 -0
  45. package/dist/can-provinces-6NOHMW37.js +25 -0
  46. package/dist/can-provinces-6NOHMW37.js.map +1 -0
  47. package/dist/chunk-26GYXS7J.mjs +5622 -0
  48. package/dist/chunk-26GYXS7J.mjs.map +1 -0
  49. package/dist/chunk-2JC3GVFR.mjs +21 -0
  50. package/dist/chunk-2JC3GVFR.mjs.map +1 -0
  51. package/dist/chunk-BMZHOWIP.mjs +21 -0
  52. package/dist/chunk-BMZHOWIP.mjs.map +1 -0
  53. package/dist/chunk-BQPGLWMB.js +25 -0
  54. package/dist/chunk-BQPGLWMB.js.map +1 -0
  55. package/dist/chunk-CFX5EF4R.js +21 -0
  56. package/dist/chunk-CFX5EF4R.js.map +1 -0
  57. package/dist/chunk-KWESVZKV.mjs +18 -0
  58. package/dist/chunk-KWESVZKV.mjs.map +1 -0
  59. package/dist/chunk-LU6ZDUJ5.js +5625 -0
  60. package/dist/chunk-LU6ZDUJ5.js.map +1 -0
  61. package/dist/chunk-YB6VNXLI.js +25 -0
  62. package/dist/chunk-YB6VNXLI.js.map +1 -0
  63. package/dist/en-US-RLEM27ZZ.js +51 -0
  64. package/dist/en-US-RLEM27ZZ.js.map +1 -0
  65. package/dist/en-US-YW7UYXNB.mjs +49 -0
  66. package/dist/en-US-YW7UYXNB.mjs.map +1 -0
  67. package/dist/es-MX-AGRGVXRK.mjs +49 -0
  68. package/dist/es-MX-AGRGVXRK.mjs.map +1 -0
  69. package/dist/es-MX-K5MWKMJW.js +51 -0
  70. package/dist/es-MX-K5MWKMJW.js.map +1 -0
  71. package/dist/fr-FR-KWQ3MPP5.mjs +49 -0
  72. package/dist/fr-FR-KWQ3MPP5.mjs.map +1 -0
  73. package/dist/fr-FR-LJIPE6BH.js +51 -0
  74. package/dist/fr-FR-LJIPE6BH.js.map +1 -0
  75. package/dist/index.d.mts +50 -5
  76. package/dist/index.d.ts +50 -5
  77. package/dist/index.js +73 -6890
  78. package/dist/index.js.map +1 -1
  79. package/dist/index.mjs +66 -6883
  80. package/dist/index.mjs.map +1 -1
  81. package/dist/mex-5BKCF6LS.js +21 -0
  82. package/dist/mex-5BKCF6LS.js.map +1 -0
  83. package/dist/mex-G3HMNBBF.mjs +19 -0
  84. package/dist/mex-G3HMNBBF.mjs.map +1 -0
  85. package/dist/mex-states-GTCRN4NS.js +44 -0
  86. package/dist/mex-states-GTCRN4NS.js.map +1 -0
  87. package/dist/mex-states-KPEGWYKG.mjs +42 -0
  88. package/dist/mex-states-KPEGWYKG.mjs.map +1 -0
  89. package/dist/pt-BR-74IZNREP.js +51 -0
  90. package/dist/pt-BR-74IZNREP.js.map +1 -0
  91. package/dist/pt-BR-P2RZ3X3H.mjs +49 -0
  92. package/dist/pt-BR-P2RZ3X3H.mjs.map +1 -0
  93. package/dist/usa-3AM7UFVG.js +20 -0
  94. package/dist/usa-3AM7UFVG.js.map +1 -0
  95. package/dist/usa-I7DK2CTL.mjs +18 -0
  96. package/dist/usa-I7DK2CTL.mjs.map +1 -0
  97. package/dist/usa-LXT6WW64.js +21 -0
  98. package/dist/usa-LXT6WW64.js.map +1 -0
  99. package/dist/usa-ZD5OWGAD.mjs +18 -0
  100. package/dist/usa-ZD5OWGAD.mjs.map +1 -0
  101. package/dist/usa-states-EBFT4LUQ.js +63 -0
  102. package/dist/usa-states-EBFT4LUQ.js.map +1 -0
  103. package/dist/usa-states-FF5OQBEL.mjs +61 -0
  104. package/dist/usa-states-FF5OQBEL.mjs.map +1 -0
  105. package/package.json +3 -1
package/dist/index.d.ts CHANGED
@@ -375,12 +375,31 @@ type I18nBundle = Record<string, string>;
375
375
  * resolveLabel('country-forms.address.postalCode.label', bundle, overrides)
376
376
  */
377
377
  type I18nOverrides = Record<string, string>;
378
+ /**
379
+ * Interpolation parameters for `resolveLabel`.
380
+ *
381
+ * Each entry replaces every `{key}` placeholder in the resolved message with
382
+ * the provided value. Numeric values are coerced via `String(value)`. Missing
383
+ * placeholders (i.e. a `{key}` appears in the message but no entry exists in
384
+ * `params`) are intentionally left untouched so the gap is visible at runtime.
385
+ *
386
+ * @example
387
+ * resolveLabel(
388
+ * 'country-forms.validation.maxLength',
389
+ * bundle,
390
+ * undefined,
391
+ * { fieldName: 'CEP', maxLength: 9 },
392
+ * )
393
+ * // bundle: "{fieldName} deve ter até {maxLength} caracteres"
394
+ * // → "CEP deve ter até 9 caracteres"
395
+ */
396
+ type I18nParams = Record<string, string | number>;
378
397
 
379
398
  /**
380
399
  * A synchronous field validator function.
381
400
  *
382
401
  * - Returns `true` when the value is valid.
383
- * - Returns an **i18n key** string (e.g. `"country-forms.validation.cpf.invalid"`) when invalid.
402
+ * - Returns an **i18n key** string (e.g. `"country-forms.validation.invalid"`) when invalid.
384
403
  * The engine passes this key to the error map; consumers resolve it via `resolveLabel`.
385
404
  *
386
405
  * Validators must be **pure** and **synchronous**.
@@ -779,7 +798,10 @@ declare function loadLocale(locale: string): Promise<I18nBundle>;
779
798
  /**
780
799
  * @module i18n/resolveLabel
781
800
  *
782
- * Resolves an i18n key to its display string using a three-level cascade:
801
+ * Resolves an i18n key to its display string using a three-level cascade and,
802
+ * optionally, interpolates `{name}` placeholders found in the resolved string.
803
+ *
804
+ * ## Cascade
783
805
  *
784
806
  * 1. **Consumer override** — `overrides[key]` wins if present.
785
807
  * 2. **Bundle value** — `bundle[key]` from `loadLocale()`.
@@ -789,10 +811,22 @@ declare function loadLocale(locale: string): Promise<I18nBundle>;
789
811
  * This design lets consumers customize individual labels without forking the
790
812
  * library or replacing the entire bundle.
791
813
  *
814
+ * ## Interpolation
815
+ *
816
+ * When `params` is provided, every `{name}` placeholder in the resolved string
817
+ * is replaced with `String(params[name])`. Replacement is **global** — the same
818
+ * placeholder may appear more than once in a message and is replaced everywhere
819
+ * it occurs. Placeholders without a matching `params` entry are left untouched
820
+ * so unfulfilled substitutions remain visible to developers.
821
+ *
822
+ * Interpolation is applied after the cascade, so it works equally for override
823
+ * strings, bundle strings, and the raw-key fallback.
824
+ *
792
825
  * @param key - i18n key (e.g. `"country-forms.address.postalCode.label"`)
793
826
  * @param bundle - Locale bundle loaded via `loadLocale()`
794
827
  * @param overrides - Optional consumer-supplied overrides
795
- * @returns Resolved display string
828
+ * @param params - Optional interpolation parameters for `{name}` placeholders
829
+ * @returns Resolved (and optionally interpolated) display string
796
830
  *
797
831
  * @example
798
832
  * const bundle = await loadLocale('pt-BR')
@@ -807,9 +841,20 @@ declare function loadLocale(locale: string): Promise<I18nBundle>;
807
841
  * @example
808
842
  * resolveLabel('country-forms.unknown.key', bundle)
809
843
  * // → "country-forms.unknown.key" (raw key fallback)
844
+ *
845
+ * @example
846
+ * // bundle: { 'country-forms.validation.maxLength':
847
+ * // '{fieldName} deve ter até {maxLength} caracteres' }
848
+ * resolveLabel(
849
+ * 'country-forms.validation.maxLength',
850
+ * bundle,
851
+ * undefined,
852
+ * { fieldName: 'CEP', maxLength: 9 },
853
+ * )
854
+ * // → "CEP deve ter até 9 caracteres"
810
855
  */
811
856
 
812
- declare function resolveLabel(key: string, bundle: I18nBundle, overrides?: I18nOverrides): string;
857
+ declare function resolveLabel(key: string, bundle: I18nBundle, overrides?: I18nOverrides, params?: I18nParams): string;
813
858
 
814
859
  /**
815
860
  * BCP 47 locale tags supported by the library's built-in translation bundles.
@@ -830,4 +875,4 @@ declare const SUPPORTED_LOCALES: readonly ["en-US", "es-MX", "fr-FR", "pt-BR"];
830
875
  /** Union of BCP 47 tags with dedicated built-in bundles. */
831
876
  type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
832
877
 
833
- export { type ConditionalOperator, type ConditionalVisibility, type FieldDefinition, type FieldType, type FormErrors, type FormSchema, type FormState, type FormType, type FormValues, type FormatFn, type I18nBundle, type I18nOverrides, type InputMode, SUPPORTED_ADDRESS_COUNTRIES, SUPPORTED_LOCALES, SUPPORTED_PERSONAL_DATA_COUNTRIES, type SelectOption, type SupportedLocale, type UnformatFn, type ValidationErrors, type ValidationRules, type ValidatorFn, createFormState, formatValue, getVisibleFields, loadLocale, loadSchema, resolveFieldOptions, resolveLabel, setValue, unformatValue, validate };
878
+ export { type ConditionalOperator, type ConditionalVisibility, type FieldDefinition, type FieldType, type FormErrors, type FormSchema, type FormState, type FormType, type FormValues, type FormatFn, type I18nBundle, type I18nOverrides, type I18nParams, type InputMode, SUPPORTED_ADDRESS_COUNTRIES, SUPPORTED_LOCALES, SUPPORTED_PERSONAL_DATA_COUNTRIES, type SelectOption, type SupportedLocale, type UnformatFn, type ValidationErrors, type ValidationRules, type ValidatorFn, createFormState, formatValue, getVisibleFields, loadLocale, loadSchema, resolveFieldOptions, resolveLabel, setValue, unformatValue, validate };