asma-core-helpers 0.42.2 → 0.43.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/lib/helpers/_processServerError.d.ts +4 -2
- package/lib/helpers/_processServerError.d.ts.map +1 -1
- package/lib/helpers/_processServerError.js +10 -3
- package/lib/helpers/_processServerError.js.map +1 -1
- package/lib/helpers/httpErrorMessage.d.ts +9 -0
- package/lib/helpers/httpErrorMessage.d.ts.map +1 -0
- package/lib/helpers/httpErrorMessage.js +121 -0
- package/lib/helpers/httpErrorMessage.js.map +1 -0
- package/lib/helpers/httpErrorMessages.d.ts +7 -0
- package/lib/helpers/httpErrorMessages.d.ts.map +1 -0
- package/lib/helpers/httpErrorMessages.js +45 -0
- package/lib/helpers/httpErrorMessages.js.map +1 -0
- package/lib/validation/index.d.ts +1 -1
- package/lib/validation/index.d.ts.map +1 -1
- package/lib/validation/index.js +1 -1
- package/lib/validation/index.js.map +1 -1
- package/lib/validation/messages.d.ts +136 -24
- package/lib/validation/messages.d.ts.map +1 -1
- package/lib/validation/messages.js +140 -23
- package/lib/validation/messages.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/_processServerError.ts +19 -3
- package/src/helpers/httpErrorMessage.test.ts +269 -0
- package/src/helpers/httpErrorMessage.ts +106 -0
- package/src/helpers/httpErrorMessages.ts +43 -0
- package/src/validation/index.ts +3 -0
- package/src/validation/messages.test.ts +60 -4
- package/src/validation/messages.ts +202 -25
package/src/validation/index.ts
CHANGED
|
@@ -7,10 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
9
|
errorWithHint,
|
|
10
|
+
formatValidationMessage,
|
|
11
|
+
getValidationMessage,
|
|
10
12
|
getValidationMessages,
|
|
11
13
|
validationMessages,
|
|
12
14
|
type ValidationLocale,
|
|
13
15
|
type ValidationMessageKey,
|
|
16
|
+
type ValidationMessageParams,
|
|
14
17
|
type ValidationMessages,
|
|
15
18
|
} from './messages.js'
|
|
16
19
|
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
import { describe, it } from 'node:test'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
errorWithHint,
|
|
6
|
+
formatValidationMessage,
|
|
7
|
+
getValidationMessage,
|
|
8
|
+
getValidationMessages,
|
|
9
|
+
validationMessages,
|
|
10
|
+
} from './messages.js'
|
|
5
11
|
|
|
6
12
|
describe('validationMessages catalog', () => {
|
|
7
13
|
it('exposes distinct NB and EN strings for every key', () => {
|
|
@@ -18,8 +24,8 @@ describe('validationMessages catalog', () => {
|
|
|
18
24
|
|
|
19
25
|
it('MUT-004: wrong language must fail — nb required is not the en string', () => {
|
|
20
26
|
assert.notEqual(validationMessages.nb.required, validationMessages.en.required)
|
|
21
|
-
assert.equal(getValidationMessages('nb').required, '
|
|
22
|
-
assert.equal(getValidationMessages('en').required, '
|
|
27
|
+
assert.equal(getValidationMessages('nb').required, 'Obligatorisk')
|
|
28
|
+
assert.equal(getValidationMessages('en').required, 'Required')
|
|
23
29
|
assert.notEqual(getValidationMessages('nb').invalid_email, getValidationMessages('en').invalid_email)
|
|
24
30
|
})
|
|
25
31
|
|
|
@@ -35,7 +41,57 @@ describe('errorWithHint', () => {
|
|
|
35
41
|
assert.equal(errorWithHint('Invalid email', 'name@carasent.com'), 'Invalid email — name@carasent.com')
|
|
36
42
|
assert.equal(
|
|
37
43
|
errorWithHint(validationMessages.nb.invalid_email, 'name@carasent.com'),
|
|
38
|
-
'
|
|
44
|
+
'Skriv inn en gyldig e-postadresse med domene. — name@carasent.com',
|
|
39
45
|
)
|
|
40
46
|
})
|
|
41
47
|
})
|
|
48
|
+
|
|
49
|
+
describe('Figma copy rules (ASMA-8073)', () => {
|
|
50
|
+
it('every sentence ends with a period; Required is the one exception', () => {
|
|
51
|
+
for (const locale of ['en', 'nb'] as const) {
|
|
52
|
+
for (const [key, value] of Object.entries(validationMessages[locale])) {
|
|
53
|
+
if (key === 'required') continue
|
|
54
|
+
assert.ok(value.endsWith('.'), `${locale}.${key} must end with a period`)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('no generic "Invalid …" / "Duplicate …" copy remains', () => {
|
|
60
|
+
for (const value of Object.values(validationMessages.en)) {
|
|
61
|
+
assert.doesNotMatch(value, /^(Invalid|Duplicate)\b/)
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('EN and NB use the same placeholders', () => {
|
|
66
|
+
const names = (s: string) => [...s.matchAll(/\{(\w+)\}/g)].map((m) => m[1]).sort().join(',')
|
|
67
|
+
for (const key of Object.keys(validationMessages.en) as (keyof typeof validationMessages.en)[]) {
|
|
68
|
+
assert.equal(names(validationMessages.nb[key]), names(validationMessages.en[key]), key)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('ASMA-8073 wave 3 copy', () => {
|
|
74
|
+
it('adds personal_number_no_spaces and drops the unapproved duplicate_employee_no/duplicate_phone keys', () => {
|
|
75
|
+
assert.equal(getValidationMessages('en').personal_number_no_spaces, 'Enter 11 digits without spaces.')
|
|
76
|
+
assert.equal(getValidationMessages('nb').personal_number_no_spaces, 'Skriv inn 11 sifre uten mellomrom.')
|
|
77
|
+
assert.ok(!('duplicate_employee_no' in validationMessages.en))
|
|
78
|
+
assert.ok(!('duplicate_phone' in validationMessages.en))
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('allows the same day in a date/time range (G1/G2)', () => {
|
|
82
|
+
assert.equal(getValidationMessages('en').date_after_start, 'Select a date on or after the start date.')
|
|
83
|
+
assert.equal(getValidationMessages('en').time_after_start, 'Select a time at or after the start time.')
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('formatValidationMessage', () => {
|
|
88
|
+
it('fills placeholders', () => {
|
|
89
|
+
assert.equal(getValidationMessage('en', 'max_length', { n: 100 }), 'Enter no more than 100 characters.')
|
|
90
|
+
assert.equal(getValidationMessage('nb', 'length_between', { min: 36, max: 100 }), 'Skriv inn mellom 36 og 100 tegn.')
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('keeps unknown placeholders visible', () => {
|
|
94
|
+
assert.equal(formatValidationMessage('Enter at least {n} characters.', {}), 'Enter at least {n} characters.')
|
|
95
|
+
assert.equal(formatValidationMessage('Required'), 'Required')
|
|
96
|
+
})
|
|
97
|
+
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Default NB/EN validation catalog for ASMA forms (ASMA-7729).
|
|
2
|
+
* Default NB/EN validation catalog for ASMA forms (ASMA-7729, ASMA-8073).
|
|
3
|
+
* EN copy follows Figma "Admin panel → Error messages" (node 11381:172081).
|
|
4
|
+
* Placeholders use `{name}` and are filled by `formatValidationMessage`.
|
|
3
5
|
* Apps override via shallow merge — translations stay in app i18n.
|
|
4
6
|
*/
|
|
5
7
|
|
|
@@ -8,44 +10,203 @@ export type ValidationLocale = 'nb' | 'en'
|
|
|
8
10
|
export type ValidationMessageKey =
|
|
9
11
|
| 'required'
|
|
10
12
|
| 'invalid_email'
|
|
13
|
+
| 'email_missing_at'
|
|
11
14
|
| 'invalid_name'
|
|
12
15
|
| 'invalid_phone'
|
|
13
16
|
| 'invalid_personal_number'
|
|
17
|
+
| 'personal_number_length'
|
|
18
|
+
| 'personal_number_no_spaces'
|
|
19
|
+
| 'personal_number_birth_date'
|
|
20
|
+
| 'personal_number_enter'
|
|
14
21
|
| 'duplicate_email'
|
|
15
22
|
| 'duplicate_journal_id'
|
|
16
23
|
| 'duplicate_personal_number'
|
|
17
|
-
| 'duplicate_employee_no'
|
|
18
|
-
| 'duplicate_phone'
|
|
19
24
|
| 'duplicate_username'
|
|
25
|
+
| 'duplicate_category'
|
|
26
|
+
| 'min_length'
|
|
27
|
+
| 'max_length'
|
|
28
|
+
| 'length_between'
|
|
29
|
+
| 'digits_only'
|
|
30
|
+
| 'letters_numbers_only'
|
|
31
|
+
| 'subdomain_chars'
|
|
32
|
+
| 'invalid_subdomain'
|
|
33
|
+
| 'date_invalid_format'
|
|
34
|
+
| 'date_invalid_day'
|
|
35
|
+
| 'date_invalid_month'
|
|
36
|
+
| 'date_year_range'
|
|
37
|
+
| 'date_invalid'
|
|
38
|
+
| 'date_after_start'
|
|
39
|
+
| 'date_unavailable'
|
|
40
|
+
| 'date_today_or_future'
|
|
41
|
+
| 'date_today_or_earlier'
|
|
42
|
+
| 'date_of_birth_invalid_format'
|
|
43
|
+
| 'date_of_birth_invalid'
|
|
44
|
+
| 'date_of_birth_not_future'
|
|
45
|
+
| 'time_invalid_format'
|
|
46
|
+
| 'time_after_start'
|
|
47
|
+
| 'hour_invalid'
|
|
48
|
+
| 'hour_range'
|
|
49
|
+
| 'minutes_quarter'
|
|
50
|
+
| 'time_greater_than_zero'
|
|
51
|
+
| 'select_at_least_one_recipient'
|
|
52
|
+
| 'category_from_list'
|
|
53
|
+
| 'customer_required'
|
|
54
|
+
| 'patient_invalid'
|
|
55
|
+
| 'file_required'
|
|
56
|
+
| 'file_download_required'
|
|
57
|
+
| 'file_count_max'
|
|
58
|
+
| 'file_single'
|
|
59
|
+
| 'file_empty'
|
|
60
|
+
| 'file_type'
|
|
61
|
+
| 'file_media_type'
|
|
62
|
+
| 'file_size_max'
|
|
63
|
+
| 'code_invalid'
|
|
64
|
+
| 'code_request_new'
|
|
65
|
+
| 'code_wait'
|
|
66
|
+
| 'phone_not_linked'
|
|
67
|
+
| 'no_portal_access'
|
|
68
|
+
| 'sign_in_method_unavailable'
|
|
69
|
+
| 'credentials_invalid'
|
|
70
|
+
| 'invitation_code_invalid'
|
|
71
|
+
| 'refresh_and_try_again'
|
|
72
|
+
| 'check_and_try_again'
|
|
73
|
+
| 'reduce_data_and_try_again'
|
|
74
|
+
| 'try_again'
|
|
20
75
|
|
|
21
76
|
export type ValidationMessages = Record<ValidationMessageKey, string>
|
|
22
77
|
|
|
23
78
|
export const validationMessages = {
|
|
24
79
|
nb: {
|
|
25
|
-
required: '
|
|
26
|
-
invalid_email: '
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
80
|
+
required: 'Obligatorisk',
|
|
81
|
+
invalid_email: 'Skriv inn en gyldig e-postadresse med domene.',
|
|
82
|
+
email_missing_at: 'Skriv inn en e-postadresse med @.',
|
|
83
|
+
invalid_name: 'Bruk bokstaver, mellomrom, bindestrek eller apostrof.',
|
|
84
|
+
invalid_phone: 'Skriv inn et gyldig telefonnummer, for eksempel +47 12 34 56 78.',
|
|
85
|
+
invalid_personal_number: 'Skriv inn et gyldig personnummer.',
|
|
86
|
+
personal_number_length: 'Skriv inn 11 sifre.',
|
|
87
|
+
personal_number_no_spaces: 'Skriv inn 11 sifre uten mellomrom.',
|
|
88
|
+
personal_number_birth_date: 'Skriv inn et gyldig personnummer.',
|
|
89
|
+
personal_number_enter: 'Skriv inn personnummeret ditt.',
|
|
90
|
+
duplicate_email: 'Skriv inn en annen e-postadresse.',
|
|
91
|
+
duplicate_journal_id: 'Skriv inn en annen journal-ID.',
|
|
92
|
+
duplicate_personal_number: 'Skriv inn et annet personnummer.',
|
|
93
|
+
duplicate_username: 'Skriv inn et annet brukernavn.',
|
|
94
|
+
duplicate_category: 'Skriv inn en annen kategori.',
|
|
95
|
+
min_length: 'Skriv inn minst {n} tegn.',
|
|
96
|
+
max_length: 'Skriv inn maks {n} tegn.',
|
|
97
|
+
length_between: 'Skriv inn mellom {min} og {max} tegn.',
|
|
98
|
+
digits_only: 'Skriv inn bare sifre.',
|
|
99
|
+
letters_numbers_only: 'Bruk bare bokstaver og tall.',
|
|
100
|
+
subdomain_chars: 'Bruk bare bokstaver, tall og bindestrek.',
|
|
101
|
+
invalid_subdomain: 'Skriv inn et gyldig underdomene.',
|
|
102
|
+
date_invalid_format: 'Skriv inn en gyldig dato i formatet DD.MM.ÅÅÅÅ.',
|
|
103
|
+
date_invalid_day: 'Skriv inn en gyldig dag.',
|
|
104
|
+
date_invalid_month: 'Skriv inn en gyldig måned.',
|
|
105
|
+
date_year_range: 'Skriv inn et år mellom {min} og {max}.',
|
|
106
|
+
date_invalid: 'Skriv inn en gyldig dato.',
|
|
107
|
+
date_after_start: 'Velg en dato på eller etter startdatoen.',
|
|
108
|
+
date_unavailable: 'Velg en annen dato.',
|
|
109
|
+
date_today_or_future: 'Velg dagens dato eller en senere dato.',
|
|
110
|
+
date_today_or_earlier: 'Velg dagens dato eller en tidligere dato.',
|
|
111
|
+
date_of_birth_invalid_format: 'Skriv inn en gyldig fødselsdato i formatet DD.MM.ÅÅÅÅ.',
|
|
112
|
+
date_of_birth_invalid: 'Skriv inn en gyldig fødselsdato.',
|
|
113
|
+
date_of_birth_not_future: 'Skriv inn en fødselsdato som er i dag eller tidligere.',
|
|
114
|
+
time_invalid_format: 'Skriv inn et gyldig klokkeslett i formatet TT:mm.',
|
|
115
|
+
time_after_start: 'Velg et klokkeslett på eller etter starttidspunktet.',
|
|
116
|
+
hour_invalid: 'Skriv inn en gyldig time.',
|
|
117
|
+
hour_range: 'Skriv inn en time mellom {min} og {max}.',
|
|
118
|
+
minutes_quarter: 'Skriv inn 0, 15, 30 eller 45 minutter.',
|
|
119
|
+
time_greater_than_zero: 'Skriv inn en tid som er større enn 0.',
|
|
120
|
+
select_at_least_one_recipient: 'Velg minst én mottaker.',
|
|
121
|
+
category_from_list: 'Velg en kategori fra listen.',
|
|
122
|
+
customer_required: 'Velg en kunde.',
|
|
123
|
+
patient_invalid: 'Velg en gyldig pasient.',
|
|
124
|
+
file_required: 'Velg en fil å laste opp.',
|
|
125
|
+
file_download_required: 'Velg en fil å laste ned.',
|
|
126
|
+
file_count_max: 'Velg opptil {n} filer.',
|
|
127
|
+
file_single: 'Velg én fil.',
|
|
128
|
+
file_empty: 'Denne filen er tom. Velg en annen fil.',
|
|
129
|
+
file_type: 'Velg en støttet filtype.',
|
|
130
|
+
file_media_type: 'Velg en støttet bilde- eller videofil.',
|
|
131
|
+
file_size_max: 'Velg en fil som ikke er større enn {size}.',
|
|
132
|
+
code_invalid: 'Skriv inn en gyldig kode.',
|
|
133
|
+
code_request_new: 'Be om en ny kode.',
|
|
134
|
+
code_wait: 'Vent {n} minutter før du ber om en ny kode.',
|
|
135
|
+
phone_not_linked: 'Skriv inn et telefonnummer som er knyttet til en konto.',
|
|
136
|
+
no_portal_access: 'Kontakt administratoren din for å få tilgang til denne portalen.',
|
|
137
|
+
sign_in_method_unavailable: 'Denne innloggingsmetoden er ikke tilgjengelig for organisasjonen din.',
|
|
138
|
+
credentials_invalid: 'Skriv inn riktig e-postadresse og passord.',
|
|
139
|
+
invitation_code_invalid: 'Skriv inn en gyldig invitasjonskode på 25 tegn.',
|
|
140
|
+
refresh_and_try_again: 'Last inn siden på nytt og prøv igjen.',
|
|
141
|
+
check_and_try_again: 'Sjekk svaret ditt og prøv igjen.',
|
|
142
|
+
reduce_data_and_try_again: 'Reduser mengden data og prøv igjen.',
|
|
143
|
+
try_again: 'Prøv igjen.',
|
|
36
144
|
},
|
|
37
145
|
en: {
|
|
38
|
-
required: '
|
|
39
|
-
invalid_email: '
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
146
|
+
required: 'Required',
|
|
147
|
+
invalid_email: 'Enter a valid email address with a domain.',
|
|
148
|
+
email_missing_at: 'Enter an email address with an @.',
|
|
149
|
+
invalid_name: 'Use letters, spaces, hyphens, or apostrophes.',
|
|
150
|
+
invalid_phone: 'Enter a valid phone number, like +47 12 34 56 78.',
|
|
151
|
+
invalid_personal_number: 'Enter a valid personal number.',
|
|
152
|
+
personal_number_length: 'Enter 11 digits.',
|
|
153
|
+
personal_number_no_spaces: 'Enter 11 digits without spaces.',
|
|
154
|
+
personal_number_birth_date: 'Enter a valid personal number.',
|
|
155
|
+
personal_number_enter: 'Enter your personal number.',
|
|
156
|
+
duplicate_email: 'Enter a different email address.',
|
|
157
|
+
duplicate_journal_id: 'Enter a different journal ID.',
|
|
158
|
+
duplicate_personal_number: 'Enter a different personal number.',
|
|
159
|
+
duplicate_username: 'Enter a different username.',
|
|
160
|
+
duplicate_category: 'Enter a different category.',
|
|
161
|
+
min_length: 'Enter at least {n} characters.',
|
|
162
|
+
max_length: 'Enter no more than {n} characters.',
|
|
163
|
+
length_between: 'Enter between {min} and {max} characters.',
|
|
164
|
+
digits_only: 'Enter digits only.',
|
|
165
|
+
letters_numbers_only: 'Use letters and numbers only.',
|
|
166
|
+
subdomain_chars: 'Use letters, numbers, and hyphens only.',
|
|
167
|
+
invalid_subdomain: 'Enter a valid subdomain.',
|
|
168
|
+
date_invalid_format: 'Enter a valid date in DD.MM.YYYY format.',
|
|
169
|
+
date_invalid_day: 'Enter a valid day.',
|
|
170
|
+
date_invalid_month: 'Enter a valid month.',
|
|
171
|
+
date_year_range: 'Enter a year between {min} and {max}.',
|
|
172
|
+
date_invalid: 'Enter a valid date.',
|
|
173
|
+
date_after_start: 'Select a date on or after the start date.',
|
|
174
|
+
date_unavailable: 'Select another date.',
|
|
175
|
+
date_today_or_future: 'Select today or a future date.',
|
|
176
|
+
date_today_or_earlier: 'Select today or an earlier date.',
|
|
177
|
+
date_of_birth_invalid_format: 'Enter a valid date of birth in DD.MM.YYYY format.',
|
|
178
|
+
date_of_birth_invalid: 'Enter a real date of birth.',
|
|
179
|
+
date_of_birth_not_future: "Enter a date of birth that's today or earlier.",
|
|
180
|
+
time_invalid_format: 'Enter a valid time in HH:mm format.',
|
|
181
|
+
time_after_start: 'Select a time at or after the start time.',
|
|
182
|
+
hour_invalid: 'Enter a valid hour.',
|
|
183
|
+
hour_range: 'Enter an hour between {min} and {max}.',
|
|
184
|
+
minutes_quarter: 'Enter 0, 15, 30, or 45 minutes.',
|
|
185
|
+
time_greater_than_zero: 'Enter a time greater than 0.',
|
|
186
|
+
select_at_least_one_recipient: 'Select at least one recipient.',
|
|
187
|
+
category_from_list: 'Select a category from the list.',
|
|
188
|
+
customer_required: 'Select a customer.',
|
|
189
|
+
patient_invalid: 'Select a valid patient.',
|
|
190
|
+
file_required: 'Select a file to upload.',
|
|
191
|
+
file_download_required: 'Select a file to download.',
|
|
192
|
+
file_count_max: 'Select up to {n} files.',
|
|
193
|
+
file_single: 'Select one file.',
|
|
194
|
+
file_empty: 'This file is empty. Select another file.',
|
|
195
|
+
file_type: 'Select a supported file type.',
|
|
196
|
+
file_media_type: 'Select a supported image or video file.',
|
|
197
|
+
file_size_max: 'Select a file no larger than {size}.',
|
|
198
|
+
code_invalid: 'Enter a valid code.',
|
|
199
|
+
code_request_new: 'Request a new code.',
|
|
200
|
+
code_wait: 'Wait {n} minutes before requesting a new code.',
|
|
201
|
+
phone_not_linked: 'Enter a phone number linked to an account.',
|
|
202
|
+
no_portal_access: 'Contact your administrator for access to this portal.',
|
|
203
|
+
sign_in_method_unavailable: "This sign-in method isn't available for your organization.",
|
|
204
|
+
credentials_invalid: 'Enter the correct email and password.',
|
|
205
|
+
invitation_code_invalid: 'Enter a valid 25-character invitation code.',
|
|
206
|
+
refresh_and_try_again: 'Refresh the page and try again.',
|
|
207
|
+
check_and_try_again: 'Check your answer and try again.',
|
|
208
|
+
reduce_data_and_try_again: 'Reduce the amount of data and try again.',
|
|
209
|
+
try_again: 'Try again.',
|
|
49
210
|
},
|
|
50
211
|
} as const satisfies Record<ValidationLocale, ValidationMessages>
|
|
51
212
|
|
|
@@ -57,6 +218,22 @@ export function getValidationMessages(
|
|
|
57
218
|
return { ...validationMessages[locale], ...overrides }
|
|
58
219
|
}
|
|
59
220
|
|
|
221
|
+
export type ValidationMessageParams = Record<string, string | number>
|
|
222
|
+
|
|
223
|
+
/** Fills `{name}` placeholders; unknown placeholders stay visible so a missing param is caught in review. */
|
|
224
|
+
export function formatValidationMessage(template: string, params?: ValidationMessageParams): string {
|
|
225
|
+
if (!params) return template
|
|
226
|
+
return template.replace(/\{(\w+)\}/g, (match, key: string) => (key in params ? String(params[key]) : match))
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function getValidationMessage(
|
|
230
|
+
locale: ValidationLocale,
|
|
231
|
+
key: ValidationMessageKey,
|
|
232
|
+
params?: ValidationMessageParams,
|
|
233
|
+
): string {
|
|
234
|
+
return formatValidationMessage(validationMessages[locale][key], params)
|
|
235
|
+
}
|
|
236
|
+
|
|
60
237
|
/**
|
|
61
238
|
* REQ-003: actionable "what's wrong — how to fix" composition.
|
|
62
239
|
* e.g. errorWithHint('Invalid email', 'name@carasent.com') → 'Invalid email — name@carasent.com'
|