valgen 5.4.0 → 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 +17 -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 +4 -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 +2 -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 +2 -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
@@ -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.isISSN = void 0;
26
+ exports.isISSN = isISSN;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -35,10 +35,10 @@ function isISSN(options) {
35
35
  // eslint-disable-next-line camelcase
36
36
  case_sensitive: options?.caseSensitive,
37
37
  };
38
- return (0, index_js_1.validator)('isISSN', function (input, context, _this) {
39
- if (typeof input === 'string' && validatorJS.isISSN(input, opts))
38
+ return (0, index_js_1.validator)('isISSN', (input, context, _this) => {
39
+ if (typeof input === 'string' && validatorJS.isISSN(input, opts)) {
40
40
  return input;
41
+ }
41
42
  context.fail(_this, `"{{value}}" is not a valid ISSN`, input);
42
43
  }, options);
43
44
  }
44
- exports.isISSN = isISSN;
@@ -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.isJWT = void 0;
26
+ exports.isJWT = isJWT;
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 isJWT
32
32
  */
33
33
  function isJWT(options) {
34
- return (0, index_js_1.validator)('isJWT', function (input, context, _this) {
34
+ return (0, index_js_1.validator)('isJWT', (input, context, _this) => {
35
35
  if (typeof input === 'string' && validatorJS.isJWT(input))
36
36
  return input;
37
37
  context.fail(_this, `Value is not a valid JWT token`, input);
38
38
  }, options);
39
39
  }
40
- exports.isJWT = isJWT;
@@ -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.isUppercase = exports.isLowercase = void 0;
26
+ exports.isLowercase = isLowercase;
27
+ exports.isUppercase = isUppercase;
27
28
  const validatorJS = __importStar(require("validator"));
28
29
  const index_js_1 = require("../../core/index.js");
29
30
  /**
@@ -31,22 +32,22 @@ const index_js_1 = require("../../core/index.js");
31
32
  * @validator isLowercase
32
33
  */
33
34
  function isLowercase(options) {
34
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isLowercase(input))
35
+ return (0, index_js_1.validator)('isLowercase', (input, context, _this) => {
36
+ if (typeof input === 'string' && validatorJS.isLowercase(input)) {
36
37
  return input;
38
+ }
37
39
  context.fail(_this, `"{{value}}" is not a lowercase string`, input);
38
40
  }, options);
39
41
  }
40
- exports.isLowercase = isLowercase;
41
42
  /**
42
43
  * Validates if value a Uppercase string
43
44
  * @validator isUppercase
44
45
  */
45
46
  function isUppercase(options) {
46
- return (0, index_js_1.validator)('isUppercase', function (input, context, _this) {
47
- if (typeof input === 'string' && validatorJS.isUppercase(input))
47
+ return (0, index_js_1.validator)('isUppercase', (input, context, _this) => {
48
+ if (typeof input === 'string' && validatorJS.isUppercase(input)) {
48
49
  return input;
50
+ }
49
51
  context.fail(_this, `"{{value}}" is not an uppercase string`, input);
50
52
  }, options);
51
53
  }
52
- exports.isUppercase = isUppercase;
@@ -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.isMACAddress = void 0;
26
+ exports.isMACAddress = isMACAddress;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -36,10 +36,12 @@ function isMACAddress(options) {
36
36
  no_separators: options?.noSeparators,
37
37
  eui: options?.eui,
38
38
  };
39
- return (0, index_js_1.validator)('isMACAddress', function (input, context, _this) {
40
- if (input != null && typeof input === 'string' && validatorJS.isMACAddress(input, opts))
39
+ return (0, index_js_1.validator)('isMACAddress', (input, context, _this) => {
40
+ if (input != null &&
41
+ typeof input === 'string' &&
42
+ validatorJS.isMACAddress(input, opts)) {
41
43
  return input;
44
+ }
42
45
  context.fail(_this, `{{label}} is not a valid MAC address`, input);
43
46
  }, options);
44
47
  }
45
- exports.isMACAddress = isMACAddress;
@@ -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.isMobilePhone = void 0;
26
+ exports.isMobilePhone = isMobilePhone;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -34,10 +34,11 @@ function isMobilePhone(options) {
34
34
  const opts = {
35
35
  strictMode: options?.strictMode,
36
36
  };
37
- return (0, index_js_1.validator)('isMobilePhone', function (input, context, _this) {
38
- if (typeof input === 'string' && validatorJS.isMobilePhone(input, options?.locale, opts))
37
+ return (0, index_js_1.validator)('isMobilePhone', (input, context, _this) => {
38
+ if (typeof input === 'string' &&
39
+ validatorJS.isMobilePhone(input, options?.locale, opts)) {
39
40
  return input;
41
+ }
40
42
  context.fail(_this, `"{{value}}" is not a valid a Mobile Phone Number`, input);
41
43
  }, options);
42
44
  }
43
- exports.isMobilePhone = isMobilePhone;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isObjectId = void 0;
6
+ exports.isObjectId = isObjectId;
7
7
  const validator_1 = __importDefault(require("validator"));
8
8
  const index_js_1 = require("../../core/index.js");
9
9
  /**
@@ -11,18 +11,20 @@ const index_js_1 = require("../../core/index.js");
11
11
  * @validator isObjectId
12
12
  */
13
13
  function isObjectId(options) {
14
- return (0, index_js_1.validator)('isObjectId', function (input, context, _this) {
14
+ return (0, index_js_1.validator)('isObjectId', (input, context, _this) => {
15
15
  if (input != null &&
16
16
  (_isObjectIdValue(input) ||
17
17
  (typeof input === 'object' &&
18
18
  typeof input.toHexString === 'function' &&
19
- _isObjectIdValue(input.toHexString()))))
19
+ _isObjectIdValue(input.toHexString())))) {
20
20
  return input;
21
+ }
21
22
  context.fail(_this, `"{{value}}" is not a valid ObjectId`, input);
22
23
  }, options);
23
24
  }
24
- exports.isObjectId = isObjectId;
25
25
  function _isObjectIdValue(input) {
26
26
  return ((input instanceof Uint8Array && input.length === 12) ||
27
- (typeof input === 'string' && input.length === 24 && validator_1.default.isHexadecimal(input)));
27
+ (typeof input === 'string' &&
28
+ input.length === 24 &&
29
+ validator_1.default.isHexadecimal(input)));
28
30
  }
@@ -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.isPassportNumber = void 0;
26
+ exports.isPassportNumber = isPassportNumber;
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 isPassportNumber
32
32
  */
33
33
  function isPassportNumber(countryCode, options) {
34
- return (0, index_js_1.validator)('isPassportNumber', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isPassportNumber(input, countryCode))
34
+ return (0, index_js_1.validator)('isPassportNumber', (input, context, _this) => {
35
+ if (typeof input === 'string' &&
36
+ validatorJS.isPassportNumber(input, countryCode)) {
36
37
  return input;
38
+ }
37
39
  context.fail(_this, `"{{value}}" is not a valid ${countryCode} PassportNumber)`, input);
38
40
  }, options);
39
41
  }
40
- exports.isPassportNumber = isPassportNumber;
@@ -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.isPort = void 0;
26
+ exports.isPort = isPort;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,12 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isPort
32
32
  */
33
33
  function isPort(options) {
34
- return (0, index_js_1.validator)('isPort', function (input, context, _this) {
35
- if (input != null && typeof input === 'string' && validatorJS.isPort(input))
34
+ return (0, index_js_1.validator)('isPort', (input, context, _this) => {
35
+ if (input != null &&
36
+ typeof input === 'string' &&
37
+ validatorJS.isPort(input)) {
36
38
  return input;
39
+ }
37
40
  context.fail(_this, `{{label}} is not a valid port number`, input);
38
41
  }, options);
39
42
  }
40
- exports.isPort = isPort;
@@ -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.isURL = void 0;
26
+ exports.isURL = isURL;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,12 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isURL
32
32
  */
33
33
  function isURL(options) {
34
- return (0, index_js_1.validator)('isURL', function (input, context, _this) {
35
- if (input != null && typeof input === 'string' && validatorJS.isURL(input, options))
34
+ return (0, index_js_1.validator)('isURL', (input, context, _this) => {
35
+ if (input != null &&
36
+ typeof input === 'string' &&
37
+ validatorJS.isURL(input, options)) {
36
38
  return input;
39
+ }
37
40
  context.fail(_this, `{{value}} is not a valid URL`, input);
38
41
  }, options);
39
42
  }
40
- exports.isURL = isURL;
@@ -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.isUUID = void 0;
26
+ exports.isUUID = isUUID;
27
27
  const validatorJS = __importStar(require("validator"));
28
28
  const index_js_1 = require("../../core/index.js");
29
29
  /**
@@ -31,10 +31,12 @@ const index_js_1 = require("../../core/index.js");
31
31
  * @validator isUUID
32
32
  */
33
33
  function isUUID(version, options) {
34
- return (0, index_js_1.validator)('isUUID', function (input, context, _this) {
35
- if (input != null && typeof input === 'string' && validatorJS.isUUID(input, version))
34
+ return (0, index_js_1.validator)('isUUID', (input, context, _this) => {
35
+ if (input != null &&
36
+ typeof input === 'string' &&
37
+ validatorJS.isUUID(input, version)) {
36
38
  return input;
39
+ }
37
40
  context.fail(_this, `{{label}} is not a valid UUID${version ? ' v' + version : ''}`, input);
38
41
  }, options);
39
42
  }
40
- exports.isUUID = isUUID;
@@ -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.isVATNumber = void 0;
26
+ exports.isVATNumber = isVATNumber;
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 isVAT
32
32
  */
33
33
  function isVATNumber(countryCode, options) {
34
- return (0, index_js_1.validator)('isVATNumber', function (input, context, _this) {
35
- if (typeof input === 'string' && validatorJS.isVAT(input, countryCode))
34
+ return (0, index_js_1.validator)('isVATNumber', (input, context, _this) => {
35
+ if (typeof input === 'string' && validatorJS.isVAT(input, countryCode)) {
36
36
  return input;
37
+ }
37
38
  context.fail(_this, `"{{value}}" is not a valid VAT number`, input);
38
39
  }, options);
39
40
  }
40
- exports.isVATNumber = isVATNumber;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matches = void 0;
3
+ exports.matches = matches;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Coerces given value to "UUID" format or returns undefined if nullish
@@ -9,7 +9,7 @@ const index_js_1 = require("../../core/index.js");
9
9
  function matches(format, options) {
10
10
  const regExp = format instanceof RegExp ? format : new RegExp(format);
11
11
  const formatName = options?.formatName;
12
- return (0, index_js_1.validator)('matches', function (input, context, _this) {
12
+ return (0, index_js_1.validator)('matches', (input, context, _this) => {
13
13
  if (input == null)
14
14
  return;
15
15
  if (typeof input === 'string' && regExp.test(input))
@@ -20,4 +20,3 @@ function matches(format, options) {
20
20
  });
21
21
  }, options);
22
22
  }
23
- exports.matches = matches;
@@ -14,19 +14,6 @@ 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("./type-rules/is-any.js"), exports);
18
- __exportStar(require("./type-rules/is-array.js"), exports);
19
- __exportStar(require("./type-rules/is-bigint.js"), exports);
20
- __exportStar(require("./type-rules/is-boolean.js"), exports);
21
- __exportStar(require("./type-rules/is-date.js"), exports);
22
- __exportStar(require("./type-rules/is-enum.js"), exports);
23
- __exportStar(require("./type-rules/is-integer.js"), exports);
24
- __exportStar(require("./type-rules/is-null.js"), exports);
25
- __exportStar(require("./type-rules/is-number.js"), exports);
26
- __exportStar(require("./type-rules/is-object.js"), exports);
27
- __exportStar(require("./type-rules/is-record.js"), exports);
28
- __exportStar(require("./type-rules/is-string.js"), exports);
29
- __exportStar(require("./type-rules/is-tuple.js"), exports);
30
17
  __exportStar(require("./format-rules/is-alpha.js"), exports);
31
18
  __exportStar(require("./format-rules/is-ascii.js"), exports);
32
19
  __exportStar(require("./format-rules/is-base64.js"), exports);
@@ -57,6 +44,20 @@ __exportStar(require("./format-rules/matches.js"), exports);
57
44
  __exportStar(require("./logical-rules/is-defined.js"), exports);
58
45
  __exportStar(require("./logical-rules/is-empty.js"), exports);
59
46
  __exportStar(require("./logical-rules/range.js"), exports);
47
+ __exportStar(require("./type-rules/is-any.js"), exports);
48
+ __exportStar(require("./type-rules/is-array.js"), exports);
49
+ __exportStar(require("./type-rules/is-bigint.js"), exports);
50
+ __exportStar(require("./type-rules/is-boolean.js"), exports);
51
+ __exportStar(require("./type-rules/is-date.js"), exports);
52
+ __exportStar(require("./type-rules/is-enum.js"), exports);
53
+ __exportStar(require("./type-rules/is-integer.js"), exports);
54
+ __exportStar(require("./type-rules/is-null.js"), exports);
55
+ __exportStar(require("./type-rules/is-number.js"), exports);
56
+ __exportStar(require("./type-rules/is-object.js"), exports);
57
+ __exportStar(require("./type-rules/is-record.js"), exports);
58
+ __exportStar(require("./type-rules/is-string.js"), exports);
59
+ __exportStar(require("./type-rules/is-tuple.js"), exports);
60
+ __exportStar(require("./type-rules/is-undefined.js"), exports);
60
61
  __exportStar(require("./utility-rules/exists.js"), exports);
61
62
  __exportStar(require("./utility-rules/get-length.js"), exports);
62
63
  __exportStar(require("./utility-rules/optional.js"), exports);
@@ -1,30 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUndefined = exports.isDefined = void 0;
3
+ exports.isDefined = isDefined;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is not "undefined" nor "null"
7
7
  * @validator isDefined
8
8
  */
9
9
  function isDefined(options) {
10
- return (0, index_js_1.validator)('is-defined', function (input, context, _this) {
10
+ return (0, index_js_1.validator)('is-defined', (input, context, _this) => {
11
11
  if (input !== undefined)
12
12
  return input;
13
13
  context.fail(_this, `Is not defined`, input);
14
14
  }, options);
15
15
  }
16
- exports.isDefined = isDefined;
17
- /**
18
- * Validates if value is "undefined"
19
- * @validator isUndefined
20
- */
21
- function isUndefined(options) {
22
- return (0, index_js_1.validator)('isUndefined', function (input, context, _this) {
23
- if (options?.coerce || context.coerce)
24
- return undefined;
25
- if (input === undefined)
26
- return;
27
- context.fail(_this, `{{label}} mustn\'t be defined`, input);
28
- }, options);
29
- }
30
- exports.isUndefined = isUndefined;
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNotEmpty = exports.isEmpty = void 0;
3
+ exports.isEmpty = isEmpty;
4
+ exports.isNotEmpty = isNotEmpty;
4
5
  const index_js_1 = require("../../core/index.js");
5
6
  /**
6
7
  * Checks if value is an empty. Value should be string, array, set, map or object
7
8
  * @validator isEmpty
8
9
  */
9
10
  function isEmpty(options) {
10
- return (0, index_js_1.validator)('isEmpty', function (input, context, _this) {
11
+ return (0, index_js_1.validator)('isEmpty', (input, context, _this) => {
11
12
  if (input == null)
12
13
  return input;
13
14
  if (typeof input === 'string') {
@@ -38,13 +39,12 @@ function isEmpty(options) {
38
39
  context.fail(_this, `Is not empty`, input);
39
40
  }, options);
40
41
  }
41
- exports.isEmpty = isEmpty;
42
42
  /**
43
43
  * Checks if value is a not empty. Value should be string, array, set, map or object
44
44
  * @validator isNotEmpty
45
45
  */
46
46
  function isNotEmpty(options) {
47
- return (0, index_js_1.validator)('isNotEmpty', function (input, context, _this) {
47
+ return (0, index_js_1.validator)('isNotEmpty', (input, context, _this) => {
48
48
  if (input != null) {
49
49
  if (typeof input === 'string') {
50
50
  if (input)
@@ -75,4 +75,3 @@ function isNotEmpty(options) {
75
75
  context.fail(_this, `Value is empty`, input);
76
76
  }, options);
77
77
  }
78
- exports.isNotEmpty = isNotEmpty;
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lengthMax = exports.lengthMin = exports.isLte = exports.isLt = exports.isGte = exports.isGt = exports.range = void 0;
3
+ exports.lengthMax = exports.lengthMin = void 0;
4
+ exports.range = range;
5
+ exports.isGt = isGt;
6
+ exports.isGte = isGte;
7
+ exports.isLt = isLt;
8
+ exports.isLte = isLte;
4
9
  const index_js_1 = require("../../core/index.js");
5
10
  const get_length_js_1 = require("../utility-rules/get-length.js");
6
11
  const pipe_js_1 = require("../utility-rules/pipe.js");
@@ -9,93 +14,119 @@ const pipe_js_1 = require("../utility-rules/pipe.js");
9
14
  * @validator range
10
15
  */
11
16
  function range(minValue, maxValue, options) {
12
- return (0, index_js_1.validator)('range', function (input, context, _this) {
17
+ return (0, index_js_1.validator)('range', (input, context, _this) => {
13
18
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
14
19
  (typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
15
20
  (typeof input === 'number' || typeof input === 'bigint') &&
16
21
  input >= minValue &&
17
- input <= maxValue)
22
+ input <= maxValue) {
18
23
  return input;
24
+ }
19
25
  if (minValue instanceof Date &&
20
26
  maxValue instanceof Date &&
21
27
  input instanceof Date &&
22
28
  input >= minValue &&
23
- input <= maxValue)
29
+ input <= maxValue) {
24
30
  return input;
31
+ }
25
32
  if (typeof minValue === 'string' &&
26
33
  typeof maxValue === 'string' &&
27
34
  typeof input === 'string' &&
28
35
  input >= minValue &&
29
- input <= maxValue)
36
+ input <= maxValue) {
30
37
  return input;
38
+ }
31
39
  context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
32
40
  }, options);
33
41
  }
34
- exports.range = range;
35
42
  function isGt(minValue, options) {
36
- return (0, index_js_1.validator)('isGt', function (input, context, _this) {
43
+ return (0, index_js_1.validator)('isGt', (input, context, _this) => {
37
44
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
38
45
  (typeof input === 'number' || typeof input === 'bigint') &&
39
- input > minValue)
46
+ input > minValue) {
40
47
  return input;
41
- if (minValue instanceof Date && input instanceof Date && input > minValue)
48
+ }
49
+ if (minValue instanceof Date &&
50
+ input instanceof Date &&
51
+ input > minValue) {
42
52
  return input;
53
+ }
43
54
  if (typeof minValue === 'string' &&
44
55
  typeof input === 'string' &&
45
- (input > minValue || (options?.caseInsensitive && input.toLowerCase() > minValue.toLowerCase())))
56
+ (input > minValue ||
57
+ (options?.caseInsensitive &&
58
+ input.toLowerCase() > minValue.toLowerCase()))) {
46
59
  return input;
60
+ }
47
61
  context.fail(_this, `{{label}} must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
48
62
  }, options);
49
63
  }
50
- exports.isGt = isGt;
51
64
  function isGte(minValue, options) {
52
- return (0, index_js_1.validator)('isGte', function (input, context, _this) {
65
+ return (0, index_js_1.validator)('isGte', (input, context, _this) => {
53
66
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
54
67
  (typeof input === 'number' || typeof input === 'bigint') &&
55
- input >= minValue)
68
+ input >= minValue) {
56
69
  return input;
57
- if (minValue instanceof Date && input instanceof Date && input >= minValue)
70
+ }
71
+ if (minValue instanceof Date &&
72
+ input instanceof Date &&
73
+ input >= minValue) {
58
74
  return input;
75
+ }
59
76
  if (typeof minValue === 'string' &&
60
77
  typeof input === 'string' &&
61
- (input >= minValue || (options?.caseInsensitive && input.toLowerCase() >= minValue.toLowerCase())))
78
+ (input >= minValue ||
79
+ (options?.caseInsensitive &&
80
+ input.toLowerCase() >= minValue.toLowerCase()))) {
62
81
  return input;
82
+ }
63
83
  context.fail(_this, `{{label}} must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
64
84
  }, options);
65
85
  }
66
- exports.isGte = isGte;
67
86
  function isLt(maxValue, options) {
68
- return (0, index_js_1.validator)('isLt', function (input, context, _this) {
87
+ return (0, index_js_1.validator)('isLt', (input, context, _this) => {
69
88
  if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
70
89
  (typeof input === 'number' || typeof input === 'bigint') &&
71
- input < maxValue)
90
+ input < maxValue) {
72
91
  return input;
73
- if (maxValue instanceof Date && input instanceof Date && input < maxValue)
92
+ }
93
+ if (maxValue instanceof Date &&
94
+ input instanceof Date &&
95
+ input < maxValue) {
74
96
  return input;
97
+ }
75
98
  if (typeof maxValue === 'string' &&
76
99
  typeof input === 'string' &&
77
- (input < maxValue || (options?.caseInsensitive && input.toLowerCase() < maxValue.toLowerCase())))
100
+ (input < maxValue ||
101
+ (options?.caseInsensitive &&
102
+ input.toLowerCase() < maxValue.toLowerCase()))) {
78
103
  return input;
104
+ }
79
105
  context.fail(_this, `{{label}} must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
80
106
  }, options);
81
107
  }
82
- exports.isLt = isLt;
83
108
  function isLte(maxValue, options) {
84
- return (0, index_js_1.validator)('isLte', function (input, context, _this) {
109
+ return (0, index_js_1.validator)('isLte', (input, context, _this) => {
85
110
  if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
86
111
  (typeof input === 'number' || typeof input === 'bigint') &&
87
- input <= maxValue)
112
+ input <= maxValue) {
88
113
  return input;
89
- if (maxValue instanceof Date && input instanceof Date && input <= maxValue)
114
+ }
115
+ if (maxValue instanceof Date &&
116
+ input instanceof Date &&
117
+ input <= maxValue) {
90
118
  return input;
119
+ }
91
120
  if (typeof maxValue === 'string' &&
92
121
  typeof input === 'string' &&
93
- (input <= maxValue || (options?.caseInsensitive && input.toLowerCase() <= maxValue.toLowerCase())))
122
+ (input <= maxValue ||
123
+ (options?.caseInsensitive &&
124
+ input.toLowerCase() <= maxValue.toLowerCase()))) {
94
125
  return input;
126
+ }
95
127
  context.fail(_this, `{{label}} must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
96
128
  }, options);
97
129
  }
98
- exports.isLte = isLte;
99
130
  /**
100
131
  * Checks the length is at least "minValue"
101
132
  * @validator lengthMin
@@ -6,7 +6,5 @@ const index_js_1 = require("../../core/index.js");
6
6
  * Does nothing, just returns original input value.
7
7
  * @validator isAny
8
8
  */
9
- const isAny = () => (0, index_js_1.validator)('is-any', function (input) {
10
- return input;
11
- });
9
+ const isAny = () => (0, index_js_1.validator)('is-any', (input) => input);
12
10
  exports.isAny = isAny;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isArray = void 0;
3
+ exports.isArray = isArray;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "array" and applies validation for each item.
@@ -8,7 +8,7 @@ const index_js_1 = require("../../core/index.js");
8
8
  * @validator isArray
9
9
  */
10
10
  function isArray(itemValidator, options) {
11
- return (0, index_js_1.validator)('isArray', function (input, context, _this) {
11
+ return (0, index_js_1.validator)('isArray', (input, context, _this) => {
12
12
  const coerce = options?.coerce || context.coerce;
13
13
  let output = input;
14
14
  if (output != null && coerce && !Array.isArray(output))
@@ -29,7 +29,9 @@ function isArray(itemValidator, options) {
29
29
  v = output[i];
30
30
  itemContext.scope = output;
31
31
  // itemContext.location = location + '[' + i + ']';
32
- itemContext.location = context.location ? context.location + `[${i}]` : `<Array>[${i}]`;
32
+ itemContext.location = context.location
33
+ ? context.location + `[${i}]`
34
+ : `<Array>[${i}]`;
33
35
  itemContext.index = i;
34
36
  v = itemValidator(v, itemContext);
35
37
  out.push(v);
@@ -37,4 +39,3 @@ function isArray(itemValidator, options) {
37
39
  return out;
38
40
  }, options);
39
41
  }
40
- exports.isArray = isArray;