valgen 5.12.0 → 5.13.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/cjs/core/context.js +2 -0
  3. package/cjs/core/validation-error.js +2 -1
  4. package/cjs/core/validator.js +12 -6
  5. package/cjs/rules/format-rules/is-alpha.js +2 -2
  6. package/cjs/rules/format-rules/is-ascii.js +1 -1
  7. package/cjs/rules/format-rules/is-base64.js +1 -1
  8. package/cjs/rules/format-rules/is-btc-address.js +1 -1
  9. package/cjs/rules/format-rules/is-credit-card.js +1 -1
  10. package/cjs/rules/format-rules/is-decimal.js +1 -1
  11. package/cjs/rules/format-rules/is-ean.js +1 -1
  12. package/cjs/rules/format-rules/is-email.js +1 -10
  13. package/cjs/rules/format-rules/is-eth-address.js +1 -1
  14. package/cjs/rules/format-rules/is-fqdn.js +1 -2
  15. package/cjs/rules/format-rules/is-hash.js +1 -1
  16. package/cjs/rules/format-rules/is-hex-color.js +1 -1
  17. package/cjs/rules/format-rules/is-hex.js +1 -1
  18. package/cjs/rules/format-rules/is-iban.js +2 -2
  19. package/cjs/rules/format-rules/is-ip.js +2 -2
  20. package/cjs/rules/format-rules/is-issn.js +1 -2
  21. package/cjs/rules/format-rules/is-jwt.js +1 -1
  22. package/cjs/rules/format-rules/is-lowercase.js +2 -2
  23. package/cjs/rules/format-rules/is-mac-address.js +1 -2
  24. package/cjs/rules/format-rules/is-mobile-phone.js +1 -1
  25. package/cjs/rules/format-rules/is-object-id.js +1 -1
  26. package/cjs/rules/format-rules/is-passport-number.js +1 -1
  27. package/cjs/rules/format-rules/is-port.js +1 -1
  28. package/cjs/rules/format-rules/is-url.js +1 -1
  29. package/cjs/rules/format-rules/is-uuid.js +1 -1
  30. package/cjs/rules/format-rules/is-vat-number.js +1 -1
  31. package/cjs/rules/format-rules/matches.js +1 -1
  32. package/cjs/rules/logical-rules/is-defined.js +1 -1
  33. package/cjs/rules/logical-rules/is-empty.js +34 -14
  34. package/cjs/rules/logical-rules/range.js +5 -5
  35. package/cjs/rules/type-rules/is-array.js +6 -2
  36. package/cjs/rules/type-rules/is-bigint.js +1 -2
  37. package/cjs/rules/type-rules/is-boolean.js +1 -2
  38. package/cjs/rules/type-rules/is-date.js +4 -6
  39. package/cjs/rules/type-rules/is-integer.js +1 -6
  40. package/cjs/rules/type-rules/is-null.js +1 -1
  41. package/cjs/rules/type-rules/is-number.js +1 -6
  42. package/cjs/rules/type-rules/is-object.js +1 -1
  43. package/cjs/rules/type-rules/is-record.js +6 -4
  44. package/cjs/rules/type-rules/is-string.js +1 -1
  45. package/cjs/rules/type-rules/is-tuple.js +1 -1
  46. package/cjs/rules/type-rules/is-undefined.js +1 -1
  47. package/cjs/rules/utility-rules/get-length.js +1 -1
  48. package/cjs/rules/utility-rules/required.js +1 -1
  49. package/cjs/tsconfig-build-cjs.tsbuildinfo +1 -1
  50. package/esm/core/context.js +2 -0
  51. package/esm/core/validation-error.js +2 -1
  52. package/esm/core/validator.js +12 -6
  53. package/esm/rules/format-rules/is-alpha.js +2 -2
  54. package/esm/rules/format-rules/is-ascii.js +1 -1
  55. package/esm/rules/format-rules/is-base64.js +1 -1
  56. package/esm/rules/format-rules/is-btc-address.js +1 -1
  57. package/esm/rules/format-rules/is-credit-card.js +1 -1
  58. package/esm/rules/format-rules/is-decimal.js +1 -1
  59. package/esm/rules/format-rules/is-ean.js +1 -1
  60. package/esm/rules/format-rules/is-email.js +1 -10
  61. package/esm/rules/format-rules/is-eth-address.js +1 -1
  62. package/esm/rules/format-rules/is-fqdn.js +1 -2
  63. package/esm/rules/format-rules/is-hash.js +1 -1
  64. package/esm/rules/format-rules/is-hex-color.js +1 -1
  65. package/esm/rules/format-rules/is-hex.js +1 -1
  66. package/esm/rules/format-rules/is-iban.js +2 -2
  67. package/esm/rules/format-rules/is-ip.js +2 -2
  68. package/esm/rules/format-rules/is-issn.js +1 -2
  69. package/esm/rules/format-rules/is-jwt.js +1 -1
  70. package/esm/rules/format-rules/is-lowercase.js +2 -2
  71. package/esm/rules/format-rules/is-mac-address.js +1 -2
  72. package/esm/rules/format-rules/is-mobile-phone.js +1 -1
  73. package/esm/rules/format-rules/is-object-id.js +1 -1
  74. package/esm/rules/format-rules/is-passport-number.js +1 -1
  75. package/esm/rules/format-rules/is-port.js +1 -1
  76. package/esm/rules/format-rules/is-url.js +1 -1
  77. package/esm/rules/format-rules/is-uuid.js +1 -1
  78. package/esm/rules/format-rules/is-vat-number.js +1 -1
  79. package/esm/rules/format-rules/matches.js +1 -1
  80. package/esm/rules/logical-rules/is-defined.js +1 -1
  81. package/esm/rules/logical-rules/is-empty.js +34 -14
  82. package/esm/rules/logical-rules/range.js +5 -5
  83. package/esm/rules/type-rules/is-array.js +6 -2
  84. package/esm/rules/type-rules/is-bigint.js +1 -2
  85. package/esm/rules/type-rules/is-boolean.js +1 -2
  86. package/esm/rules/type-rules/is-date.js +4 -6
  87. package/esm/rules/type-rules/is-integer.js +1 -6
  88. package/esm/rules/type-rules/is-null.js +1 -1
  89. package/esm/rules/type-rules/is-number.js +1 -6
  90. package/esm/rules/type-rules/is-object.js +1 -1
  91. package/esm/rules/type-rules/is-record.js +6 -4
  92. package/esm/rules/type-rules/is-string.js +1 -1
  93. package/esm/rules/type-rules/is-tuple.js +1 -1
  94. package/esm/rules/type-rules/is-undefined.js +1 -1
  95. package/esm/rules/utility-rules/get-length.js +1 -1
  96. package/esm/rules/utility-rules/required.js +1 -1
  97. package/esm/tsconfig-build-esm.tsbuildinfo +1 -1
  98. package/package.json +3 -3
  99. package/types/core/context.d.ts +1 -0
  100. package/types/index.d.cts +1 -1
  101. package/types/index.d.ts +1 -1
  102. package/types/rules/format-rules/is-object-id.d.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # v5.13.1
