@bedrockio/yada 1.0.9 → 1.0.10
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/cjs/localization.js +1 -1
- package/dist/cjs/messages.js +3 -3
- package/package.json +1 -1
- package/src/localization.js +1 -1
- package/src/messages.js +3 -3
- package/test/all.test.js +13 -0
package/dist/cjs/localization.js
CHANGED
|
@@ -33,7 +33,7 @@ function localize(template, values = {}) {
|
|
|
33
33
|
}
|
|
34
34
|
templates[template] = message;
|
|
35
35
|
return message.replace(TOKEN_REG, (match, token) => {
|
|
36
|
-
return values[token];
|
|
36
|
+
return token in values ? values[token] : match;
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
function getLocalizerTemplates() {
|
package/dist/cjs/messages.js
CHANGED
|
@@ -33,12 +33,12 @@ function getLabeledMessage(error, options) {
|
|
|
33
33
|
} = options;
|
|
34
34
|
const base = getBase(error.message);
|
|
35
35
|
if (field) {
|
|
36
|
-
const msg = `{field} ${base}`;
|
|
36
|
+
const msg = `{field} ${downcase(base)}`;
|
|
37
37
|
return (0, _localization.localize)(msg, {
|
|
38
38
|
field: getFieldLabel(field, options)
|
|
39
39
|
});
|
|
40
40
|
} else if (index != null) {
|
|
41
|
-
const msg = `Element at index "{index}" ${base}`;
|
|
41
|
+
const msg = `Element at index "{index}" ${downcase(base)}`;
|
|
42
42
|
return (0, _localization.localize)(msg, {
|
|
43
43
|
index
|
|
44
44
|
});
|
|
@@ -60,7 +60,7 @@ function getBase(str) {
|
|
|
60
60
|
if (str === 'Value is required.') {
|
|
61
61
|
return 'is required.';
|
|
62
62
|
} else {
|
|
63
|
-
return
|
|
63
|
+
return str;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
function naturalize(str) {
|
package/package.json
CHANGED
package/src/localization.js
CHANGED
package/src/messages.js
CHANGED
|
@@ -26,12 +26,12 @@ function getLabeledMessage(error, options) {
|
|
|
26
26
|
const { field, index } = options;
|
|
27
27
|
const base = getBase(error.message);
|
|
28
28
|
if (field) {
|
|
29
|
-
const msg = `{field} ${base}`;
|
|
29
|
+
const msg = `{field} ${downcase(base)}`;
|
|
30
30
|
return localize(msg, {
|
|
31
31
|
field: getFieldLabel(field, options),
|
|
32
32
|
});
|
|
33
33
|
} else if (index != null) {
|
|
34
|
-
const msg = `Element at index "{index}" ${base}`;
|
|
34
|
+
const msg = `Element at index "{index}" ${downcase(base)}`;
|
|
35
35
|
return localize(msg, {
|
|
36
36
|
index,
|
|
37
37
|
});
|
|
@@ -53,7 +53,7 @@ function getBase(str) {
|
|
|
53
53
|
if (str === 'Value is required.') {
|
|
54
54
|
return 'is required.';
|
|
55
55
|
} else {
|
|
56
|
-
return
|
|
56
|
+
return str;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
package/test/all.test.js
CHANGED
|
@@ -1802,6 +1802,19 @@ describe('getFullMessage', () => {
|
|
|
1802
1802
|
'Auth code is required. Pass code is required. My token is required.'
|
|
1803
1803
|
);
|
|
1804
1804
|
});
|
|
1805
|
+
|
|
1806
|
+
it('should not interpolate tokens that do not exist', async () => {
|
|
1807
|
+
const schema = yd.custom(() => {
|
|
1808
|
+
throw new Error('Must {not} be.');
|
|
1809
|
+
});
|
|
1810
|
+
try {
|
|
1811
|
+
await schema.validate({
|
|
1812
|
+
foo: 'bar',
|
|
1813
|
+
});
|
|
1814
|
+
} catch (error) {
|
|
1815
|
+
expect(error.getFullMessage()).toBe('Must {not} be.');
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1805
1818
|
});
|
|
1806
1819
|
|
|
1807
1820
|
describe('localization', () => {
|