valgen 5.4.1 → 5.5.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 (125) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/cjs/core/context.js +13 -10
  3. package/cjs/core/index.js +2 -2
  4. package/cjs/core/utilities.js +4 -5
  5. package/cjs/core/validator.js +10 -7
  6. package/cjs/helpers/object.utils.js +2 -3
  7. package/cjs/helpers/omit-undefined.js +1 -2
  8. package/cjs/helpers/string.utils.js +2 -5
  9. package/cjs/index.js +2 -2
  10. package/cjs/rules/format-rules/is-alpha.js +6 -6
  11. package/cjs/rules/format-rules/is-ascii.js +2 -3
  12. package/cjs/rules/format-rules/is-base64.js +4 -4
  13. package/cjs/rules/format-rules/is-btc-address.js +4 -4
  14. package/cjs/rules/format-rules/is-credit-card.js +5 -4
  15. package/cjs/rules/format-rules/is-decimal.js +4 -4
  16. package/cjs/rules/format-rules/is-ean.js +2 -3
  17. package/cjs/rules/format-rules/is-email.js +4 -4
  18. package/cjs/rules/format-rules/is-eth-address.js +4 -4
  19. package/cjs/rules/format-rules/is-fqdn.js +4 -4
  20. package/cjs/rules/format-rules/is-hash.js +4 -4
  21. package/cjs/rules/format-rules/is-hex-color.js +4 -4
  22. package/cjs/rules/format-rules/is-hex.js +4 -4
  23. package/cjs/rules/format-rules/is-iban.js +4 -5
  24. package/cjs/rules/format-rules/is-ip.js +12 -7
  25. package/cjs/rules/format-rules/is-issn.js +4 -4
  26. package/cjs/rules/format-rules/is-jwt.js +2 -3
  27. package/cjs/rules/format-rules/is-lowercase.js +8 -7
  28. package/cjs/rules/format-rules/is-mac-address.js +6 -4
  29. package/cjs/rules/format-rules/is-mobile-phone.js +5 -4
  30. package/cjs/rules/format-rules/is-object-id.js +7 -5
  31. package/cjs/rules/format-rules/is-passport-number.js +5 -4
  32. package/cjs/rules/format-rules/is-port.js +6 -4
  33. package/cjs/rules/format-rules/is-url.js +6 -4
  34. package/cjs/rules/format-rules/is-uuid.js +6 -4
  35. package/cjs/rules/format-rules/is-vat-number.js +4 -4
  36. package/cjs/rules/format-rules/matches.js +2 -3
  37. package/cjs/rules/index.js +14 -13
  38. package/cjs/rules/logical-rules/is-defined.js +2 -17
  39. package/cjs/rules/logical-rules/is-empty.js +4 -5
  40. package/cjs/rules/logical-rules/range.js +57 -26
  41. package/cjs/rules/type-rules/is-any.js +1 -3
  42. package/cjs/rules/type-rules/is-array.js +5 -4
  43. package/cjs/rules/type-rules/is-bigint.js +5 -4
  44. package/cjs/rules/type-rules/is-boolean.js +2 -3
  45. package/cjs/rules/type-rules/is-date.js +13 -8
  46. package/cjs/rules/type-rules/is-enum.js +7 -4
  47. package/cjs/rules/type-rules/is-integer.js +11 -5
  48. package/cjs/rules/type-rules/is-null.js +4 -11
  49. package/cjs/rules/type-rules/is-number.js +7 -4
  50. package/cjs/rules/type-rules/is-object.js +20 -12
  51. package/cjs/rules/type-rules/is-record.js +2 -3
  52. package/cjs/rules/type-rules/is-string.js +11 -11
  53. package/cjs/rules/type-rules/is-tuple.js +7 -5
  54. package/cjs/rules/type-rules/is-undefined.js +17 -0
  55. package/cjs/rules/utility-rules/exists.js +6 -4
  56. package/cjs/rules/utility-rules/get-length.js +10 -5
  57. package/cjs/rules/utility-rules/optional.js +2 -3
  58. package/cjs/rules/utility-rules/pipe.js +5 -6
  59. package/cjs/rules/utility-rules/required.js +2 -3
  60. package/cjs/rules/utility-rules/union.js +2 -3
  61. package/esm/core/context.js +13 -10
  62. package/esm/core/index.js +2 -2
  63. package/esm/core/utilities.js +3 -3
  64. package/esm/core/validator.js +8 -4
  65. package/esm/helpers/string.utils.js +1 -3
  66. package/esm/index.js +1 -1
  67. package/esm/rules/format-rules/is-alpha.js +4 -3
  68. package/esm/rules/format-rules/is-ascii.js +1 -1
  69. package/esm/rules/format-rules/is-base64.js +3 -2
  70. package/esm/rules/format-rules/is-btc-address.js +3 -2
  71. package/esm/rules/format-rules/is-credit-card.js +4 -2
  72. package/esm/rules/format-rules/is-decimal.js +3 -2
  73. package/esm/rules/format-rules/is-ean.js +1 -1
  74. package/esm/rules/format-rules/is-email.js +3 -2
  75. package/esm/rules/format-rules/is-eth-address.js +3 -2
  76. package/esm/rules/format-rules/is-fqdn.js +3 -2
  77. package/esm/rules/format-rules/is-hash.js +3 -2
  78. package/esm/rules/format-rules/is-hex-color.js +3 -2
  79. package/esm/rules/format-rules/is-hex.js +3 -2
  80. package/esm/rules/format-rules/is-iban.js +2 -2
  81. package/esm/rules/format-rules/is-ip.js +10 -4
  82. package/esm/rules/format-rules/is-issn.js +3 -2
  83. package/esm/rules/format-rules/is-jwt.js +1 -1
  84. package/esm/rules/format-rules/is-lowercase.js +6 -4
  85. package/esm/rules/format-rules/is-mac-address.js +5 -2
  86. package/esm/rules/format-rules/is-mobile-phone.js +4 -2
  87. package/esm/rules/format-rules/is-object-id.js +7 -4
  88. package/esm/rules/format-rules/is-passport-number.js +4 -2
  89. package/esm/rules/format-rules/is-port.js +5 -2
  90. package/esm/rules/format-rules/is-url.js +5 -2
  91. package/esm/rules/format-rules/is-uuid.js +5 -2
  92. package/esm/rules/format-rules/is-vat-number.js +3 -2
  93. package/esm/rules/format-rules/matches.js +2 -2
  94. package/esm/rules/index.js +14 -13
  95. package/esm/rules/logical-rules/is-defined.js +1 -14
  96. package/esm/rules/logical-rules/is-empty.js +2 -2
  97. package/esm/rules/logical-rules/range.js +52 -21
  98. package/esm/rules/type-rules/is-any.js +1 -3
  99. package/esm/rules/type-rules/is-array.js +5 -3
  100. package/esm/rules/type-rules/is-bigint.js +4 -2
  101. package/esm/rules/type-rules/is-boolean.js +2 -2
  102. package/esm/rules/type-rules/is-date.js +11 -5
  103. package/esm/rules/type-rules/is-enum.js +7 -3
  104. package/esm/rules/type-rules/is-integer.js +11 -4
  105. package/esm/rules/type-rules/is-null.js +2 -8
  106. package/esm/rules/type-rules/is-number.js +6 -2
  107. package/esm/rules/type-rules/is-object.js +19 -10
  108. package/esm/rules/type-rules/is-record.js +2 -2
  109. package/esm/rules/type-rules/is-string.js +7 -7
  110. package/esm/rules/type-rules/is-tuple.js +7 -4
  111. package/esm/rules/type-rules/is-undefined.js +14 -0
  112. package/esm/rules/utility-rules/exists.js +5 -2
  113. package/esm/rules/utility-rules/get-length.js +9 -3
  114. package/esm/rules/utility-rules/optional.js +2 -2
  115. package/esm/rules/utility-rules/pipe.js +4 -4
  116. package/esm/rules/utility-rules/required.js +2 -2
  117. package/esm/rules/utility-rules/union.js +1 -1
  118. package/package.json +2 -2
  119. package/typings/core/index.d.ts +3 -3
  120. package/typings/core/types.d.ts +1 -1
  121. package/typings/index.d.ts +1 -1
  122. package/typings/rules/index.d.ts +14 -13
  123. package/typings/rules/logical-rules/is-defined.d.ts +0 -5
  124. package/typings/rules/type-rules/is-tuple.d.ts +36 -4
  125. package/typings/rules/type-rules/is-undefined.d.ts +6 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # v5.5.0
