valgen 5.10.0 → 5.13.0

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 (108) hide show
  1. package/CHANGELOG.md +25 -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 +5 -5
  6. package/cjs/rules/format-rules/is-ascii.js +3 -3
  7. package/cjs/rules/format-rules/is-base64.js +3 -3
  8. package/cjs/rules/format-rules/is-btc-address.js +3 -3
  9. package/cjs/rules/format-rules/is-credit-card.js +3 -3
  10. package/cjs/rules/format-rules/is-decimal.js +3 -3
  11. package/cjs/rules/format-rules/is-ean.js +3 -3
  12. package/cjs/rules/format-rules/is-email.js +8 -17
  13. package/cjs/rules/format-rules/is-eth-address.js +3 -3
  14. package/cjs/rules/format-rules/is-fqdn.js +3 -4
  15. package/cjs/rules/format-rules/is-hash.js +3 -3
  16. package/cjs/rules/format-rules/is-hex-color.js +3 -3
  17. package/cjs/rules/format-rules/is-hex.js +3 -3
  18. package/cjs/rules/format-rules/is-iban.js +5 -5
  19. package/cjs/rules/format-rules/is-ip.js +5 -5
  20. package/cjs/rules/format-rules/is-issn.js +3 -4
  21. package/cjs/rules/format-rules/is-jwt.js +3 -3
  22. package/cjs/rules/format-rules/is-lowercase.js +5 -5
  23. package/cjs/rules/format-rules/is-mac-address.js +3 -4
  24. package/cjs/rules/format-rules/is-mobile-phone.js +3 -3
  25. package/cjs/rules/format-rules/is-object-id.js +2 -2
  26. package/cjs/rules/format-rules/is-passport-number.js +3 -3
  27. package/cjs/rules/format-rules/is-port.js +6 -4
  28. package/cjs/rules/format-rules/is-url.js +3 -3
  29. package/cjs/rules/format-rules/is-uuid.js +3 -3
  30. package/cjs/rules/format-rules/is-vat-number.js +3 -3
  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 +12 -12
  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 +3 -3
  54. package/esm/rules/format-rules/is-ascii.js +2 -2
  55. package/esm/rules/format-rules/is-base64.js +2 -2
  56. package/esm/rules/format-rules/is-btc-address.js +2 -2
  57. package/esm/rules/format-rules/is-credit-card.js +2 -2
  58. package/esm/rules/format-rules/is-decimal.js +2 -2
  59. package/esm/rules/format-rules/is-ean.js +2 -2
  60. package/esm/rules/format-rules/is-email.js +2 -11
  61. package/esm/rules/format-rules/is-eth-address.js +2 -2
  62. package/esm/rules/format-rules/is-fqdn.js +2 -3
  63. package/esm/rules/format-rules/is-hash.js +2 -2
  64. package/esm/rules/format-rules/is-hex-color.js +2 -2
  65. package/esm/rules/format-rules/is-hex.js +2 -2
  66. package/esm/rules/format-rules/is-iban.js +3 -3
  67. package/esm/rules/format-rules/is-ip.js +3 -3
  68. package/esm/rules/format-rules/is-issn.js +2 -3
  69. package/esm/rules/format-rules/is-jwt.js +2 -2
  70. package/esm/rules/format-rules/is-lowercase.js +3 -3
  71. package/esm/rules/format-rules/is-mac-address.js +2 -3
  72. package/esm/rules/format-rules/is-mobile-phone.js +2 -2
  73. package/esm/rules/format-rules/is-object-id.js +2 -2
  74. package/esm/rules/format-rules/is-passport-number.js +2 -2
  75. package/esm/rules/format-rules/is-port.js +5 -3
  76. package/esm/rules/format-rules/is-url.js +2 -2
  77. package/esm/rules/format-rules/is-uuid.js +2 -2
  78. package/esm/rules/format-rules/is-vat-number.js +2 -2
  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 +12 -12
  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 +5 -5
  99. package/types/core/context.d.ts +1 -0
  100. package/types/index.d.cts +2 -2
  101. package/types/index.d.ts +2 -2
  102. package/types/rules/format-rules/is-base64.d.ts +1 -1
  103. package/types/rules/format-rules/is-credit-card.d.ts +1 -1
  104. package/types/rules/format-rules/is-hash.d.ts +1 -1
  105. package/types/rules/format-rules/is-mobile-phone.d.ts +1 -1
  106. package/types/rules/format-rules/is-object-id.d.ts +1 -1
  107. package/types/rules/format-rules/is-port.d.ts +1 -1
  108. package/types/rules/format-rules/is-url.d.ts +1 -1
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Check if the string represents a decimal number,
@@ -10,6 +10,6 @@ export function isDecimal(options) {
10
10
  if (typeof input === 'string' && validatorJS.isDecimal(input)) {
11
11
  return input;
12
12
  }
13
- context.fail(_this, `"{{value}}" is not an decimal number string`, input);
13
+ context.fail(_this, `Value must be a decimal number string`, input);
14
14
  }, options);
