@bedrockio/yada 1.2.3 → 1.2.4
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/messages.js +10 -10
- package/package.json +1 -1
- package/src/messages.js +10 -8
package/dist/cjs/messages.js
CHANGED
|
@@ -44,9 +44,6 @@ function getInnerPath(error, options) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
function getLabeledMessage(error, options) {
|
|
47
|
-
const {
|
|
48
|
-
type
|
|
49
|
-
} = error;
|
|
50
47
|
const {
|
|
51
48
|
path = []
|
|
52
49
|
} = options;
|
|
@@ -54,8 +51,10 @@ function getLabeledMessage(error, options) {
|
|
|
54
51
|
let template;
|
|
55
52
|
if (base.includes('{field}')) {
|
|
56
53
|
template = base;
|
|
57
|
-
} else if (canAutoAddField(
|
|
54
|
+
} else if (canAutoAddField(path, base)) {
|
|
58
55
|
template = `{field} ${downcase(base)}`;
|
|
56
|
+
} else {
|
|
57
|
+
template = error.message;
|
|
59
58
|
}
|
|
60
59
|
if (template) {
|
|
61
60
|
return (0, _localization.localize)(template, {
|
|
@@ -65,13 +64,14 @@ function getLabeledMessage(error, options) {
|
|
|
65
64
|
return (0, _localization.localize)(base);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
const
|
|
67
|
+
const GENERIC_MESSAGE_REG = /^Must|is required\.?$/;
|
|
69
68
|
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
// Only "generic" error messages should automatically add the field.
|
|
70
|
+
// A custom error message may be "Please verify you are human" which
|
|
71
|
+
// is intended to be understood in context and does not benefit from
|
|
72
|
+
// the inclusion of the field name.
|
|
73
|
+
function canAutoAddField(path, base) {
|
|
74
|
+
return path.length && GENERIC_MESSAGE_REG.test(base);
|
|
75
75
|
}
|
|
76
76
|
function getFieldLabel(options) {
|
|
77
77
|
const {
|
package/package.json
CHANGED
package/src/messages.js
CHANGED
|
@@ -40,15 +40,16 @@ function getInnerPath(error, options) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function getLabeledMessage(error, options) {
|
|
43
|
-
const { type } = error;
|
|
44
43
|
const { path = [] } = options;
|
|
45
44
|
const base = getBase(error.message);
|
|
46
45
|
|
|
47
46
|
let template;
|
|
48
47
|
if (base.includes('{field}')) {
|
|
49
48
|
template = base;
|
|
50
|
-
} else if (canAutoAddField(
|
|
49
|
+
} else if (canAutoAddField(path, base)) {
|
|
51
50
|
template = `{field} ${downcase(base)}`;
|
|
51
|
+
} else {
|
|
52
|
+
template = error.message;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
if (template) {
|
|
@@ -60,13 +61,14 @@ function getLabeledMessage(error, options) {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
const
|
|
64
|
+
const GENERIC_MESSAGE_REG = /^Must|is required\.?$/;
|
|
64
65
|
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
// Only "generic" error messages should automatically add the field.
|
|
67
|
+
// A custom error message may be "Please verify you are human" which
|
|
68
|
+
// is intended to be understood in context and does not benefit from
|
|
69
|
+
// the inclusion of the field name.
|
|
70
|
+
function canAutoAddField(path, base) {
|
|
71
|
+
return path.length && GENERIC_MESSAGE_REG.test(base);
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
function getFieldLabel(options) {
|