2
+ [2024-07-14]
3
+
4
+ ### Changes
5
+
6
+ * Moved eslint config to @panates/eslint-config ([`c2f3e2d`](https://github.com/panates/valgen/commit/c2f3e2dfec484fe891de3b519b7f26779c451b43))
7
+ * Changed error message ([`3edf948`](https://github.com/panates/valgen/commit/3edf948a674d11a4ff5efcb97ca255b0723a11ca))
8
+ * Removed coercing of isNull and isNullish rules ([`4337d0a`](https://github.com/panates/valgen/commit/4337d0a4bd148718f33f744257b13afdd5c3ac50))
9
+ * Now pipe can return original input value when returnIndex = -1 ([`baf698c`](https://github.com/panates/valgen/commit/baf698c289254743d70ef815188f2300d7230f00))
10
+
1
11
  # v5.4.1
2
12
  [2024-05-18]
3
13
 
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Context = void 0;
4
4
  const omit_undefined_js_1 = require("../helpers/omit-undefined.js");
5
- const constants_js_1 = require("./constants.js");
6
5
  const validation_error_js_1 = require("./validation-error.js");
7
6
  const VARIABLE_REPLACE_PATTERN = /{{([^}]*)}}/g;
8
7
  const OPTIONAL_VAR_PATTERN = /^([^?]+)(?:\||(.*))?$/;
@@ -25,11 +24,8 @@ class Context {
25
24
  ...details,
26
25
  });
27
26
  issue.value = value;
28
- const onFail = this.onFail || rule[constants_js_1.kOptions].onFail;
29
- if (onFail) {
30
- const proto = Object.getPrototypeOf(this);
31
- const superOnFail = proto.onFail !== onFail ? proto.onFail : undefined;
32
- const x = onFail(issue, this, superOnFail);
27
+ if (this.onFail) {
28
+ const x = this.onFail(issue, this);
33
29
  if (!x)
34
30
  return;
35
31
  if (typeof x === 'object')
@@ -47,8 +43,9 @@ class Context {
47
43
  const s = String(issue.value);
48
44
  return s.length < 30 ? s : s.substring(0, 30) + '..';
49
45
  }
50
- if (!v && k === 'label' && (this.location || this.property))
46
+ if (!v && k === 'label' && (this.location || this.property)) {
51
47
  v = '`' + (this.location || this.property) + '`';
48
+ }
52
49
  if (v != null)
53
50
  return v;
54
51
  if (m[2])
@@ -56,13 +53,19 @@ class Context {
56
53
  return m[1] === 'label' ? 'Value' : x;
57
54
  });
58
55
  this.errors.push(issue);
59
- if (this.errors.length >= (this.maxErrors ?? Infinity))
56
+ if (this.errors.length >= (this.maxErrors ?? Infinity)) {
60
57
  throw new validation_error_js_1.ValidationError(this.errors);
58
+ }
61
59
  }
62
60
  extend(options) {
63
- const extended = new Context({ onFail: undefined, ...options });
61
+ const extended = {};
62
+ if (options) {
63
+ for (const [k, v] of Object.entries(options)) {
64
+ if (v !== undefined)
65
+ extended[k] = v;
66
+ }
67
+ }
64
68
  Object.setPrototypeOf(extended, this);
65
- delete extended.errors;
66
69
  return extended;
67
70
  }
68
71
  }
package/cjs/core/index.js CHANGED
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./context.js"), exports);
18
17
  __exportStar(require("./constants.js"), exports);
18
+ __exportStar(require("./context.js"), exports);
19
19
  __exportStar(require("./types.js"), exports);
20
+ __exportStar(require("./utilities.js"), exports);
20
21
  __exportStar(require("./validation-error.js"), exports);
21
22
  __exportStar(require("./validator.js"), exports);
22
- __exportStar(require("./utilities.js"), exports);
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.iif = exports.forwardRef = void 0;
3
+ exports.forwardRef = forwardRef;
4
+ exports.iif = iif;
4
5
  const index_js_1 = require("./index.js");
5
6
  /**
6
7
  * Forwards codec process to a sub codec. Useful for circular checks
7
8
  * @validator forwardRef
8
9
  */
9
10
  function forwardRef(fn) {
10
- return (0, index_js_1.validator)('forwardRef', function (input, context) {
11
+ return (0, index_js_1.validator)('forwardRef', (input, context) => {
11
12
  const nested = fn(context);
12
13
  return nested(input, context);
13
14
  });
14
15
  }
15
- exports.forwardRef = forwardRef;
16
16
  function iif(check, _then, _else) {
17
- return (0, index_js_1.validator)('iif', function (input, context) {
17
+ return (0, index_js_1.validator)('iif', (input, context) => {
18
18
  let c = _else;
19
19
  try {
20
20
  if (check(input) !== undefined)
@@ -28,4 +28,3 @@ function iif(check, _then, _else) {
28
28
  return c;
29
29
  });
30
30
  }
31
- exports.iif = iif;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidator = exports.validator = void 0;
3
+ exports.validator = validator;
4
+ exports.isValidator = isValidator;
4
5
  const string_utils_js_1 = require("../helpers/string.utils.js");
5
6
  const constants_js_1 = require("./constants.js");
6
7
  const context_js_1 = require("./context.js");
7
8
  const validation_error_js_1 = require("./validation-error.js");
9
+ let unnamedValidatorIndex = 0;
8
10
  function validator(arg0, arg1, arg2) {
9
11
  let id = '';
10
12
  let fn;
@@ -18,15 +20,17 @@ function validator(arg0, arg1, arg2) {
18
20
  fn = arg0;
19
21
  validatorOptions = arg1;
20
22
  }
21
- if (typeof fn !== 'function')
23
+ if (typeof fn !== 'function') {
22
24
  throw new TypeError('You must provide a rule function argument');
23
- id = id || fn.name || 'unnamed-rule';
25
+ }
26
+ id = id || fn.name || 'validator' + ++unnamedValidatorIndex;
24
27
  const name = fn.name || (0, string_utils_js_1.camelCase)(id);
25
28
  const _rule = {
26
29
  [name](input, options) {
27
30
  const ctx = options instanceof context_js_1.Context ? options : undefined;
28
31
  const opts = ctx ? undefined : options;
29
- const context = ctx || new context_js_1.Context(opts);
32
+ const context = ctx?.extend({ ...validatorOptions, ...opts }) ||
33
+ new context_js_1.Context({ ...validatorOptions, ...opts });
30
34
  let value;
31
35
  try {
32
36
  value = fn(input, context, _rule);
@@ -36,8 +40,9 @@ function validator(arg0, arg1, arg2) {
36
40
  throw e;
37
41
  context.fail(_rule, e, input);
38
42
  }
39
- if (!ctx && context.errors.length)
43
+ if (!ctx && context.errors.length) {
40
44
  throw new validation_error_js_1.ValidationError(context.errors);
45
+ }
41
46
  return value;
42
47
  },
43
48
  }[name];
@@ -55,8 +60,6 @@ function validator(arg0, arg1, arg2) {
55
60
  };
56
61
  return _rule;
57
62
  }
58
- exports.validator = validator;
59
63
  function isValidator(x) {
60
64
  return !!(typeof x === 'function' && x.id && x[constants_js_1.kValidatorFn]);
61
65
  }
62
- exports.isValidator = isValidator;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pickKeys = exports.omitKeys = void 0;
3
+ exports.omitKeys = omitKeys;
4
+ exports.pickKeys = pickKeys;
4
5
  function omitKeys(o, keys) {
5
6
  return Object.keys(o).reduce((a, k) => {
6
7
  if (!keys.includes(k))
@@ -8,7 +9,6 @@ function omitKeys(o, keys) {
8
9
  return a;
9
10
  }, {});
10
11
  }
11
- exports.omitKeys = omitKeys;
12
12
  function pickKeys(o, keys) {
13
13
  return Object.keys(o).reduce((a, k) => {
14
14
  if (keys.includes(k))
@@ -16,4 +16,3 @@ function pickKeys(o, keys) {
16
16
  return a;
17
17
  }, {});
18
18
  }
19
- exports.pickKeys = pickKeys;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.omitUndefined = void 0;
3
+ exports.omitUndefined = omitUndefined;
4
4
  function omitUndefined(obj, recursive) {
5
5
  if (!(obj && typeof obj === 'object'))
6
6
  return obj;
@@ -12,4 +12,3 @@ function omitUndefined(obj, recursive) {
12
12
  }
13
13
  return obj;
14
14
  }
15
- exports.omitUndefined = omitUndefined;
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.camelCase = void 0;
3
+ exports.camelCase = camelCase;
4
4
  function camelCase(v) {
5
- return v.replace(/[\W_\s]+([^\W_\s])/g, (arg$, c) => {
6
- return c[0].toUpperCase();
7
- });
5
+ return v.replace(/[\W_\s]+([^\W_\s])/g, (arg$, c) => c[0].toUpperCase());
8
6
  }
9
- exports.camelCase = camelCase;
package/cjs/index.js CHANGED
@@ -26,8 +26,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.toArray = exports.isHex = exports.isDecimal = exports.isAscii = exports.isAlphanumeric = exports.isAlpha = exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isETHAddress = exports.isBtcAddress = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isIBAN = exports.isCreditCard = exports.isSWIFT = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID5 = exports.isUUID4 = exports.isUUID3 = exports.isUUID2 = exports.isUUID1 = exports.isUUID = exports.isString = exports.isObjectId = exports.isObject = exports.isNumber = exports.isUndefined = exports.isDefined = exports.isNullish = exports.isNull = exports.isInteger = exports.isNotEmpty = exports.isEmpty = exports.isDateString = exports.isDate = exports.isBoolean = exports.isBigint = exports.isArray = exports.isAny = exports.vg = void 0;
30
- exports.toString = exports.toNumber = exports.toInteger = exports.toDateString = exports.toDate = exports.toBigint = exports.toBoolean = void 0;
29
+ exports.toBigint = exports.toArray = exports.isUUID5 = exports.isUUID4 = exports.isUUID3 = exports.isUUID2 = exports.isUUID1 = exports.isUUID = exports.isURL = exports.isUppercase = exports.isUndefined = exports.isSWIFT = exports.isString = exports.isPort = exports.isObjectId = exports.isObject = exports.isNumber = exports.isNullish = exports.isNull = exports.isNotEmpty = exports.isMobilePhone = exports.isMACAddress = exports.isLowercase = exports.isJWT = exports.isISSN = exports.isIPRange = exports.isIP = exports.isInteger = exports.isIBAN = exports.isHexColor = exports.isHex = exports.isFQDN = exports.isETHAddress = exports.isEmpty = exports.isEmail = exports.isEAN = exports.isDefined = exports.isDecimal = exports.isDateString = exports.isDate = exports.isCreditCard = exports.isBtcAddress = exports.isBoolean = exports.isBigint = exports.isBase64 = exports.isAscii = exports.isArray = exports.isAny = exports.isAlphanumeric = exports.isAlpha = void 0;
30
+ exports.vg = exports.toString = exports.toNumber = exports.toInteger = exports.toDateString = exports.toDate = exports.toBoolean = void 0;
31
31
  const vg = __importStar(require("./rules/index.js"));
32
32
  exports.vg = vg;
33
33
  __exportStar(require("./constants.js"), exports);
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isAlphanumeric = exports.isAlpha = void 0;
26
+ exports.isAlpha = isAlpha;
27
+ exports.isAlphanumeric = isAlphanumeric;
27
28
  const validatorJS = __importStar(require("validator"));
28
29
  const index_js_1 = require("../../core/index.js");
29
30
  /**
@@ -31,22 +32,21 @@ const index_js_1 = require("../../core/index.js");
31
32
  * @validator isAlpha
32
33
  */
33
34
  function isAlpha(options) {
34
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
35
+ return (0, index_js_1.validator)('isLowercase', (input, context, _this) => {
35
36
  if (typeof input === 'string' && validatorJS.isAlpha(input))
36
37
  return input;
37
38
  context.fail(_this, `"{{value}}" is not an alpha string`, input);
38
39
  }, options);
39
40
  }
40
- exports.isAlpha = isAlpha;
41
41
  /**
42
42
  * Check if the string contains only letters and numbers.
43
43
  * @validator isAlphanumeric
44
44
  */
45
45
  function isAlphanumeric(options) {
46
- return (0, index_js_1.validator)('isAlphanumeric', function (input, context, _this) {
47
- if (typeof input === 'string' && validatorJS.isAlphanumeric(input))
46
+ return (0, index_js_1.validator)('isAlphanumeric', (input, context, _this) => {
47
+ if (typeof input === 'string' && validatorJS.isAlphanumeric(input)) {
48
48
  return input;
49
+ }
49
50
  context.fail(_this, `"{{value}}" is not an alphanumeric string`, input);
50
51
  }, options);
51
52
  }
52
- exports.isAlphanumeric = isAlphanumeric;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isAscii = void 0;
26
+ exports.isAscii = isAscii;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,9 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isAscii
32
32
  */
33
33
  function isAscii(options) {
34
- return (0, index_js_1.validator)('isAscii', function (input, context, _this) {
34
+ return (0, index_js_1.validator)('isAscii', (input, context, _this) => {
35
35
  if (typeof input === 'string' && validatorJS.isAscii(input))
36
36
  return input;
37
37
  context.fail(_this, `Value is not an ascii string`, input);
38
38
  }, options);
39
39
  }
40
- exports.isAscii = isAscii;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isBase64 = void 0;
26
+ exports.isBase64 = isBase64;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isBase64
32
32
  */
33
33
  function isBase64(options) {
34
- return (0, index_js_1.validator)('isBase64', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isBase64(input, options))
34
+ return (0, index_js_1.validator)('isBase64', (input, context, _this) => {
35
+ if (typeof input === 'string' && validatorJS.isBase64(input, options)) {
36
36
  return input;
37
+ }
37
38
  context.fail(_this, `"{{value}}" is not a valid a Base64 string`, input);
38
39
  }, options);
39
40
  }
40
- exports.isBase64 = isBase64;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isBtcAddress = void 0;
26
+ exports.isBtcAddress = isBtcAddress;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isBtcAddress
32
32
  */
33
33
  function isBtcAddress(options) {
34
- return (0, index_js_1.validator)('isBtcAddress', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isBtcAddress(input))
34
+ return (0, index_js_1.validator)('isBtcAddress', (input, context, _this) => {
35
+ if (typeof input === 'string' && validatorJS.isBtcAddress(input)) {
36
36
  return input;
37
+ }
37
38
  context.fail(_this, `Value is not a valid a BTC address`, input);
38
39
  }, options);
39
40
  }
40
- exports.isBtcAddress = isBtcAddress;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isCreditCard = void 0;
26
+ exports.isCreditCard = isCreditCard;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,11 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isCreditCard
32
32
  */
33
33
  function isCreditCard(options) {
34
- return (0, index_js_1.validator)('isCreditCard', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isCreditCard(input, options))
34
+ return (0, index_js_1.validator)('isCreditCard', (input, context, _this) => {
35
+ if (typeof input === 'string' &&
36
+ validatorJS.isCreditCard(input, options)) {
36
37
  return input;
38
+ }
37
39
  context.fail(_this, `"{{value}}" is not a valid Credit Card number`, input);
38
40
  }, options);
39
41
  }
40
- exports.isCreditCard = isCreditCard;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isDecimal = void 0;
26
+ exports.isDecimal = isDecimal;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -32,10 +32,10 @@ const index_js_1 = require("../../core/index.js");
32
32
  * @validator isDecimal
33
33
  */
34
34
  function isDecimal(options) {
35
- return (0, index_js_1.validator)('isDecimal', function (input, context, _this) {
36
- if (typeof input === 'string' && validatorJS.isDecimal(input))
35
+ return (0, index_js_1.validator)('isDecimal', (input, context, _this) => {
36
+ if (typeof input === 'string' && validatorJS.isDecimal(input)) {
37
37
  return input;
38
+ }
38
39
  context.fail(_this, `"{{value}}" is not an decimal number string`, input);
39
40
  }, options);
40
41
  }
41
- exports.isDecimal = isDecimal;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isEAN = void 0;
26
+ exports.isEAN = isEAN;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,9 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isEAN
32
32
  */
33
33
  function isEAN(options) {
34
- return (0, index_js_1.validator)('isEAN', function (input, context, _this) {
34
+ return (0, index_js_1.validator)('isEAN', (input, context, _this) => {
35
35
  if (typeof input === 'string' && validatorJS.isEAN(input))
36
36
  return input;
37
37
  context.fail(_this, `"{{value}}" is not a valid EAN (European Article Number)`, input);
38
38
  }, options);
39
39
  }
40
- exports.isEAN = isEAN;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isEmail = void 0;
26
+ exports.isEmail = isEmail;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -41,8 +41,9 @@ function isEmail(options) {
41
41
  // eslint-disable-next-line camelcase
42
42
  allow_ip_domain: options?.allowIpDomain,
43
43
  };
44
- return (0, index_js_1.validator)('isEmail', function (input, context, _this) {
45
- if (typeof input === 'string' && validatorJS.isEmail(input, emailOptions)) {
44
+ return (0, index_js_1.validator)('isEmail', (input, context, _this) => {
45
+ if (typeof input === 'string' &&
46
+ validatorJS.isEmail(input, emailOptions)) {
46
47
  if (options?.requireDisplayName) {
47
48
  if (!validatorJS.isEmail(input, {
48
49
  ...emailOptions,
@@ -94,4 +95,3 @@ function isEmail(options) {
94
95
  context.fail(_this, `"{{value}}" does not match required e-mail format`, input);
95
96
  }, options);
96
97
  }
97
- exports.isEmail = isEmail;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isETHAddress = void 0;
26
+ exports.isETHAddress = isETHAddress;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isETHAddress
32
32
  */
33
33
  function isETHAddress(options) {
34
- return (0, index_js_1.validator)('isETHAddress', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isEthereumAddress(input))
34
+ return (0, index_js_1.validator)('isETHAddress', (input, context, _this) => {
35
+ if (typeof input === 'string' && validatorJS.isEthereumAddress(input)) {
36
36
  return input;
37
+ }
37
38
  context.fail(_this, `Value is not a valid a ETH (Ethereum) address`, input);
38
39
  }, options);
39
40
  }
40
- exports.isETHAddress = isETHAddress;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isFQDN = void 0;
26
+ exports.isFQDN = isFQDN;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -35,10 +35,10 @@ function isFQDN(options) {
35
35
  // eslint-disable-next-line camelcase
36
36
  allow_wildcard: options?.allowWildcard,
37
37
  };
38
- return (0, index_js_1.validator)('isFQDN', function (input, context, _this) {
39
- if (typeof input === 'string' && validatorJS.isFQDN(input, opts))
38
+ return (0, index_js_1.validator)('isFQDN', (input, context, _this) => {
39
+ if (typeof input === 'string' && validatorJS.isFQDN(input, opts)) {
40
40
  return input;
41
+ }
41
42
  context.fail(_this, `"{{value}}" is not valid FQDN`, input);
42
43
  }, options);
43
44
  }
44
- exports.isFQDN = isFQDN;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isHash = void 0;
26
+ exports.isHash = isHash;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isHash
32
32
  */
33
33
  function isHash(algorithm, options) {
34
- return (0, index_js_1.validator)('isHash', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isHash(input, algorithm))
34
+ return (0, index_js_1.validator)('isHash', (input, context, _this) => {
35
+ if (typeof input === 'string' && validatorJS.isHash(input, algorithm)) {
36
36
  return input;
37
+ }
37
38
  context.fail(_this, `Value is not a valid ${algorithm} hash`, input);
38
39
  }, options);
39
40
  }
40
- exports.isHash = isHash;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isHexColor = void 0;
26
+ exports.isHexColor = isHexColor;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isHexColor
32
32
  */
33
33
  function isHexColor(options) {
34
- return (0, index_js_1.validator)('isHexColor', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isHexColor(input))
34
+ return (0, index_js_1.validator)('isHexColor', (input, context, _this) => {
35
+ if (typeof input === 'string' && validatorJS.isHexColor(input)) {
36
36
  return input;
37
+ }
37
38
  context.fail(_this, `{{label}} is not a valid Hex Color`, input);
38
39
  }, options);
39
40
  }
40
- exports.isHexColor = isHexColor;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isHex = void 0;
26
+ exports.isHex = isHex;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,10 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isHex
32
32
  */
33
33
  function isHex(options) {
34
- return (0, index_js_1.validator)('isHex', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isHexadecimal(input))
34
+ return (0, index_js_1.validator)('isHex', (input, context, _this) => {
35
+ if (typeof input === 'string' && validatorJS.isHexadecimal(input)) {
36
36
  return input;
37
+ }
37
38
  context.fail(_this, `{{label}} is not an hexadecimal string`, input);
38
39
  }, options);
39
40
  }
40
- exports.isHex = isHex;
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isSWIFT = exports.isIBAN = void 0;
26
+ exports.isIBAN = isIBAN;
27
+ exports.isSWIFT = isSWIFT;
27
28
  const validatorJS = __importStar(require("validator"));
28
29
  const index_js_1 = require("../../core/index.js");
29
30
  /**
@@ -31,22 +32,20 @@ const index_js_1 = require("../../core/index.js");
31
32
  * @validator isIBAN
32
33
  */
33
34
  function isIBAN(options) {
34
- return (0, index_js_1.validator)('isIBAN', function (input, context, _this) {
35
+ return (0, index_js_1.validator)('isIBAN', (input, context, _this) => {
35
36
  if (typeof input === 'string' && validatorJS.isIBAN(input))
36
37
  return input;
37
38
  context.fail(_this, `{{label}} is not a valid IBAN (International Bank Account Number)`, input);
38
39
  }, options);
39
40
  }
40
- exports.isIBAN = isIBAN;
41
41
  /**
42
42
  * Validates if value is a BIC (Bank Identification Code) or SWIFT code
43
43
  * @validator isSWIFT
44
44
  */
45
45
  function isSWIFT(options) {
46
- return (0, index_js_1.validator)('isSWIFT', function (input, context, _this) {
46
+ return (0, index_js_1.validator)('isSWIFT', (input, context, _this) => {
47
47
  if (typeof input === 'string' && validatorJS.isBIC(input))
48
48
  return input;
49
49
  context.fail(_this, `{{label}}is not a valid a BIC (Bank Identification Code) or SWIFT code`, input);
50
50
  }, options);
51
51
  }
52
- exports.isSWIFT = isSWIFT;
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isIPRange = exports.isIP = void 0;
26
+ exports.isIP = isIP;
27
+ exports.isIPRange = isIPRange;
27
28
  const validatorJS = __importStar(require("validator"));
28
29
  const index_js_1 = require("../../core/index.js");
29
30
  /**
@@ -31,22 +32,26 @@ const index_js_1 = require("../../core/index.js");
31
32
  * @validator isIP
32
33
  */
33
34
  function isIP(version, options) {
34
- return (0, index_js_1.validator)('isIP', function (input, context, _this) {
35
- if (input != null && typeof input === 'string' && validatorJS.isIP(input, version))
35
+ return (0, index_js_1.validator)('isIP', (input, context, _this) => {
36
+ if (input != null &&
37
+ typeof input === 'string' &&
38
+ validatorJS.isIP(input, version)) {
36
39
  return input;
40
+ }
37
41
  context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''}`, input);
38
42
  }, options);
39
43
  }
40
- exports.isIP = isIP;
41
44
  /**
42
45
  * Validates if value is an IP
43
46
  * @validator isIPRange
44
47
  */
45
48
  function isIPRange(version, options) {
46
- return (0, index_js_1.validator)('isIPRange', function (input, context, _this) {
47
- if (input != null && typeof input === 'string' && validatorJS.isIPRange(input, version))
49
+ return (0, index_js_1.validator)('isIPRange', (input, context, _this) => {
50
+ if (input != null &&
51
+ typeof input === 'string' &&
52
+ validatorJS.isIPRange(input, version)) {
48
53
  return input;
54
+ }
49
55
  context.fail(_this, `"{{value}}" is not a valid IP${version ? ' v' + version : ''} range`, input);
50
56
  }, options);
51
57
  }
52
- exports.isIPRange = isIPRange;