15
15
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an EAN (European Article Number)
@@ -8,6 +8,6 @@ export function isEAN(options) {
8
8
  return validator('isEAN', (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isEAN(input))
10
10
  return input;
11
- context.fail(_this, `"{{value}}" is not a valid EAN (European Article Number)`, input);
11
+ context.fail(_this, `Value must be a valid EAN (European Article Number)`, input);
12
12
  }, options);
13
13
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is a valid Email
@@ -6,13 +6,9 @@ import { validator, } from '../../core/index.js';
6
6
  */
7
7
  export function isEmail(options) {
8
8
  const emailOptions = {
9
- // eslint-disable-next-line camelcase
10
9
  allow_display_name: true,
11
- // eslint-disable-next-line camelcase
12
10
  allow_utf8_local_part: options?.utf8LocalPart,
13
- // eslint-disable-next-line camelcase
14
11
  ignore_max_length: true,
15
- // eslint-disable-next-line camelcase
16
12
  allow_ip_domain: options?.allowIpDomain,
17
13
  };
18
14
  return validator('isEmail', (input, context, _this) => {
@@ -21,7 +17,6 @@ export function isEmail(options) {
21
17
  if (options?.requireDisplayName) {
22
18
  if (!validatorJS.isEmail(input, {
23
19
  ...emailOptions,
24
- // eslint-disable-next-line camelcase
25
20
  require_display_name: true,
26
21
  })) {
27
22
  context.fail(_this, `Display name for the email is required. Etc. ( Name <me@tempuri.org> ) `, input);
@@ -31,7 +26,6 @@ export function isEmail(options) {
31
26
  else if (!options?.allowDisplayName &&
32
27
  !validatorJS.isEmail(input, {
33
28
  ...emailOptions,
34
- // eslint-disable-next-line camelcase
35
29
  allow_display_name: false,
36
30
  })) {
37
31
  context.fail(_this, `Display name in email is not allowed`, input);
@@ -40,7 +34,6 @@ export function isEmail(options) {
40
34
  if (options?.hostBlacklist &&
41
35
  !validatorJS.isEmail(input, {
42
36
  ...emailOptions,
43
- // eslint-disable-next-line camelcase
44
37
  host_blacklist: options.hostBlacklist,
45
38
  })) {
46
39
  context.fail(_this, `Email "{{value}}" is in black-list`, input);
@@ -49,7 +42,6 @@ export function isEmail(options) {
49
42
  if (options?.hostWhitelist &&
50
43
  !validatorJS.isEmail(input, {
51
44
  ...emailOptions,
52
- // eslint-disable-next-line camelcase
53
45
  host_whitelist: options.hostWhitelist,
54
46
  })) {
55
47
  context.fail(_this, `Email "{{value}}" is in not white-list`, input);
@@ -58,7 +50,6 @@ export function isEmail(options) {
58
50
  if (options?.blacklistedChars &&
59
51
  !validatorJS.isEmail(input, {
60
52
  ...emailOptions,
61
- // eslint-disable-next-line camelcase
62
53
  blacklisted_chars: options.blacklistedChars,
63
54
  })) {
64
55
  context.fail(_this, `Black listed characters (${options.blacklistedChars}) found in name part`, input);
@@ -66,6 +57,6 @@ export function isEmail(options) {
66
57
  }
67
58
  return input;
68
59
  }
69
- context.fail(_this, `"{{value}}" does not match required e-mail format`, input);
60
+ context.fail(_this, `Value must much required e-mail format`, input);
70
61
  }, options);
71
62
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is a ETH (Ethereum) address.
@@ -9,6 +9,6 @@ export function isETHAddress(options) {
9
9
  if (typeof input === 'string' && validatorJS.isEthereumAddress(input)) {
10
10
  return input;
11
11
  }
12
- context.fail(_this, `Value is not a valid a ETH (Ethereum) address`, input);
12
+ context.fail(_this, `Value must be valid ETH (Ethereum) address`, input);
13
13
  }, options);
14
14
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an FQDN
@@ -6,13 +6,12 @@ import { validator, } from '../../core/index.js';
6
6
  */
7
7
  export function isFQDN(options) {
8
8
  const opts = {
9
- // eslint-disable-next-line camelcase
10
9
  allow_wildcard: options?.allowWildcard,
11
10
  };
12
11
  return validator('isFQDN', (input, context, _this) => {
13
12
  if (typeof input === 'string' && validatorJS.isFQDN(input, opts)) {
14
13
  return input;
15
14
  }
16
- context.fail(_this, `"{{value}}" is not valid FQDN`, input);
15
+ context.fail(_this, `Value must be valid FQDN`, input);
17
16
  }, options);
18
17
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value a hash of type algorithm
@@ -9,6 +9,6 @@ export function isHash(algorithm, options) {
9
9
  if (typeof input === 'string' && validatorJS.isHash(input, algorithm)) {
10
10
  return input;
11
11
  }
12
- context.fail(_this, `Value is not a valid ${algorithm} hash`, input);
12
+ context.fail(_this, `Value must be a valid ${algorithm} hash`, input);
13
13
  }, options);
14
14
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is a Hex Color
@@ -9,6 +9,6 @@ export function isHexColor(options) {
9
9
  if (typeof input === 'string' && validatorJS.isHexColor(input)) {
10
10
  return input;
11
11
  }
12
- context.fail(_this, `{{label}} is not a valid Hex Color`, input);
12
+ context.fail(_this, `Value must be a valid Hex Color`, input);
13
13
  }, options);
14
14
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Check if the string is a hexadecimal number.
@@ -9,6 +9,6 @@ export function isHex(options) {
9
9
  if (typeof input === 'string' && validatorJS.isHexadecimal(input)) {
10
10
  return input;
11
11
  }
12
- context.fail(_this, `{{label}} is not an hexadecimal string`, input);
12
+ context.fail(_this, `Value must be an hexadecimal string`, input);
13
13
  }, options);
14
14
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an IBAN (International Bank Account Number)
@@ -8,7 +8,7 @@ export function isIBAN(options) {
8
8
  return validator('isIBAN', (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isIBAN(input))
10
10
  return input;
11
- context.fail(_this, `{{label}} is not a valid IBAN (International Bank Account Number)`, input);
11
+ context.fail(_this, `Value must be a valid IBAN (International Bank Account Number)`, input);
12
12
  }, options);
13
13
  }
14
14
  /**
@@ -19,6 +19,6 @@ export function isSWIFT(options) {
19
19
  return validator('isSWIFT', (input, context, _this) => {
20
20
  if (typeof input === 'string' && validatorJS.isBIC(input))
21
21
  return input;
22
- context.fail(_this, `{{label}}is not a valid a BIC (Bank Identification Code) or SWIFT code`, input);
22
+ context.fail(_this, `Value must be a valid a BIC (Bank Identification Code) or SWIFT code`, input);
23
23
  }, options);
24
24
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an IP
@@ -11,7 +11,7 @@ export function isIP(version, options) {
11
11
  validatorJS.isIP(input, version)) {
12
12
  return input;
13
13
  }
14
- context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''}`, input);
14
+ context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''}`, input);
15
15
  }, options);
16
16
  }
17
17
  /**
@@ -25,6 +25,6 @@ export function isIPRange(version, options) {
25
25
  validatorJS.isIPRange(input, version)) {
26
26
  return input;
27
27
  }
28
- context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''} range`, input);
28
+ context.fail(_this, `Value must be a valid IP${version ? ' v' + version : ''} range`, input);
29
29
  }, options);
30
30
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an ISSN
@@ -6,13 +6,12 @@ import { validator, } from '../../core/index.js';
6
6
  */
7
7
  export function isISSN(options) {
8
8
  const opts = {
9
- // eslint-disable-next-line camelcase
10
9
  case_sensitive: options?.caseSensitive,
11
10
  };
12
11
  return validator('isISSN', (input, context, _this) => {
13
12
  if (typeof input === 'string' && validatorJS.isISSN(input, opts)) {
14
13
  return input;
15
14
  }
16
- context.fail(_this, `"{{value}}" is not a valid ISSN`, input);
15
+ context.fail(_this, `Value must be a valid ISSN`, input);
17
16
  }, options);
18
17
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value a valid JWT token
@@ -8,6 +8,6 @@ export function isJWT(options) {
8
8
  return validator('isJWT', (input, context, _this) => {
9
9
  if (typeof input === 'string' && validatorJS.isJWT(input))
10
10
  return input;
11
- context.fail(_this, `Value is not a valid JWT token`, input);
11
+ context.fail(_this, `Value must be valid JWT token`, input);
12
12
  }, options);
13
13
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value a Lowercase string
@@ -9,7 +9,7 @@ export function isLowercase(options) {
9
9
  if (typeof input === 'string' && validatorJS.isLowercase(input)) {
10
10
  return input;
11
11
  }
12
- context.fail(_this, `"{{value}}" is not a lowercase string`, input);
12
+ context.fail(_this, `Value must be a lowercase string`, input);
13
13
  }, options);
14
14
  }
15
15
  /**
@@ -21,6 +21,6 @@ export function isUppercase(options) {
21
21
  if (typeof input === 'string' && validatorJS.isUppercase(input)) {
22
22
  return input;
23
23
  }
24
- context.fail(_this, `"{{value}}" is not an uppercase string`, input);
24
+ context.fail(_this, `Value must be an uppercase string`, input);
25
25
  }, options);
26
26
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an MACAddress
@@ -6,7 +6,6 @@ import { validator, } from '../../core/index.js';
6
6
  */
7
7
  export function isMACAddress(options) {
8
8
  const opts = {
9
- // eslint-disable-next-line camelcase
10
9
  no_separators: options?.noSeparators,
11
10
  eui: options?.eui,
12
11
  };
@@ -16,6 +15,6 @@ export function isMACAddress(options) {
16
15
  validatorJS.isMACAddress(input, opts)) {
17
16
  return input;
18
17
  }
19
- context.fail(_this, `{{label}} is not a valid MAC address`, input);
18
+ context.fail(_this, `Value must be a valid MAC address`, input);
20
19
  }, options);
21
20
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is a valid Email
@@ -13,6 +13,6 @@ export function isMobilePhone(options) {
13
13
  validatorJS.isMobilePhone(input, options?.locale, opts)) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `"{{value}}" is not a valid a Mobile Phone Number`, input);
16
+ context.fail(_this, `Value must be a valid a Mobile Phone Number`, input);
17
17
  }, options);
18
18
  }
@@ -1,4 +1,4 @@
1
- import validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an "ObjectId".
@@ -13,7 +13,7 @@ export function isObjectId(options) {
13
13
  _isObjectIdValue(input.toHexString())))) {
14
14
  return input;
15
15
  }