2
+ [2025-03-14]
3
+
4
+ ### Fixes
5
+
6
+ * fix: Fixed validation of Date, Buffer and ArrayBuffer objects of isEmpty and isNotEmpty rules ([`24992b8`](https://github.com/panates/valgen/commit/24992b845f229c8cd1e5d0049704e6c99bf5a6be))
7
+ * fix: Fixed validation of Date, Buffer and ArrayBuffer objects of isEmpty and isNotEmpty rules ([`37681bf`](https://github.com/panates/valgen/commit/37681bf88f5c0adf4f102856791b0b3a547aea74))
8
+
9
+ ### Changes
10
+
11
+ * chore: Removed Node 16 tests ([`606e01a`](https://github.com/panates/valgen/commit/606e01abb6cefd11e0dfdc6a20cb4e26371bb6e9))
12
+
13
+ # v5.13.0
14
+ [2025-02-03]
15
+
16
+ ### Changes
17
+
18
+ * refactor: Updated dependencies ([`dca11c1`](https://github.com/panates/valgen/commit/dca11c1d094daca39974bbc9c70b8f30480c4d0a))
19
+ * refactor: Changed error messages to "positive sentences" ([`3b746df`](https://github.com/panates/valgen/commit/3b746df70ab0e25e32e3f5b957f1c24f3f0fcc70))
20
+ * chore: Updated github workflow ([`661738f`](https://github.com/panates/valgen/commit/661738f1fd90eed72ec2718e67159a8ab614e65e))
21
+ * dev: Fixed ts config ([`e3251ce`](https://github.com/panates/valgen/commit/e3251ce7776de3bd4afeb0c2d0ed5d19f6aabd4f))
22
+ * dev: Added missing script ([`dd019d9`](https://github.com/panates/valgen/commit/dd019d923f8305462e27cad1745564071c9c34bb))
23
+
1
24
  # v5.12.0
2
25
  [2024-11-04]
3
26
 
@@ -7,6 +7,7 @@ const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
7
7
  const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
8
8
  class Context {
9
9
  constructor(options) {
10
+ this.isRoot = true;
10
11
  this.errors = [];
11
12
  Object.assign(this, options);
12
13
  }
@@ -65,6 +66,7 @@ class Context {
65
66
  extended[k] = v;
66
67
  }
67
68
  }
69
+ extended.isRoot = false;
68
70
  Object.setPrototypeOf(extended, this);
69
71
  return extended;
70
72
  }
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ValidationError = void 0;
4
4
  class ValidationError extends Error {
5
5
  constructor(issues) {
6
- super(issues[0].message);
6
+ super(issues[0].message +
7
+ (issues[0].location ? `\n at ${issues[0].location}` : ''));
7
8
  this.issues = [];
8
9
  this.issues = issues;
9
10
  }
@@ -26,11 +26,17 @@ function validator(arg0, arg1, arg2) {
26
26
  id = id || fn.name || 'validator' + ++unnamedValidatorIndex;
27
27
  const name = fn.name || (0, string_utils_js_1.camelCase)(id);
28
28
  const _rule = {
29
- [name](input, options) {
30
- const ctx = options instanceof context_js_1.Context ? options : undefined;
31
- const opts = ctx ? undefined : options;
32
- const context = ctx?.extend({ ...validatorOptions, ...opts }) ||
33
- new context_js_1.Context({ ...validatorOptions, ...opts });
29
+ [name](input, options, context) {
30
+ if (context) {
31
+ if (options || validatorOptions)
32
+ context = context.extend({ ...validatorOptions, ...options });
33
+ }
34
+ else {
35
+ context =
36
+ options instanceof context_js_1.Context
37
+ ? options.extend({ ...validatorOptions })
38
+ : new context_js_1.Context({ ...validatorOptions, ...options });
39
+ }
34
40
  let value;
35
41
  try {
36
42
  value = fn(input, context, _rule);
@@ -40,7 +46,7 @@ function validator(arg0, arg1, arg2) {
40
46
  throw e;
41
47
  context.fail(_rule, e, input);
42
48
  }
43
- if (!ctx && context.errors.length) {
49
+ if (context.isRoot && context.errors.length) {
44
50
  throw new validation_error_js_1.ValidationError(context.errors);
45
51
  }
46
52
  return value;
@@ -13,7 +13,7 @@ function isAlpha(options) {
13
13
  return (0, index_js_1.validator)('isLowercase', (input, context, _this) => {
14
14
  if (typeof input === 'string' && validator_1.default.isAlpha(input))
15
15
  return input;
16
- context.fail(_this, `"{{value}}" is not an alpha string`, input);
16
+ context.fail(_this, `"Value must be an alpha string`, input);
17
17
  }, options);
18
18
  }
19
19
  /**
@@ -25,6 +25,6 @@ function isAlphanumeric(options) {
25
25
  if (typeof input === 'string' && validator_1.default.isAlphanumeric(input)) {
26
26
  return input;
27
27
  }
28
- context.fail(_this, `"{{value}}" is not an alphanumeric string`, input);
28
+ context.fail(_this, `"Value must be an alphanumeric string`, input);
29
29
  }, options);
30
30
  }
@@ -12,6 +12,6 @@ function isAscii(options) {
12
12
  return (0, index_js_1.validator)('isAscii', (input, context, _this) => {
13
13
  if (typeof input === 'string' && validator_1.default.isAscii(input))
14
14
  return input;
15
- context.fail(_this, `Value is not an ascii string`, input);
15
+ context.fail(_this, `Value must be an ascii string`, input);
16
16
  }, options);
17
17
  }
@@ -13,6 +13,6 @@ function isBase64(options) {
13
13
  if (typeof input === 'string' && validator_1.default.isBase64(input, options)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `"{{value}}" is not a valid a Base64 string`, input);
16
+ context.fail(_this, `"Value must be a Base64 string`, input);
17
17
  }, options);
18
18
  }
@@ -13,6 +13,6 @@ function isBtcAddress(options) {
13
13
  if (typeof input === 'string' && validator_1.default.isBtcAddress(input)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `Value is not a valid a BTC address`, input);
16
+ context.fail(_this, `Value must be a valid BTC address`, input);
17
17
  }, options);
18
18
  }
@@ -14,6 +14,6 @@ function isCreditCard(options) {
14
14
  validator_1.default.isCreditCard(input, options)) {
15
15
  return input;
16
16
  }
17
- context.fail(_this, `"{{value}}" is not a valid Credit Card number`, input);
17
+ context.fail(_this, `Value must be a valid Credit Card number`, input);
18
18
  }, options);
19
19
  }
@@ -14,6 +14,6 @@ function isDecimal(options) {
14
14
  if (typeof input === 'string' && validator_1.default.isDecimal(input)) {
15
15
  return input;
16
16
  }
17
- context.fail(_this, `"{{value}}" is not an decimal number string`, input);
17
+ context.fail(_this, `Value must be a decimal number string`, input);
18
18
  }, options);
19
19
  }
@@ -12,6 +12,6 @@ function isEAN(options) {
12
12
  return (0, index_js_1.validator)('isEAN', (input, context, _this) => {
13
13
  if (typeof input === 'string' && validator_1.default.isEAN(input))
14
14
  return input;
15
- context.fail(_this, `"{{value}}" is not a valid EAN (European Article Number)`, input);
15
+ context.fail(_this, `Value must be a valid EAN (European Article Number)`, input);
16
16
  }, options);
17
17
  }
@@ -10,13 +10,9 @@ const index_js_1 = require("../../core/index.js");
10
10
  */
11
11
  function isEmail(options) {
12
12
  const emailOptions = {
13
- // eslint-disable-next-line camelcase
14
13
  allow_display_name: true,
15
- // eslint-disable-next-line camelcase
16
14
  allow_utf8_local_part: options?.utf8LocalPart,
17
- // eslint-disable-next-line camelcase
18
15
  ignore_max_length: true,
19
- // eslint-disable-next-line camelcase
20
16
  allow_ip_domain: options?.allowIpDomain,
21
17
  };
22
18
  return (0, index_js_1.validator)('isEmail', (input, context, _this) => {
@@ -25,7 +21,6 @@ function isEmail(options) {
25
21
  if (options?.requireDisplayName) {
26
22
  if (!validator_1.default.isEmail(input, {
27
23
  ...emailOptions,
28
- // eslint-disable-next-line camelcase
29
24
  require_display_name: true,
30
25
  })) {
31
26
  context.fail(_this, `Display name for the email is required. Etc. ( Name <me@tempuri.org> ) `, input);
@@ -35,7 +30,6 @@ function isEmail(options) {
35
30
  else if (!options?.allowDisplayName &&
36
31
  !validator_1.default.isEmail(input, {
37
32
  ...emailOptions,
38
- // eslint-disable-next-line camelcase
39
33
  allow_display_name: false,
40
34
  })) {
41
35
  context.fail(_this, `Display name in email is not allowed`, input);
@@ -44,7 +38,6 @@ function isEmail(options) {
44
38
  if (options?.hostBlacklist &&
45
39
  !validator_1.default.isEmail(input, {
46
40
  ...emailOptions,
47
- // eslint-disable-next-line camelcase
48
41
  host_blacklist: options.hostBlacklist,
49
42
  })) {
50
43
  context.fail(_this, `Email "{{value}}" is in black-list`, input);
@@ -53,7 +46,6 @@ function isEmail(options) {
53
46
  if (options?.hostWhitelist &&
54
47
  !validator_1.default.isEmail(input, {
55
48
  ...emailOptions,
56
- // eslint-disable-next-line camelcase
57
49
  host_whitelist: options.hostWhitelist,
58
50
  })) {
59
51
  context.fail(_this, `Email "{{value}}" is in not white-list`, input);
@@ -62,7 +54,6 @@ function isEmail(options) {
62
54
  if (options?.blacklistedChars &&
63
55
  !validator_1.default.isEmail(input, {
64
56
  ...emailOptions,
65
- // eslint-disable-next-line camelcase
66
57
  blacklisted_chars: options.blacklistedChars,
67
58
  })) {
68
59
  context.fail(_this, `Black listed characters (${options.blacklistedChars}) found in name part`, input);
@@ -70,6 +61,6 @@ function isEmail(options) {
70
61
  }
71
62
  return input;
72
63
  }
73
- context.fail(_this, `"{{value}}" does not match required e-mail format`, input);
64
+ context.fail(_this, `Value must much required e-mail format`, input);
74
65
  }, options);
75
66
  }
@@ -13,6 +13,6 @@ function isETHAddress(options) {
13
13
  if (typeof input === 'string' && validator_1.default.isEthereumAddress(input)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `Value is not a valid a ETH (Ethereum) address`, input);
16
+ context.fail(_this, `Value must be valid ETH (Ethereum) address`, input);
17
17
  }, options);
18
18
  }
@@ -10,13 +10,12 @@ const index_js_1 = require("../../core/index.js");
10
10
  */
11
11
  function isFQDN(options) {
12
12
  const opts = {
13
- // eslint-disable-next-line camelcase
14
13
  allow_wildcard: options?.allowWildcard,
15
14
  };
16
15
  return (0, index_js_1.validator)('isFQDN', (input, context, _this) => {
17
16
  if (typeof input === 'string' && validator_1.default.isFQDN(input, opts)) {
18
17
  return input;
19
18
  }
20
- context.fail(_this, `"{{value}}" is not valid FQDN`, input);
19
+ context.fail(_this, `Value must be valid FQDN`, input);
21
20
  }, options);
22
21
  }
@@ -13,6 +13,6 @@ function isHash(algorithm, options) {
13
13
  if (typeof input === 'string' && validator_1.default.isHash(input, algorithm)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `Value is not a valid ${algorithm} hash`, input);
16
+ context.fail(_this, `Value must be a valid ${algorithm} hash`, input);
17
17
  }, options);
18
18
  }
@@ -13,6 +13,6 @@ function isHexColor(options) {
13
13
  if (typeof input === 'string' && validator_1.default.isHexColor(input)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `{{label}} is not a valid Hex Color`, input);
16
+ context.fail(_this, `Value must be a valid Hex Color`, input);
17
17
  }, options);
18
18
  }
@@ -13,6 +13,6 @@ function isHex(options) {
13
13
  if (typeof input === 'string' && validator_1.default.isHexadecimal(input)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `{{label}} is not an hexadecimal string`, input);
16
+ context.fail(_this, `Value must be an hexadecimal string`, input);
17
17
  }, options);
18
18
  }
@@ -13,7 +13,7 @@ function isIBAN(options) {
13
13
  return (0, index_js_1.validator)('isIBAN', (input, context, _this) => {
14
14
  if (typeof input === 'string' && validator_1.default.isIBAN(input))
15
15
  return input;
16
- context.fail(_this, `{{label}} is not a valid IBAN (International Bank Account Number)`, input);
16
+ context.fail(_this, `Value must be a valid IBAN (International Bank Account Number)`, input);
17
17
  }, options);
18
18
  }
19
19
  /**
@@ -24,6 +24,6 @@ function isSWIFT(options) {
24
24
  return (0, index_js_1.validator)('isSWIFT', (input, context, _this) => {
25
25
  if (typeof input === 'string' && validator_1.default.isBIC(input))
26
26
  return input;
27
- context.fail(_this, `{{label}}is not a valid a BIC (Bank Identification Code) or SWIFT code`, input);
27
+ context.fail(_this, `Value must be a valid a BIC (Bank Identification Code) or SWIFT code`, input);
28
28
  }, options);
29
29
  }
@@ -16,7 +16,7 @@ function isIP(version, options) {
16
16
  validator_1.default.isIP(input, version)) {
17
17
  return input;
18
18
  }
19
- context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''}`, input);
19
+ context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''}`, input);
20
20
  }, options);
21
21
  }
22
22
  /**
@@ -30,6 +30,6 @@ function isIPRange(version, options) {
30
30
  validator_1.default.isIPRange(input, version)) {
31
31
  return input;
32
32
  }
33
- context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''} range`, input);
33
+ context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''} range`, input);
34
34
  }, options);
35
35
  }
@@ -10,13 +10,12 @@ const index_js_1 = require("../../core/index.js");
10
10
  */
11
11
  function isISSN(options) {
12
12
  const opts = {
13
- // eslint-disable-next-line camelcase
14
13
  case_sensitive: options?.caseSensitive,
15
14
  };
16
15
  return (0, index_js_1.validator)('isISSN', (input, context, _this) => {
17
16
  if (typeof input === 'string' && validator_1.default.isISSN(input, opts)) {
18
17
  return input;
19
18
  }
20
- context.fail(_this, `"{{value}}" is not a valid ISSN`, input);
19
+ context.fail(_this, `Value must be a valid ISSN`, input);
21
20
  }, options);
22
21
  }
@@ -12,6 +12,6 @@ function isJWT(options) {
12
12
  return (0, index_js_1.validator)('isJWT', (input, context, _this) => {
13
13
  if (typeof input === 'string' && validator_1.default.isJWT(input))
14
14
  return input;
15
- context.fail(_this, `Value is not a valid JWT token`, input);
15
+ context.fail(_this, `Value must be valid JWT token`, input);
16
16
  }, options);
17
17
  }
@@ -14,7 +14,7 @@ function isLowercase(options) {
14
14
  if (typeof input === 'string' && validator_1.default.isLowercase(input)) {
15
15
  return input;
16
16
  }
17
- context.fail(_this, `"{{value}}" is not a lowercase string`, input);
17
+ context.fail(_this, `Value must be a lowercase string`, input);
18
18
  }, options);
19
19
  }
20
20
  /**
@@ -26,6 +26,6 @@ function isUppercase(options) {
26
26
  if (typeof input === 'string' && validator_1.default.isUppercase(input)) {
27
27
  return input;
28
28
  }
29
- context.fail(_this, `"{{value}}" is not an uppercase string`, input);
29
+ context.fail(_this, `Value must be an uppercase string`, input);
30
30
  }, options);
31
31
  }
@@ -10,7 +10,6 @@ const index_js_1 = require("../../core/index.js");
10
10
  */
11
11
  function isMACAddress(options) {
12
12
  const opts = {
13
- // eslint-disable-next-line camelcase
14
13
  no_separators: options?.noSeparators,
15
14
  eui: options?.eui,
16
15
  };
@@ -20,6 +19,6 @@ function isMACAddress(options) {
20
19
  validator_1.default.isMACAddress(input, opts)) {
21
20
  return input;
22
21
  }
23
- context.fail(_this, `{{label}} is not a valid MAC address`, input);
22
+ context.fail(_this, `Value must be a valid MAC address`, input);
24
23
  }, options);
25
24
  }
@@ -17,6 +17,6 @@ function isMobilePhone(options) {
17
17
  validator_1.default.isMobilePhone(input, options?.locale, opts)) {
18
18
  return input;
19
19
  }
20
- context.fail(_this, `"{{value}}" is not a valid a Mobile Phone Number`, input);
20
+ context.fail(_this, `Value must be a valid a Mobile Phone Number`, input);
21
21
  }, options);
22
22
  }
@@ -17,7 +17,7 @@ function isObjectId(options) {
17
17
  _isObjectIdValue(input.toHexString())))) {
18
18
  return input;
19
19
  }
20
- context.fail(_this, `"{{value}}" is not a valid ObjectId`, input);
20
+ context.fail(_this, `Value must be a valid ObjectId`, input);
21
21
  }, options);
22
22
  }
23
23
  function _isObjectIdValue(input) {
@@ -14,6 +14,6 @@ function isPassportNumber(countryCode, options) {
14
14
  validator_1.default.isPassportNumber(input, countryCode)) {
15
15
  return input;
16
16
  }
17
- context.fail(_this, `"{{value}}" is not a valid ${countryCode} PassportNumber)`, input);
17
+ context.fail(_this, `Value must be a valid ${countryCode} PassportNumber)`, input);
18
18
  }, options);
19
19
  }
@@ -17,6 +17,6 @@ function isPort(options) {
17
17
  validator_1.default.isPort(input)) {
18
18
  return parseInt(input, 10);
19
19
  }
20
- context.fail(_this, `{{label}} is not a valid port number`, input);
20
+ context.fail(_this, `Value must be a valid port number`, input);
21
21
  }, options);
22
22
  }
@@ -15,6 +15,6 @@ function isURL(options) {
15
15
  validator_1.default.isURL(input, options)) {
16
16
  return input;
17
17
  }
18
- context.fail(_this, `{{value}} is not a valid URL`, input);
18
+ context.fail(_this, `Value must be a valid URL`, input);
19
19
  }, options);
20
20
  }
@@ -15,6 +15,6 @@ function isUUID(version, options) {
15
15
  validator_1.default.isUUID(input, version)) {
16
16
  return input;
17
17
  }
18
- context.fail(_this, `{{label}} is not a valid UUID${version ? ' v' + version : ''}`, input);
18
+ context.fail(_this, `Value must be a valid UUID${version ? ' v' + version : ''}`, input);
19
19
  }, options);
20
20
  }
@@ -13,6 +13,6 @@ function isVATNumber(countryCode, options) {
13
13
  if (typeof input === 'string' && validator_1.default.isVAT(input, countryCode)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `"{{value}}" is not a valid VAT number`, input);
16
+ context.fail(_this, `Value must be a valid VAT number`, input);
17
17
  }, options);
