valgen 5.3.0 → 5.3.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 (172) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/cjs/core/context.js +2 -3
  3. package/cjs/core/validator.js +4 -4
  4. package/cjs/index.js +5 -5
  5. package/cjs/rules/format-rules/is-alpha.js +52 -0
  6. package/cjs/rules/format-rules/is-ascii.js +40 -0
  7. package/cjs/rules/format-rules/is-base64.js +40 -0
  8. package/cjs/rules/format-rules/is-btc-address.js +40 -0
  9. package/cjs/rules/format-rules/is-credit-card.js +40 -0
  10. package/cjs/rules/format-rules/is-decimal.js +41 -0
  11. package/cjs/rules/format-rules/is-ean.js +40 -0
  12. package/cjs/rules/format-rules/is-email.js +97 -0
  13. package/cjs/rules/format-rules/is-eth-address.js +40 -0
  14. package/cjs/rules/format-rules/is-fqdn.js +44 -0
  15. package/cjs/rules/format-rules/is-hash.js +40 -0
  16. package/cjs/rules/format-rules/is-hex-color.js +40 -0
  17. package/cjs/rules/format-rules/is-hex.js +40 -0
  18. package/cjs/rules/format-rules/is-iban.js +52 -0
  19. package/cjs/rules/format-rules/is-ip.js +52 -0
  20. package/cjs/rules/format-rules/is-issn.js +44 -0
  21. package/cjs/rules/format-rules/is-jwt.js +40 -0
  22. package/cjs/rules/format-rules/is-lowercase.js +52 -0
  23. package/cjs/rules/format-rules/is-mac-address.js +45 -0
  24. package/cjs/rules/format-rules/is-mobile-phone.js +43 -0
  25. package/cjs/rules/{is-object-id.js → format-rules/is-object-id.js} +3 -3
  26. package/cjs/rules/format-rules/is-passport-number.js +40 -0
  27. package/cjs/rules/format-rules/is-port.js +40 -0
  28. package/cjs/rules/format-rules/is-url.js +40 -0
  29. package/cjs/rules/format-rules/is-uuid.js +40 -0
  30. package/cjs/rules/format-rules/is-vat-number.js +40 -0
  31. package/cjs/rules/{is-regexp.js → format-rules/matches.js} +8 -5
  32. package/cjs/rules/index.js +49 -22
  33. package/cjs/rules/logical-rules/is-defined.js +30 -0
  34. package/cjs/rules/{is-empty.js → logical-rules/is-empty.js} +1 -1
  35. package/cjs/rules/{range.js → logical-rules/range.js} +63 -38
  36. package/cjs/rules/{is-any.js → type-rules/is-any.js} +1 -1
  37. package/cjs/rules/{is-array.js → type-rules/is-array.js} +2 -4
  38. package/cjs/rules/{is-bigint.js → type-rules/is-bigint.js} +2 -3
  39. package/cjs/rules/{is-boolean.js → type-rules/is-boolean.js} +1 -1
  40. package/cjs/rules/{is-date.js → type-rules/is-date.js} +5 -5
  41. package/cjs/rules/{is-enum.js → type-rules/is-enum.js} +6 -5
  42. package/cjs/rules/{is-integer.js → type-rules/is-integer.js} +2 -3
  43. package/cjs/rules/{is-null.js → type-rules/is-null.js} +2 -28
  44. package/cjs/rules/{is-number.js → type-rules/is-number.js} +2 -3
  45. package/cjs/rules/{is-object.js → type-rules/is-object.js} +3 -4
  46. package/cjs/rules/{is-record.js → type-rules/is-record.js} +1 -1
  47. package/cjs/rules/{is-string.js → type-rules/is-string.js} +1 -1
  48. package/cjs/rules/{is-tuple.js → type-rules/is-tuple.js} +2 -3
  49. package/cjs/rules/utility-rules/exists.js +16 -0
  50. package/cjs/rules/utility-rules/get-length.js +24 -0
  51. package/cjs/rules/utility-rules/optional.js +16 -0
  52. package/cjs/rules/{pipe.js → utility-rules/pipe.js} +1 -1
  53. package/cjs/rules/utility-rules/required.js +18 -0
  54. package/cjs/rules/{union.js → utility-rules/union.js} +2 -2
  55. package/esm/core/context.js +2 -3
  56. package/esm/core/validator.js +4 -4
  57. package/esm/index.js +3 -3
  58. package/esm/rules/format-rules/is-alpha.js +24 -0
  59. package/esm/rules/format-rules/is-ascii.js +13 -0
  60. package/esm/rules/format-rules/is-base64.js +13 -0
  61. package/esm/rules/format-rules/is-btc-address.js +13 -0
  62. package/esm/rules/format-rules/is-credit-card.js +13 -0
  63. package/esm/rules/format-rules/is-decimal.js +14 -0
  64. package/esm/rules/format-rules/is-ean.js +13 -0
  65. package/esm/rules/format-rules/is-email.js +70 -0
  66. package/esm/rules/format-rules/is-eth-address.js +13 -0
  67. package/esm/rules/format-rules/is-fqdn.js +17 -0
  68. package/esm/rules/format-rules/is-hash.js +13 -0
  69. package/esm/rules/format-rules/is-hex-color.js +13 -0
  70. package/esm/rules/format-rules/is-hex.js +13 -0
  71. package/esm/rules/format-rules/is-iban.js +24 -0
  72. package/esm/rules/format-rules/is-ip.js +24 -0
  73. package/esm/rules/format-rules/is-issn.js +17 -0
  74. package/esm/rules/format-rules/is-jwt.js +13 -0
  75. package/esm/rules/format-rules/is-lowercase.js +24 -0
  76. package/esm/rules/format-rules/is-mac-address.js +18 -0
  77. package/esm/rules/format-rules/is-mobile-phone.js +16 -0
  78. package/esm/rules/{is-object-id.js → format-rules/is-object-id.js} +3 -3
  79. package/esm/rules/format-rules/is-passport-number.js +13 -0
  80. package/esm/rules/format-rules/is-port.js +13 -0
  81. package/esm/rules/format-rules/is-url.js +13 -0
  82. package/esm/rules/format-rules/is-uuid.js +13 -0
  83. package/esm/rules/format-rules/is-vat-number.js +13 -0
  84. package/esm/rules/{is-regexp.js → format-rules/matches.js} +6 -3
  85. package/esm/rules/index.js +49 -22
  86. package/esm/rules/logical-rules/is-defined.js +25 -0
  87. package/esm/rules/{is-empty.js → logical-rules/is-empty.js} +1 -1
  88. package/esm/rules/{range.js → logical-rules/range.js} +59 -36
  89. package/esm/rules/{is-any.js → type-rules/is-any.js} +1 -1
  90. package/esm/rules/{is-array.js → type-rules/is-array.js} +2 -4
  91. package/esm/rules/{is-bigint.js → type-rules/is-bigint.js} +2 -3
  92. package/esm/rules/{is-boolean.js → type-rules/is-boolean.js} +1 -1
  93. package/esm/rules/{is-date.js → type-rules/is-date.js} +5 -5
  94. package/esm/rules/{is-enum.js → type-rules/is-enum.js} +6 -5
  95. package/esm/rules/{is-integer.js → type-rules/is-integer.js} +2 -3
  96. package/esm/rules/{is-null.js → type-rules/is-null.js} +1 -25
  97. package/esm/rules/{is-number.js → type-rules/is-number.js} +2 -3
  98. package/esm/rules/{is-object.js → type-rules/is-object.js} +3 -4
  99. package/esm/rules/{is-record.js → type-rules/is-record.js} +1 -1
  100. package/esm/rules/{is-string.js → type-rules/is-string.js} +1 -1
  101. package/esm/rules/{is-tuple.js → type-rules/is-tuple.js} +2 -3
  102. package/esm/rules/utility-rules/exists.js +12 -0
  103. package/esm/rules/utility-rules/get-length.js +20 -0
  104. package/esm/rules/utility-rules/optional.js +12 -0
  105. package/esm/rules/{pipe.js → utility-rules/pipe.js} +1 -1
  106. package/esm/rules/utility-rules/required.js +14 -0
  107. package/esm/rules/{union.js → utility-rules/union.js} +2 -2
  108. package/package.json +1 -1
  109. package/typings/index.d.ts +4 -4
  110. package/typings/rules/format-rules/is-alpha.d.ts +11 -0
  111. package/typings/rules/format-rules/is-ascii.d.ts +6 -0
  112. package/typings/rules/format-rules/is-base64.d.ts +9 -0
  113. package/typings/rules/format-rules/is-btc-address.d.ts +6 -0
  114. package/typings/rules/format-rules/is-credit-card.d.ts +9 -0
  115. package/typings/rules/format-rules/is-decimal.d.ts +7 -0
  116. package/typings/rules/format-rules/is-ean.d.ts +6 -0
  117. package/typings/rules/format-rules/is-email.d.ts +62 -0
  118. package/typings/rules/format-rules/is-eth-address.d.ts +6 -0
  119. package/typings/rules/format-rules/is-fqdn.d.ts +13 -0
  120. package/typings/rules/format-rules/is-hash.d.ts +8 -0
  121. package/typings/rules/format-rules/is-hex-color.d.ts +6 -0
  122. package/typings/rules/format-rules/is-hex.d.ts +6 -0
  123. package/typings/rules/format-rules/is-iban.d.ts +11 -0
  124. package/typings/rules/format-rules/is-ip.d.ts +11 -0
  125. package/typings/rules/format-rules/is-issn.d.ts +14 -0
  126. package/typings/rules/format-rules/is-jwt.d.ts +6 -0
  127. package/typings/rules/format-rules/is-lowercase.d.ts +11 -0
  128. package/typings/rules/format-rules/is-mac-address.d.ts +21 -0
  129. package/typings/rules/format-rules/is-mobile-phone.d.ts +20 -0
  130. package/typings/rules/{is-object-id.d.ts → format-rules/is-object-id.d.ts} +2 -2
  131. package/typings/rules/format-rules/is-passport-number.d.ts +6 -0
  132. package/typings/rules/format-rules/is-port.d.ts +6 -0
  133. package/typings/rules/format-rules/is-url.d.ts +9 -0
  134. package/typings/rules/format-rules/is-uuid.d.ts +6 -0
  135. package/typings/rules/format-rules/is-vat-number.d.ts +6 -0
  136. package/typings/rules/format-rules/matches.d.ts +9 -0
  137. package/typings/rules/index.d.ts +49 -22
  138. package/typings/rules/logical-rules/is-defined.d.ts +11 -0
  139. package/typings/rules/{is-empty.d.ts → logical-rules/is-empty.d.ts} +3 -3
  140. package/typings/rules/{range.d.ts → logical-rules/range.d.ts} +14 -4
  141. package/typings/rules/type-rules/is-any.d.ts +5 -0
  142. package/typings/rules/{is-array.d.ts → type-rules/is-array.d.ts} +2 -2
  143. package/typings/rules/{is-bigint.d.ts → type-rules/is-bigint.d.ts} +2 -2
  144. package/typings/rules/{is-boolean.d.ts → type-rules/is-boolean.d.ts} +2 -2
  145. package/typings/rules/{is-date.d.ts → type-rules/is-date.d.ts} +3 -3
  146. package/typings/rules/{is-enum.d.ts → type-rules/is-enum.d.ts} +1 -1
  147. package/typings/rules/{is-integer.d.ts → type-rules/is-integer.d.ts} +2 -2
  148. package/typings/rules/type-rules/is-null.d.ts +11 -0
  149. package/typings/rules/{is-number.d.ts → type-rules/is-number.d.ts} +2 -2
  150. package/typings/rules/{is-object.d.ts → type-rules/is-object.d.ts} +1 -1
  151. package/typings/rules/{is-record.d.ts → type-rules/is-record.d.ts} +2 -2
  152. package/typings/rules/{is-string.d.ts → type-rules/is-string.d.ts} +5 -5
  153. package/typings/rules/{is-tuple.d.ts → type-rules/is-tuple.d.ts} +2 -8
  154. package/typings/rules/utility-rules/exists.d.ts +6 -0
  155. package/typings/rules/utility-rules/get-length.d.ts +11 -0
  156. package/typings/rules/utility-rules/optional.d.ts +7 -0
  157. package/typings/rules/{pipe.d.ts → utility-rules/pipe.d.ts} +1 -1
  158. package/typings/rules/utility-rules/required.d.ts +7 -0
  159. package/typings/rules/utility-rules/union.d.ts +5 -0
  160. package/cjs/rules/length.js +0 -41
  161. package/cjs/rules/optional.js +0 -44
  162. package/cjs/rules/string-formats.js +0 -377
  163. package/esm/rules/length.js +0 -35
  164. package/esm/rules/optional.js +0 -38
  165. package/esm/rules/string-formats.js +0 -322
  166. package/typings/rules/is-any.d.ts +0 -5
  167. package/typings/rules/is-null.d.ts +0 -21
  168. package/typings/rules/is-regexp.d.ts +0 -9
  169. package/typings/rules/length.d.ts +0 -21
  170. package/typings/rules/optional.d.ts +0 -17
  171. package/typings/rules/string-formats.d.ts +0 -166
  172. package/typings/rules/union.d.ts +0 -5