16
- context.fail(_this, `"{{value}}" is not a valid ObjectId`, input);
16
+ context.fail(_this, `Value must be a valid ObjectId`, input);
17
17
  }, options);
18
18
  }
19
19
  function _isObjectIdValue(input) {
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is a passport number
@@ -10,6 +10,6 @@ export function isPassportNumber(countryCode, options) {
10
10
  validatorJS.isPassportNumber(input, countryCode)) {
11
11
  return input;
12
12
  }
13
- context.fail(_this, `"{{value}}" is not a valid ${countryCode} PassportNumber)`, input);
13
+ context.fail(_this, `Value must be a valid ${countryCode} PassportNumber)`, input);
14
14
  }, options);
15
15
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is a port number
@@ -6,11 +6,13 @@ import { validator, } from '../../core/index.js';
6
6
  */
7
7
  export function isPort(options) {
8
8
  return validator('isPort', (input, context, _this) => {
9
+ if (typeof input === 'number')
10
+ input = String(input);
9
11
  if (input != null &&
10
12
  typeof input === 'string' &&
11
13
  validatorJS.isPort(input)) {
12
- return input;
14
+ return parseInt(input, 10);
13
15
  }
14
- context.fail(_this, `{{label}} is not a valid port number`, input);
16
+ context.fail(_this, `Value must be a valid port number`, input);
15
17
  }, options);
16
18
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an URL
@@ -11,6 +11,6 @@ export function isURL(options) {
11
11
  validatorJS.isURL(input, options)) {
12
12
  return input;
13
13
  }
14
- context.fail(_this, `{{value}} is not a valid URL`, input);
14
+ context.fail(_this, `Value must be a valid URL`, input);
15
15
  }, options);