18
18
  }
@@ -14,7 +14,7 @@ function matches(format, options) {
14
14
  return;
15
15
  if (typeof input === 'string' && regExp.test(input))
16
16
  return input;
17
- context.fail(_this, `"{{value}}" does not match ${formatName || 'requested'} format`, input, {
17
+ context.fail(_this, `Value must match ${formatName || 'requested'} format`, input, {
18
18
  format,
19
19
  formatName,
20
20
  });
@@ -10,6 +10,6 @@ function isDefined(options) {
10
10
  return (0, index_js_1.validator)('is-defined', (input, context, _this) => {
11
11
  if (input !== undefined)
12
12
  return input;
13
- context.fail(_this, `Is not defined`, input);
13
+ context.fail(_this, `Value must be defined`, input);
14
14
  }, options);
15
15
  }
@@ -14,29 +14,39 @@ function isEmpty(options) {
14
14
  if (typeof input === 'string') {
15
15
  if (!input)
16
16
  return input;
17
- context.fail(_this, `Is not an empty string`, input);
17
+ context.fail(_this, `Value must be an empty string`, input);
18
18
  }
19
19
  else if (Array.isArray(input)) {
20
20
  if (!input.length)
21
21
  return input;
22
- context.fail(_this, `Is not an empty array`, input);
22
+ context.fail(_this, `Value must be an empty array`, input);
23
23
  }
24
24
  else if (input instanceof Set) {
25
25
  if (!input.size)
26
26
  return input;
27
- context.fail(_this, `Is not an empty Set`, input);
27
+ context.fail(_this, `Value must be an empty Set`, input);
28
28
  }
29
29
  else if (input instanceof Map) {
30
30
  if (!input.size)
31
31
  return input;
32
- context.fail(_this, `Is not an empty Map`, input);
32
+ context.fail(_this, `Value must be an empty Map`, input);
33
+ }
34
+ else if (Buffer.isBuffer(input)) {
35
+ if (!input.length)
36
+ return input;
37
+ context.fail(_this, `Value must be an empty Buffer`, input);
38
+ }
39
+ else if (input instanceof ArrayBuffer) {
40
+ if (!input.byteLength)
41
+ return input;
42
+ context.fail(_this, `Value must be an empty ArrayBuffer`, input);
33
43
  }
34
44
  else if (typeof input === 'object') {
35
- if (!Object.keys(input).length)
45
+ if (input instanceof Date || !Object.keys(input).length)
36
46
  return input;
37
- context.fail(_this, `Is not an empty Object`, input);
47
+ context.fail(_this, `Value must be an empty Object`, input);
38
48
  }
39
- context.fail(_this, `Is not empty`, input);
49
+ context.fail(_this, `Value must be empty`, input);
40
50
  }, options);
41
51
  }
42
52
  /**
@@ -49,29 +59,39 @@ function isNotEmpty(options) {
49
59
  if (typeof input === 'string') {
50
60
  if (input)
51
61
  return input;
52
- context.fail(_this, `Value is an empty string`, input);
62
+ context.fail(_this, `Value must not be empty`, input);
53
63
  }
54
64
  else if (Array.isArray(input)) {
55
65
  if (input.length)
56
66
  return input;
57
- context.fail(_this, `Value is an empty array`, input);
67
+ context.fail(_this, `Array must not be empty`, input);
58
68
  }
59
69
  else if (input instanceof Set) {
60
70
  if (input.size)
61
71
  return input;
62
- context.fail(_this, `Value is an empty Set`, input);
72
+ context.fail(_this, `Set must not be empty`, input);
63
73
  }
64
74
  else if (input instanceof Map) {
65
75
  if (input.size)
66
76
  return input;
67
- context.fail(_this, `Value is an empty Map`, input);
77
+ context.fail(_this, `Map must not be empty`, input);
78
+ }
79
+ else if (Buffer.isBuffer(input)) {
80
+ if (input.length)
81
+ return input;
82
+ context.fail(_this, `Buffer must not be empty`, input);
83
+ }
84
+ else if (input instanceof ArrayBuffer) {
85
+ if (input.byteLength)
86
+ return input;
87
+ context.fail(_this, `ArrayBuffer must not be empty`, input);
68
88
  }
69
89
  else if (typeof input === 'object') {
70
- if (Object.keys(input).length)
90
+ if (input instanceof Date || Object.keys(input).length)
71
91
  return input;
72
- context.fail(_this, `Value is an empty Object`, input);
92
+ context.fail(_this, `Object must not be empty`, input);
73
93
  }
74
94
  }
75
- context.fail(_this, `Value is empty`, input);
95
+ context.fail(_this, `Value must not be empty`, input);
76
96
  }, options);
77
97
  }
@@ -58,7 +58,7 @@ function isGt(minValue, options) {
58
58
  input.toLowerCase() > minValue.toLowerCase()))) {
59
59
  return input;
60
60
  }
61
- context.fail(_this, `{{label}} must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
61
+ context.fail(_this, `Value must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
62
62
  }, options);
63
63
  }
64
64
  function isGte(minValue, options) {
@@ -80,7 +80,7 @@ function isGte(minValue, options) {
80
80
  input.toLowerCase() >= minValue.toLowerCase()))) {
81
81
  return input;
82
82
  }
83
- context.fail(_this, `{{label}} must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
83
+ context.fail(_this, `Value must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
84
84
  }, options);
85
85
  }
86
86
  function isLt(maxValue, options) {
@@ -102,7 +102,7 @@ function isLt(maxValue, options) {
102
102
  input.toLowerCase() < maxValue.toLowerCase()))) {
103
103
  return input;
104
104
  }
105
- context.fail(_this, `{{label}} must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
105
+ context.fail(_this, `Value must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
106
106
  }, options);
107
107
  }
108
108
  function isLte(maxValue, options) {
@@ -124,7 +124,7 @@ function isLte(maxValue, options) {
124
124
  input.toLowerCase() <= maxValue.toLowerCase()))) {
125
125
  return input;
126
126
  }
127
- context.fail(_this, `{{label}} must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
127
+ context.fail(_this, `Value must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
128
128
  }, options);
129
129
  }
130
130
  /**
@@ -135,7 +135,7 @@ const lengthMin = (minValue) => (0, pipe_js_1.allOf)([
135
135
  (0, pipe_js_1.pipe)([
136
136
  (0, get_length_js_1.getLength)(),
137
137
  isGte(minValue, {
138
- onFail: () => `The length of {{label}} must be at least ${minValue}`,
138
+ onFail: () => `Value length must be at least ${minValue}`,
139
139
  }),
140
140
  ]),
141
141
  ]);
@@ -14,7 +14,7 @@ function isArray(itemValidator, options) {
14
14
  if (output != null && coerce && !Array.isArray(output))
15
15
  output = [output];
16
16
  if (!Array.isArray(output)) {
17
- context.fail(_this, `"{{value}}" is not an array value`, input);
17
+ context.fail(_this, `Value must be an array`, input);
18
18
  return;
19
19
  }
20
20
  if (!itemValidator)
@@ -33,7 +33,11 @@ function isArray(itemValidator, options) {
33
33
  ? context.location + `[${i}]`
34
34
  : `<Array>[${i}]`;
35
35
  itemContext.index = i;
36
- v = itemValidator(v, itemContext);
36
+ v = itemValidator(v, {
37
+ onFail(issue) {
38
+ return `Item at index [${i}] is not a valid. ` + issue.message;
39
+ },
40
+ }, itemContext);
37
41
  out.push(v);
38
42
  }
39
43
  return out;
@@ -16,7 +16,6 @@ function isBigint(options) {
16
16
  (typeof input === 'string' && coerce)) {
17
17
  return BigInt(input);
18
18
  }
19
- const t = typeof input === 'string' ? 'String ' : '';
20
- context.fail(_this, `${t}"{{value}}" is not a valid BigInt value`, input);
19
+ context.fail(_this, `Value must be a BigInt`, input);
21
20
  }, options);
22
21
  }
@@ -26,7 +26,6 @@ function isBoolean(options) {
26
26
  }
27
27
  if (typeof output === 'boolean')
28
28
  return output;
29
- const t = typeof input === 'string' ? 'String ' : '';
30
- context.fail(_this, `${t}"{{value}}" is not a valid boolean value`, input);
29
+ context.fail(_this, `Value must be a boolean`, input);
31
30
  }, options);
32
31
  }