@@ -19,7 +19,7 @@ export class Context {
19
19
  index: this.index,
20
20
  label: this.label,
21
21
  value,
22
- ...details
22
+ ...details,
23
23
  });
24
24
  issue.value = value;
25
25
  const onFail = this.onFail || rule[kOptions].onFail;
@@ -34,8 +34,7 @@ export class Context {
34
34
  else
35
35
  issue.message = String(x);
36
36
  }
37
- issue.message = ('' + issue.message)
38
- .replace(VARIABLE_REPLACE_PATTERN, (x, g) => {
37
+ issue.message = ('' + issue.message).replace(VARIABLE_REPLACE_PATTERN, (x, g) => {
39
38
  const m = OPTIONAL_VAR_PATTERN.exec(g);
40
39
  if (!m)
41
40
  return x;
@@ -19,10 +19,10 @@ export function validator(arg0, arg1, arg2) {
19
19
  throw new TypeError('You must provide a rule function argument');
20
20
  id = id || fn.name || 'unnamed-rule';
21
21
  const name = fn.name || camelCase(id);
22
- const _rule = ({
22
+ const _rule = {
23
23
  [name](input, options) {
24
24
  const ctx = options instanceof Context ? options : undefined;
25
- const opts = (ctx ? undefined : options);
25
+ const opts = ctx ? undefined : options;
26
26
  const context = ctx || new Context(opts);
27
27
  let value;
28
28
  try {
@@ -36,8 +36,8 @@ export function validator(arg0, arg1, arg2) {
36
36
  if (!ctx && context.errors.length)
37
37
  throw new ValidationError(context.errors);
38
38
  return value;
39
- }
40
- })[name];
39
+ },
40
+ }[name];
41
41
  _rule.id = id;
42
42
  _rule[kValidatorFn] = fn;
43
43
  _rule[kOptions] = validatorOptions || {};
package/esm/index.js CHANGED
@@ -32,7 +32,7 @@ const isMACAddress = vg.isMACAddress();
32
32
  const isPort = vg.isPort();
33
33
  const isURL = vg.isURL();
34
34
  const isBase64 = vg.isBase64();
35
- const isBIC = vg.isBIC();
35
+ const isSWIFT = vg.isSWIFT();
36
36
  const isCreditCard = vg.isCreditCard();
37
37
  const isIBAN = vg.isIBAN();
38
38
  const isEAN = vg.isEAN();
@@ -48,7 +48,7 @@ const isAlpha = vg.isAlpha();
48
48
  const isAlphanumeric = vg.isAlphanumeric();
49
49
  const isAscii = vg.isAscii();
50
50
  const isDecimal = vg.isDecimal();
51
- const isHexadecimal = vg.isHexadecimal();
51
+ const isHex = vg.isHex();
52
52
  const toArray = vg.isArray(isAny, { coerce: true });
53
53
  const toBoolean = vg.isBoolean({ coerce: true });
54
54
  const toDate = vg.isDate({ coerce: true });
@@ -56,4 +56,4 @@ const toDateString = vg.isDateString({ coerce: true });
56
56
  const toInteger = vg.isInteger({ coerce: true });
57
57
  const toNumber = vg.isNumber({ coerce: true });
58
58
  const toString = vg.isString({ coerce: true });
59
- export { vg, isAny, isArray, isBigint, isBoolean, isDate, isDateString, isEmpty, isNotEmpty, isInteger, isNull, isNullish, isDefined, isUndefined, isNumber, isObject, isObjectId, isString, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isEmail, isMobilePhone, isIP, isIPRange, isMACAddress, isPort, isURL, isBase64, isBIC, isCreditCard, isIBAN, isEAN, isFQDN, isISSN, isBtcAddress, isETHAddress, isHexColor, isJWT, isLowercase, isUppercase, isAlpha, isAlphanumeric, isAscii, isDecimal, isHexadecimal, toArray, toBoolean, toDate, toDateString, toInteger, toNumber, toString };
59
+ export { vg, isAny, isArray, isBigint, isBoolean, isDate, isDateString, isEmpty, isNotEmpty, isInteger, isNull, isNullish, isDefined, isUndefined, isNumber, isObject, isObjectId, isString, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isEmail, isMobilePhone, isIP, isIPRange, isMACAddress, isPort, isURL, isBase64, isSWIFT, isCreditCard, isIBAN, isEAN, isFQDN, isISSN, isBtcAddress, isETHAddress, isHexColor, isJWT, isLowercase, isUppercase, isAlpha, isAlphanumeric, isAscii, isDecimal, isHex, toArray, toBoolean, toDate, toDateString, toInteger, toNumber, toString, };
@@ -0,0 +1,24 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Check if the string contains only letters (a-zA-Z).
5
+ * @validator isAlpha
6
+ */
7
+ export function isAlpha(options) {
8
+ return validator('isLowercase', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isAlpha(input))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not an alpha string`, input);
12
+ }, options);
13
+ }
14
+ /**
15
+ * Check if the string contains only letters and numbers.
16
+ * @validator isAlphanumeric
17
+ */
18
+ export function isAlphanumeric(options) {
19
+ return validator('isAlphanumeric', function (input, context, _this) {
20
+ if (typeof input === 'string' && validatorJS.isAlphanumeric(input))
21
+ return input;
22
+ context.fail(_this, `"{{value}}" is not an alphanumeric string`, input);
23
+ }, options);
24
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Check if the string contains ASCII chars only.
5
+ * @validator isAscii
6
+ */
7
+ export function isAscii(options) {
8
+ return validator('isAscii', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isAscii(input))
10
+ return input;
11
+ context.fail(_this, `Value is not an ascii string`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a "Base64" string.
5
+ * @validator isBase64
6
+ */
7
+ export function isBase64(options) {
8
+ return validator('isBase64', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isBase64(input, options))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not a valid a Base64 string`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a BTC address.
5
+ * @validator isBtcAddress
6
+ */
7
+ export function isBtcAddress(options) {
8
+ return validator('isBtcAddress', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isBtcAddress(input))
10
+ return input;
11
+ context.fail(_this, `Value is not a valid a BTC address`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a credit card number
5
+ * @validator isCreditCard
6
+ */
7
+ export function isCreditCard(options) {
8
+ return validator('isCreditCard', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isCreditCard(input, options))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not a valid Credit Card number`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,14 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Check if the string represents a decimal number,
5
+ * such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
6
+ * @validator isDecimal
7
+ */
8
+ export function isDecimal(options) {
9
+ return validator('isDecimal', function (input, context, _this) {
10
+ if (typeof input === 'string' && validatorJS.isDecimal(input))
11
+ return input;
12
+ context.fail(_this, `"{{value}}" is not an decimal number string`, input);
13
+ }, options);
14
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an EAN (European Article Number)
5
+ * @validator isEAN
6
+ */
7
+ export function isEAN(options) {
8
+ return validator('isEAN', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isEAN(input))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not a valid EAN (European Article Number)`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,70 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a valid Email
5
+ * @validator isEmail
6
+ */
7
+ export function isEmail(options) {
8
+ const emailOptions = {
9
+ // eslint-disable-next-line camelcase
10
+ allow_display_name: true,
11
+ // eslint-disable-next-line camelcase
12
+ allow_utf8_local_part: options?.utf8LocalPart,
13
+ // eslint-disable-next-line camelcase
14
+ ignore_max_length: true,
15
+ // eslint-disable-next-line camelcase
16
+ allow_ip_domain: options?.allowIpDomain,
17
+ };
18
+ return validator('isEmail', function (input, context, _this) {
19
+ if (typeof input === 'string' && validatorJS.isEmail(input, emailOptions)) {
20
+ if (options?.requireDisplayName) {
21
+ if (!validatorJS.isEmail(input, {
22
+ ...emailOptions,
23
+ // eslint-disable-next-line camelcase
24
+ require_display_name: true,
25
+ })) {
26
+ context.fail(_this, `Display name for the email is required. Etc. ( Name <me@tempuri.org> ) `, input);
27
+ return;
28
+ }
29
+ }
30
+ else if (!options?.allowDisplayName &&
31
+ !validatorJS.isEmail(input, {
32
+ ...emailOptions,
33
+ // eslint-disable-next-line camelcase
34
+ allow_display_name: false,
35
+ })) {
36
+ context.fail(_this, `Display name in email is not allowed`, input);
37
+ return;
38
+ }
39
+ if (options?.hostBlacklist &&
40
+ !validatorJS.isEmail(input, {
41
+ ...emailOptions,
42
+ // eslint-disable-next-line camelcase
43
+ host_blacklist: options.hostBlacklist,
44
+ })) {
45
+ context.fail(_this, `Email "{{value}}" is in black-list`, input);
46
+ return;
47
+ }
48
+ if (options?.hostWhitelist &&
49
+ !validatorJS.isEmail(input, {
50
+ ...emailOptions,
51
+ // eslint-disable-next-line camelcase
52
+ host_whitelist: options.hostWhitelist,
53
+ })) {
54
+ context.fail(_this, `Email "{{value}}" is in not white-list`, input);
55
+ return;
56
+ }
57
+ if (options?.blacklistedChars &&
58
+ !validatorJS.isEmail(input, {
59
+ ...emailOptions,
60
+ // eslint-disable-next-line camelcase
61
+ blacklisted_chars: options.blacklistedChars,
62
+ })) {
63
+ context.fail(_this, `Black listed characters (${options.blacklistedChars}) found in name part`, input);
64
+ return;
65
+ }
66
+ return input;
67
+ }
68
+ context.fail(_this, `"{{value}}" does not match required e-mail format`, input);
69
+ }, options);
70
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a ETH (Ethereum) address.
5
+ * @validator isETHAddress
6
+ */
7
+ export function isETHAddress(options) {
8
+ return validator('isETHAddress', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isEthereumAddress(input))
10
+ return input;
11
+ context.fail(_this, `Value is not a valid a ETH (Ethereum) address`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,17 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an FQDN
5
+ * @validator isFQDN
6
+ */
7
+ export function isFQDN(options) {
8
+ const opts = {
9
+ // eslint-disable-next-line camelcase
10
+ allow_wildcard: options?.allowWildcard,
11
+ };
12
+ return validator('isFQDN', function (input, context, _this) {
13
+ if (typeof input === 'string' && validatorJS.isFQDN(input, opts))
14
+ return input;
15
+ context.fail(_this, `"{{value}}" is not valid FQDN`, input);
16
+ }, options);
17
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value a hash of type algorithm
5
+ * @validator isHash
6
+ */
7
+ export function isHash(algorithm, options) {
8
+ return validator('isHash', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isHash(input, algorithm))
10
+ return input;
11
+ context.fail(_this, `Value is not a valid ${algorithm} hash`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a Hex Color
5
+ * @validator isHexColor
6
+ */
7
+ export function isHexColor(options) {
8
+ return validator('isHexColor', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isHexColor(input))
10
+ return input;
11
+ context.fail(_this, `{{label}} is not a valid Hex Color`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Check if the string is a hexadecimal number.
5
+ * @validator isHex
6
+ */
7
+ export function isHex(options) {
8
+ return validator('isHex', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isHexadecimal(input))
10
+ return input;
11
+ context.fail(_this, `{{label}} is not an hexadecimal string`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,24 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an IBAN (International Bank Account Number)
5
+ * @validator isIBAN
6
+ */
7
+ export function isIBAN(options) {
8
+ return validator('isIBAN', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isIBAN(input))
10
+ return input;
11
+ context.fail(_this, `{{label}} is not a valid IBAN (International Bank Account Number)`, input);
12
+ }, options);
13
+ }
14
+ /**
15
+ * Validates if value is a BIC (Bank Identification Code) or SWIFT code
16
+ * @validator isSWIFT
17
+ */
18
+ export function isSWIFT(options) {
19
+ return validator('isSWIFT', function (input, context, _this) {
20
+ if (typeof input === 'string' && validatorJS.isBIC(input))
21
+ return input;
22
+ context.fail(_this, `{{label}}is not a valid a BIC (Bank Identification Code) or SWIFT code`, input);
23
+ }, options);
24
+ }
@@ -0,0 +1,24 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an IP
5
+ * @validator isIP
6
+ */
7
+ export function isIP(version, options) {
8
+ return validator('isIP', function (input, context, _this) {
9
+ if (input != null && typeof input === 'string' && validatorJS.isIP(input, version))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''}`, input);
12
+ }, options);
13
+ }
14
+ /**
15
+ * Validates if value is an IP
16
+ * @validator isIPRange
17
+ */
18
+ export function isIPRange(version, options) {
19
+ return validator('isIPRange', function (input, context, _this) {
20
+ if (input != null && typeof input === 'string' && validatorJS.isIPRange(input, version))
21
+ return input;
22
+ context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''} range`, input);
23
+ }, options);
24
+ }
@@ -0,0 +1,17 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an ISSN
5
+ * @validator isISSN
6
+ */
7
+ export function isISSN(options) {
8
+ const opts = {
9
+ // eslint-disable-next-line camelcase
10
+ case_sensitive: options?.caseSensitive,
11
+ };
12
+ return validator('isISSN', function (input, context, _this) {
13
+ if (typeof input === 'string' && validatorJS.isISSN(input, opts))
14
+ return input;
15
+ context.fail(_this, `"{{value}}" is not a valid ISSN`, input);
16
+ }, options);
17
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value a valid JWT token
5
+ * @validator isJWT
6
+ */
7
+ export function isJWT(options) {
8
+ return validator('isJWT', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isJWT(input))
10
+ return input;
11
+ context.fail(_this, `Value is not a valid JWT token`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,24 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value a Lowercase string
5
+ * @validator isLowercase
6
+ */
7
+ export function isLowercase(options) {
8
+ return validator('isLowercase', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isLowercase(input))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not a lowercase string`, input);
12
+ }, options);
13
+ }
14
+ /**
15
+ * Validates if value a Uppercase string
16
+ * @validator isUppercase
17
+ */
18
+ export function isUppercase(options) {
19
+ return validator('isUppercase', function (input, context, _this) {
20
+ if (typeof input === 'string' && validatorJS.isUppercase(input))
21
+ return input;
22
+ context.fail(_this, `"{{value}}" is not an uppercase string`, input);
23
+ }, options);
24
+ }
@@ -0,0 +1,18 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an MACAddress
5
+ * @validator isMACAddress
6
+ */
7
+ export function isMACAddress(options) {
8
+ const opts = {
9
+ // eslint-disable-next-line camelcase
10
+ no_separators: options?.noSeparators,
11
+ eui: options?.eui,
12
+ };
13
+ return validator('isMACAddress', function (input, context, _this) {
14
+ if (input != null && typeof input === 'string' && validatorJS.isMACAddress(input, opts))
15
+ return input;
16
+ context.fail(_this, `{{label}} is not a valid MAC address`, input);
17
+ }, options);
18
+ }
@@ -0,0 +1,16 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a valid Email
5
+ * @validator isMobilePhone
6
+ */
7
+ export function isMobilePhone(options) {
8
+ const opts = {
9
+ strictMode: options?.strictMode,
10
+ };
11
+ return validator('isMobilePhone', function (input, context, _this) {
12
+ if (typeof input === 'string' && validatorJS.isMobilePhone(input, options?.locale, opts))
13
+ return input;
14
+ context.fail(_this, `"{{value}}" is not a valid a Mobile Phone Number`, input);
15
+ }, options);
16
+ }
@@ -1,5 +1,5 @@
1
1
  import validatorJS from 'validator';
2
- import { validator } from '../core/index.js';
2
+ import { validator } from '../../core/index.js';
3
3
  /**
4
4
  * Validates if value is an "ObjectId".
5
5
  * @validator isObjectId
@@ -16,6 +16,6 @@ export function isObjectId(options) {
16
16
  }, options);
17
17
  }
18
18
  function _isObjectIdValue(input) {
19
- return (input instanceof Uint8Array && input.length === 12) ||
20
- (typeof input === 'string' && input.length === 24 && validatorJS.isHexadecimal(input));
19
+ return ((input instanceof Uint8Array && input.length === 12) ||
20
+ (typeof input === 'string' && input.length === 24 && validatorJS.isHexadecimal(input)));
21
21
  }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a passport number
5
+ * @validator isPassportNumber
6
+ */
7
+ export function isPassportNumber(countryCode, options) {
8
+ return validator('isPassportNumber', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isPassportNumber(input, countryCode))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not a valid ${countryCode} PassportNumber)`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is a port number
5
+ * @validator isPort
6
+ */
7
+ export function isPort(options) {
8
+ return validator('isPort', function (input, context, _this) {
9
+ if (input != null && typeof input === 'string' && validatorJS.isPort(input))
10
+ return input;
11
+ context.fail(_this, `{{label}} is not a valid port number`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an URL
5
+ * @validator isURL
6
+ */
7
+ export function isURL(options) {
8
+ return validator('isURL', function (input, context, _this) {
9
+ if (input != null && typeof input === 'string' && validatorJS.isURL(input, options))
10
+ return input;
11
+ context.fail(_this, `{{value}} is not a valid URL`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an "UUID".
5
+ * @validator isUUID
6
+ */
7
+ export function isUUID(version, options) {
8
+ return validator('isUUID', function (input, context, _this) {
9
+ if (input != null && typeof input === 'string' && validatorJS.isUUID(input, version))
10
+ return input;
11
+ context.fail(_this, `{{label}} is not a valid UUID${version ? ' v' + version : ''}`, input);
12
+ }, options);
13
+ }
@@ -0,0 +1,13 @@
1
+ import * as validatorJS from 'validator';
2
+ import { validator } from '../../core/index.js';
3
+ /**
4
+ * Validates if value is an VAT number
5
+ * @validator isVAT
6
+ */
7
+ export function isVATNumber(countryCode, options) {
8
+ return validator('isVATNumber', function (input, context, _this) {
9
+ if (typeof input === 'string' && validatorJS.isVAT(input, countryCode))
10
+ return input;
11
+ context.fail(_this, `"{{value}}" is not a valid VAT number`, input);
12
+ }, options);
13
+ }
@@ -1,9 +1,9 @@
1
- import { validator } from '../core/index.js';
1
+ import { validator } from '../../core/index.js';
2
2
  /**
3
3
  * Coerces given value to "UUID" format or returns undefined if nullish
4
4
  * @validator uuid
5
5
  */
6
- export function isRegExp(format, options) {
6
+ export function matches(format, options) {
7
7
  const regExp = format instanceof RegExp ? format : new RegExp(format);
8
8
  const formatName = options?.formatName;
9
9
  return validator('matches', function (input, context, _this) {
@@ -11,6 +11,9 @@ export function isRegExp(format, options) {
11
11
  return;
12
12
  if (typeof input === 'string' && regExp.test(input))
13
13
  return input;
14
- context.fail(_this, `{{label}} does not match ${formatName || 'requested'} format`, input, { format, formatName });
14
+ context.fail(_this, `"{{value}}" does not match ${formatName || 'requested'} format`, input, {
15
+ format,
16
+ formatName,
17
+ });
15
18
  }, options);
16
19
  }