16
16
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an "UUID".
@@ -11,6 +11,6 @@ export function isUUID(version, options) {
11
11
  validatorJS.isUUID(input, version)) {
12
12
  return input;
13
13
  }
14
- context.fail(_this, `{{label}} is not a valid UUID${version ? ' v' + version : ''}`, input);
14
+ context.fail(_this, `Value must be a valid UUID${version ? ' v' + version : ''}`, input);
15
15
  }, options);
16
16
  }
@@ -1,4 +1,4 @@
1
- import * as validatorJS from 'validator';
1
+ import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an VAT number
@@ -9,6 +9,6 @@ export function isVATNumber(countryCode, options) {
9
9
  if (typeof input === 'string' && validatorJS.isVAT(input, countryCode)) {
10
10
  return input;
11
11
  }
12
- context.fail(_this, `"{{value}}" is not a valid VAT number`, input);
12
+ context.fail(_this, `Value must be a valid VAT number`, input);
13
13
  }, options);
14
14
  }
@@ -11,7 +11,7 @@ export function matches(format, options) {
11
11
  return;
12
12
  if (typeof input === 'string' && regExp.test(input))
13
13
  return input;
14
- context.fail(_this, `"{{value}}" does not match ${formatName || 'requested'} format`, input, {
14
+ context.fail(_this, `Value must match ${formatName || 'requested'} format`, input, {
15
15
  format,
16
16
  formatName,
17
17
  });
@@ -7,6 +7,6 @@ export function isDefined(options) {
7
7
  return validator('is-defined', (input, context, _this) => {
8
8
  if (input !== undefined)
9
9
  return input;
10
- context.fail(_this, `Is not defined`, input);
10
+ context.fail(_this, `Value must be defined`, input);
11
11
  }, options);
12
12
  }
@@ -10,29 +10,29 @@ export function isEmpty(options) {
10
10
  if (typeof input === 'string') {
11
11
  if (!input)
12
12
  return input;
13
- context.fail(_this, `Is not an empty string`, input);
13
+ context.fail(_this, `Value must be an empty string`, input);
14
14
  }
15
15
  else if (Array.isArray(input)) {
16
16
  if (!input.length)
17
17
  return input;
18
- context.fail(_this, `Is not an empty array`, input);
18
+ context.fail(_this, `Value must be an empty array`, input);
19
19
  }
20
20
  else if (input instanceof Set) {
21
21
  if (!input.size)
22
22
  return input;
23
- context.fail(_this, `Is not an empty Set`, input);
23
+ context.fail(_this, `Value must be an empty Set`, input);
24
24
  }
25
25
  else if (input instanceof Map) {
26
26
  if (!input.size)
27
27
  return input;
28
- context.fail(_this, `Is not an empty Map`, input);
28
+ context.fail(_this, `Value must be an empty Map`, input);
29
29
  }
30
30
  else if (typeof input === 'object') {
31
31
  if (!Object.keys(input).length)
32
32
  return input;
33
- context.fail(_this, `Is not an empty Object`, input);
33
+ context.fail(_this, `Value must be an empty Object`, input);
34
34
  }
35
- context.fail(_this, `Is not empty`, input);
35
+ context.fail(_this, `Value must be empty`, input);
36
36
  }, options);
37
37
  }
38
38
  /**
@@ -45,29 +45,29 @@ export function isNotEmpty(options) {
45
45
  if (typeof input === 'string') {
46
46
  if (input)
47
47
  return input;
48
- context.fail(_this, `Value is an empty string`, input);
48
+ context.fail(_this, `Value must not be empty`, input);
49
49
  }
50
50
  else if (Array.isArray(input)) {
51
51
  if (input.length)
52
52
  return input;
53
- context.fail(_this, `Value is an empty array`, input);
53
+ context.fail(_this, `Array must not be empty`, input);
54
54
  }
55
55
  else if (input instanceof Set) {
56
56
  if (input.size)
57
57
  return input;
58
- context.fail(_this, `Value is an empty Set`, input);
58
+ context.fail(_this, `Set must not be empty`, input);
59
59
  }
60
60
  else if (input instanceof Map) {
61
61
  if (input.size)
62
62
  return input;
63
- context.fail(_this, `Value is an empty Map`, input);
63
+ context.fail(_this, `Map must not be empty`, input);
64
64
  }
65
65
  else if (typeof input === 'object') {
66
66
  if (Object.keys(input).length)
67
67
  return input;
68
- context.fail(_this, `Value is an empty Object`, input);
68
+ context.fail(_this, `Object must not be empty`, input);
69
69
  }
70
70
  }
71
- context.fail(_this, `Value is empty`, input);
71
+ context.fail(_this, `Value must not be empty`, input);
72
72
  }, options);
73
73
  }
@@ -50,7 +50,7 @@ export function isGt(minValue, options) {
50
50
  input.toLowerCase() > minValue.toLowerCase()))) {
51
51
  return input;
52
52
  }
53
- context.fail(_this, `{{label}} must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
53
+ context.fail(_this, `Value must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
54
54
  }, options);
55
55
  }
56
56
  export function isGte(minValue, options) {
@@ -72,7 +72,7 @@ export function isGte(minValue, options) {
72
72
  input.toLowerCase() >= minValue.toLowerCase()))) {
73
73
  return input;
74
74
  }
75
- context.fail(_this, `{{label}} must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
75
+ context.fail(_this, `Value must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
76
76
  }, options);
77
77
  }
78
78
  export function isLt(maxValue, options) {
@@ -94,7 +94,7 @@ export function isLt(maxValue, options) {
94
94
  input.toLowerCase() < maxValue.toLowerCase()))) {
95
95
  return input;
96
96
  }
97
- context.fail(_this, `{{label}} must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
97
+ context.fail(_this, `Value must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
98
98
  }, options);
99
99
  }
100
100
  export function isLte(maxValue, options) {
@@ -116,7 +116,7 @@ export function isLte(maxValue, options) {
116
116
  input.toLowerCase() <= maxValue.toLowerCase()))) {
117
117
  return input;
118
118
  }
119
- context.fail(_this, `{{label}} must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
119
+ context.fail(_this, `Value must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
120
120
  }, options);
121
121
  }
122
122
  /**
@@ -127,7 +127,7 @@ export const lengthMin = (minValue) => allOf([
127
127
  pipe([
128
128
  getLength(),
129
129
  isGte(minValue, {
130
- onFail: () => `The length of {{label}} must be at least ${minValue}`,
130
+ onFail: () => `Value length must be at least ${minValue}`,
131
131
  }),
132
132
  ]),
133
133
  ]);
@@ -11,7 +11,7 @@ export function isArray(itemValidator, options) {
11
11
  if (output != null && coerce && !Array.isArray(output))
12
12
  output = [output];
13
13
  if (!Array.isArray(output)) {
14
- context.fail(_this, `"{{value}}" is not an array value`, input);
14
+ context.fail(_this, `Value must be an array`, input);
15
15
  return;
16
16
  }
17
17
  if (!itemValidator)
@@ -30,7 +30,11 @@ export function isArray(itemValidator, options) {
30
30
  ? context.location + `[${i}]`
31
31
  : `<Array>[${i}]`;
32
32
  itemContext.index = i;
33
- v = itemValidator(v, itemContext);
33
+ v = itemValidator(v, {
34
+ onFail(issue) {
35
+ return `Item at index [${i}] is not a valid. ` + issue.message;
36
+ },
37
+ }, itemContext);
34
38
  out.push(v);
35
39
  }
36
40
  return out;
@@ -13,7 +13,6 @@ export function isBigint(options) {
13
13
  (typeof input === 'string' && coerce)) {
14
14
  return BigInt(input);
15
15
  }
16
- const t = typeof input === 'string' ? 'String ' : '';
17
- context.fail(_this, `${t}"{{value}}" is not a valid BigInt value`, input);
16
+ context.fail(_this, `Value must be a BigInt`, input);
18
17
  }, options);
19
18
  }
@@ -23,7 +23,6 @@ export function isBoolean(options) {
23
23
  }
24
24
  if (typeof output === 'boolean')
25
25
  return output;
26
- const t = typeof input === 'string' ? 'String ' : '';
27
- context.fail(_this, `${t}"{{value}}" is not a valid boolean value`, input);
26
+ context.fail(_this, `Value must be a boolean`, input);
28
27
  }, options);
29
28
  }
@@ -1,9 +1,7 @@
1
1
  import { formatISO, parseISO } from 'date-fns';
2
2
  import { validator, } from '../../core/index.js';
3
- /* eslint-disable-next-line max-len */ // noinspection RegExpUnnecessaryNonCapturingGroup
4
- const DATE_PATTERN =
5
- // eslint-disable-next-line max-len
6
- /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
3
+ // noinspection RegExpUnnecessaryNonCapturingGroup
4
+ const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
7
5
  /**
8
6
  * Validates if value is instance of "Date".
9
7
  * Converts input value to Date if coerce option is set to 'true'.
@@ -36,7 +34,7 @@ export function isDate(options) {
36
34
  d.setHours(0, 0, 0, 0);
37
35
  return d;
38
36
  }
39
- context.fail(_this, `"{{value}}" is not a valid date value`, input, {
37
+ context.fail(_this, `Value must be a valid date`, input, {
40
38
  ...options,
41
39
  });
42
40
  }, options);
@@ -89,7 +87,7 @@ export function isDateString(options) {
89
87
  ? formatISO(input, { representation: 'date' })
90
88
  : formatISO(input).substring(0, 19);
91
89
  }
92
- context.fail(_this, `"{{value}}" is not a valid date string`, input, {
90
+ context.fail(_this, `Value must be a valid date string`, input, {
93
91
  ...options,
94
92
  });
95
93
  }, options);
@@ -22,11 +22,6 @@ export function isInteger(options) {
22
22
  Number.isInteger(output)) {
23
23
  return output;
24
24
  }
25
- const t = typeof input === 'bigint'
26
- ? 'BigInt '
27
- : typeof input === 'string'
28
- ? 'String '
29
- : '';
30
- context.fail(_this, `${t}"{{value}}" is not a valid integer value`, input);
25
+ context.fail(_this, `Value must be a valid integer value`, input);
31
26
  }, options);
32
27
  }