@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.
@@ -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(type, path)) {
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 DISALLOWED_TYPES = ['field', 'element', 'array', 'custom'];
67
+ const GENERIC_MESSAGE_REG = /^Must|is required\.?$/;
69
68
 
70
- // Error types that have custom messages should not add the field
71
- // names automatically. Instead the custom messages can include
72
- // the {field} token to allow it to be interpolated if required.
73
- function canAutoAddField(type, path) {
74
- return type && path.length && !DISALLOWED_TYPES.includes(type);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/yada",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Validation library inspired by Joi.",
5
5
  "scripts": {
6
6
  "test": "jest",
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(type, path)) {
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 DISALLOWED_TYPES = ['field', 'element', 'array', 'custom'];
64
+ const GENERIC_MESSAGE_REG = /^Must|is required\.?$/;
64
65
 
65
- // Error types that have custom messages should not add the field
66
- // names automatically. Instead the custom messages can include
67
- // the {field} token to allow it to be interpolated if required.
68
- function canAutoAddField(type, path) {
69
- return type && path.length && !DISALLOWED_TYPES.includes(type);
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) {