valgen 5.2.2 → 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 (176) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/cjs/core/context.js +7 -4
  3. package/cjs/core/validator.js +4 -4
  4. package/cjs/index.js +20 -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} +4 -4
  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} +13 -3
  35. package/cjs/rules/logical-rules/range.js +114 -0
  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} +5 -6
  38. package/cjs/rules/{is-bigint.js → type-rules/is-bigint.js} +5 -4
  39. package/cjs/rules/{is-boolean.js → type-rules/is-boolean.js} +5 -3
  40. package/cjs/rules/{is-date.js → type-rules/is-date.js} +12 -10
  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} +5 -3
  43. package/cjs/rules/type-rules/is-null.js +34 -0
  44. package/cjs/rules/{is-number.js → type-rules/is-number.js} +6 -4
  45. package/cjs/rules/{is-object.js → type-rules/is-object.js} +5 -5
  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} +3 -2
  48. package/cjs/rules/{is-tuple.js → type-rules/is-tuple.js} +5 -5
  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} +3 -3
  55. package/esm/core/context.js +7 -4
  56. package/esm/core/validator.js +4 -4
  57. package/esm/index.js +10 -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} +4 -4
  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} +13 -3
  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} +5 -6
  91. package/esm/rules/{is-bigint.js → type-rules/is-bigint.js} +5 -4
  92. package/esm/rules/{is-boolean.js → type-rules/is-boolean.js} +5 -3
  93. package/esm/rules/{is-date.js → type-rules/is-date.js} +12 -10
  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} +5 -3
  96. package/esm/rules/type-rules/is-null.js +29 -0
  97. package/esm/rules/{is-number.js → type-rules/is-number.js} +6 -4
  98. package/esm/rules/{is-object.js → type-rules/is-object.js} +5 -5
  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} +3 -2
  101. package/esm/rules/{is-tuple.js → type-rules/is-tuple.js} +5 -5
  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} +3 -3
  108. package/package.json +2 -2
  109. package/typings/core/types.d.ts +1 -0
  110. package/typings/index.d.ts +11 -4
  111. package/typings/rules/format-rules/is-alpha.d.ts +11 -0
  112. package/typings/rules/format-rules/is-ascii.d.ts +6 -0
  113. package/typings/rules/format-rules/is-base64.d.ts +9 -0
  114. package/typings/rules/format-rules/is-btc-address.d.ts +6 -0
  115. package/typings/rules/format-rules/is-credit-card.d.ts +9 -0
  116. package/typings/rules/format-rules/is-decimal.d.ts +7 -0
  117. package/typings/rules/format-rules/is-ean.d.ts +6 -0
  118. package/typings/rules/format-rules/is-email.d.ts +62 -0
  119. package/typings/rules/format-rules/is-eth-address.d.ts +6 -0
  120. package/typings/rules/format-rules/is-fqdn.d.ts +13 -0
  121. package/typings/rules/format-rules/is-hash.d.ts +8 -0
  122. package/typings/rules/format-rules/is-hex-color.d.ts +6 -0
  123. package/typings/rules/format-rules/is-hex.d.ts +6 -0
  124. package/typings/rules/format-rules/is-iban.d.ts +11 -0
  125. package/typings/rules/format-rules/is-ip.d.ts +11 -0
  126. package/typings/rules/format-rules/is-issn.d.ts +14 -0
  127. package/typings/rules/format-rules/is-jwt.d.ts +6 -0
  128. package/typings/rules/format-rules/is-lowercase.d.ts +11 -0
  129. package/typings/rules/format-rules/is-mac-address.d.ts +21 -0
  130. package/typings/rules/format-rules/is-mobile-phone.d.ts +20 -0
  131. package/typings/rules/{is-object-id.d.ts → format-rules/is-object-id.d.ts} +2 -2
  132. package/typings/rules/format-rules/is-passport-number.d.ts +6 -0
  133. package/typings/rules/format-rules/is-port.d.ts +6 -0
  134. package/typings/rules/format-rules/is-url.d.ts +9 -0
  135. package/typings/rules/format-rules/is-uuid.d.ts +6 -0
  136. package/typings/rules/format-rules/is-vat-number.d.ts +6 -0
  137. package/typings/rules/format-rules/matches.d.ts +9 -0
  138. package/typings/rules/index.d.ts +49 -22
  139. package/typings/rules/logical-rules/is-defined.d.ts +11 -0
  140. package/typings/rules/{is-empty.d.ts → logical-rules/is-empty.d.ts} +3 -3
  141. package/typings/rules/{range.d.ts → logical-rules/range.d.ts} +14 -4
  142. package/typings/rules/type-rules/is-any.d.ts +5 -0
  143. package/typings/rules/{is-array.d.ts → type-rules/is-array.d.ts} +2 -2
  144. package/typings/rules/{is-bigint.d.ts → type-rules/is-bigint.d.ts} +2 -2
  145. package/typings/rules/{is-boolean.d.ts → type-rules/is-boolean.d.ts} +2 -2
  146. package/typings/rules/{is-date.d.ts → type-rules/is-date.d.ts} +3 -3
  147. package/typings/rules/{is-enum.d.ts → type-rules/is-enum.d.ts} +1 -1
  148. package/typings/rules/{is-integer.d.ts → type-rules/is-integer.d.ts} +2 -2
  149. package/typings/rules/type-rules/is-null.d.ts +11 -0
  150. package/typings/rules/{is-number.d.ts → type-rules/is-number.d.ts} +2 -2
  151. package/typings/rules/{is-object.d.ts → type-rules/is-object.d.ts} +1 -1
  152. package/typings/rules/{is-record.d.ts → type-rules/is-record.d.ts} +2 -2
  153. package/typings/rules/{is-string.d.ts → type-rules/is-string.d.ts} +5 -5
  154. package/typings/rules/{is-tuple.d.ts → type-rules/is-tuple.d.ts} +2 -8
  155. package/typings/rules/utility-rules/exists.d.ts +6 -0
  156. package/typings/rules/utility-rules/get-length.d.ts +11 -0
  157. package/typings/rules/utility-rules/optional.d.ts +7 -0
  158. package/typings/rules/{pipe.d.ts → utility-rules/pipe.d.ts} +1 -1
  159. package/typings/rules/utility-rules/required.d.ts +7 -0
  160. package/typings/rules/utility-rules/union.d.ts +5 -0
  161. package/cjs/rules/is-null.js +0 -58
  162. package/cjs/rules/length.js +0 -41
  163. package/cjs/rules/optional.js +0 -44
  164. package/cjs/rules/range.js +0 -89
  165. package/cjs/rules/string-formats.js +0 -377
  166. package/esm/rules/is-null.js +0 -51
  167. package/esm/rules/length.js +0 -35
  168. package/esm/rules/optional.js +0 -38
  169. package/esm/rules/string-formats.js +0 -322
  170. package/typings/rules/is-any.d.ts +0 -5
  171. package/typings/rules/is-null.d.ts +0 -21
  172. package/typings/rules/is-regexp.d.ts +0 -9
  173. package/typings/rules/length.d.ts +0 -21
  174. package/typings/rules/optional.d.ts +0 -17
  175. package/typings/rules/string-formats.d.ts +0 -166
  176. package/typings/rules/union.d.ts +0 -5
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRegExp = void 0;
4
- const index_js_1 = require("../core/index.js");
3
+ exports.matches = void 0;
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Coerces given value to "UUID" format or returns undefined if nullish
7
7
  * @validator uuid
8
8
  */
9
- function isRegExp(format, options) {
9
+ function matches(format, options) {
10
10
  const regExp = format instanceof RegExp ? format : new RegExp(format);
11
11
  const formatName = options?.formatName;
12
12
  return (0, index_js_1.validator)('matches', function (input, context, _this) {
@@ -14,7 +14,10 @@ function isRegExp(format, options) {
14
14
  return;
15
15
  if (typeof input === 'string' && regExp.test(input))
16
16
  return input;
17
- context.fail(_this, `{{label}} does not match ${formatName || 'requested'} format`, input, { format, formatName });
17
+ context.fail(_this, `"{{value}}" does not match ${formatName || 'requested'} format`, input, {
18
+ format,
19
+ formatName,
20
+ });
18
21
  }, options);
19
22
  }
20
- exports.isRegExp = isRegExp;
23
+ exports.matches = matches;
@@ -14,25 +14,52 @@ 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("./is-any.js"), exports);
18
- __exportStar(require("./is-array.js"), exports);
19
- __exportStar(require("./is-bigint.js"), exports);
20
- __exportStar(require("./is-boolean.js"), exports);
21
- __exportStar(require("./is-date.js"), exports);
22
- __exportStar(require("./is-empty.js"), exports);
23
- __exportStar(require("./is-enum.js"), exports);
24
- __exportStar(require("./is-integer.js"), exports);
25
- __exportStar(require("./is-null.js"), exports);
26
- __exportStar(require("./is-regexp.js"), exports);
27
- __exportStar(require("./is-number.js"), exports);
28
- __exportStar(require("./is-object.js"), exports);
29
- __exportStar(require("./is-object-id.js"), exports);
30
- __exportStar(require("./is-record.js"), exports);
31
- __exportStar(require("./is-string.js"), exports);
32
- __exportStar(require("./is-tuple.js"), exports);
33
- __exportStar(require("./length.js"), exports);
34
- __exportStar(require("./optional.js"), exports);
35
- __exportStar(require("./pipe.js"), exports);
36
- __exportStar(require("./range.js"), exports);
37
- __exportStar(require("./string-formats.js"), exports);
38
- __exportStar(require("./union.js"), exports);
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
+ __exportStar(require("./format-rules/is-alpha.js"), exports);
31
+ __exportStar(require("./format-rules/is-ascii.js"), exports);
32
+ __exportStar(require("./format-rules/is-base64.js"), exports);
33
+ __exportStar(require("./format-rules/is-btc-address.js"), exports);
34
+ __exportStar(require("./format-rules/is-credit-card.js"), exports);
35
+ __exportStar(require("./format-rules/is-decimal.js"), exports);
36
+ __exportStar(require("./format-rules/is-ean.js"), exports);
37
+ __exportStar(require("./format-rules/is-email.js"), exports);
38
+ __exportStar(require("./format-rules/is-eth-address.js"), exports);
39
+ __exportStar(require("./format-rules/is-fqdn.js"), exports);
40
+ __exportStar(require("./format-rules/is-hash.js"), exports);
41
+ __exportStar(require("./format-rules/is-hex.js"), exports);
42
+ __exportStar(require("./format-rules/is-hex-color.js"), exports);
43
+ __exportStar(require("./format-rules/is-iban.js"), exports);
44
+ __exportStar(require("./format-rules/is-ip.js"), exports);
45
+ __exportStar(require("./format-rules/is-issn.js"), exports);
46
+ __exportStar(require("./format-rules/is-jwt.js"), exports);
47
+ __exportStar(require("./format-rules/is-lowercase.js"), exports);
48
+ __exportStar(require("./format-rules/is-mac-address.js"), exports);
49
+ __exportStar(require("./format-rules/is-mobile-phone.js"), exports);
50
+ __exportStar(require("./format-rules/is-object-id.js"), exports);
51
+ __exportStar(require("./format-rules/is-passport-number.js"), exports);
52
+ __exportStar(require("./format-rules/is-port.js"), exports);
53
+ __exportStar(require("./format-rules/is-url.js"), exports);
54
+ __exportStar(require("./format-rules/is-uuid.js"), exports);
55
+ __exportStar(require("./format-rules/is-vat-number.js"), exports);
56
+ __exportStar(require("./format-rules/matches.js"), exports);
57
+ __exportStar(require("./logical-rules/is-defined.js"), exports);
58
+ __exportStar(require("./logical-rules/is-empty.js"), exports);
59
+ __exportStar(require("./logical-rules/range.js"), exports);
60
+ __exportStar(require("./utility-rules/exists.js"), exports);
61
+ __exportStar(require("./utility-rules/get-length.js"), exports);
62
+ __exportStar(require("./utility-rules/optional.js"), exports);
63
+ __exportStar(require("./utility-rules/pipe.js"), exports);
64
+ __exportStar(require("./utility-rules/required.js"), exports);
65
+ __exportStar(require("./utility-rules/union.js"), exports);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUndefined = exports.isDefined = void 0;
4
+ const index_js_1 = require("../../core/index.js");
5
+ /**
6
+ * Validates if value is not "undefined" nor "null"
7
+ * @validator isDefined
8
+ */
9
+ function isDefined(options) {
10
+ return (0, index_js_1.validator)('is-defined', function (input, context, _this) {
11
+ if (input !== undefined)
12
+ return input;
13
+ context.fail(_this, `Is not defined`, input);
14
+ }, options);
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,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNotEmpty = exports.isEmpty = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Checks if value is an empty. Value should be string, array, set, map or object
7
7
  * @validator isEmpty
@@ -13,24 +13,29 @@ function isEmpty(options) {
13
13
  if (typeof input === 'string') {
14
14
  if (!input)
15
15
  return input;
16
+ context.fail(_this, `Is not an empty string`, input);
16
17
  }
17
18
  else if (Array.isArray(input)) {
18
19
  if (!input.length)
19
20
  return input;
21
+ context.fail(_this, `Is not an empty array`, input);
20
22
  }
21
23
  else if (input instanceof Set) {
22
24
  if (!input.size)
23
25
  return input;
26
+ context.fail(_this, `Is not an empty Set`, input);
24
27
  }
25
28
  else if (input instanceof Map) {
26
29
  if (!input.size)
27
30
  return input;
31
+ context.fail(_this, `Is not an empty Map`, input);
28
32
  }
29
33
  else if (typeof input === 'object') {
30
34
  if (!Object.keys(input).length)
31
35
  return input;
36
+ context.fail(_this, `Is not an empty Object`, input);
32
37
  }
33
- context.fail(_this, `{{label}} must be empty`, input);
38
+ context.fail(_this, `Is not empty`, input);
34
39
  }, options);
35
40
  }
36
41
  exports.isEmpty = isEmpty;
@@ -44,25 +49,30 @@ function isNotEmpty(options) {
44
49
  if (typeof input === 'string') {
45
50
  if (input)
46
51
  return input;
52
+ context.fail(_this, `Value is an empty string`, input);
47
53
  }
48
54
  else if (Array.isArray(input)) {
49
55
  if (input.length)
50
56
  return input;
57
+ context.fail(_this, `Value is an empty array`, input);
51
58
  }
52
59
  else if (input instanceof Set) {
53
60
  if (input.size)
54
61
  return input;
62
+ context.fail(_this, `Value is an empty Set`, input);
55
63
  }
56
64
  else if (input instanceof Map) {
57
65
  if (input.size)
58
66
  return input;
67
+ context.fail(_this, `Value is an empty Map`, input);
59
68
  }
60
69
  else if (typeof input === 'object') {
61
70
  if (Object.keys(input).length)
62
71
  return input;
72
+ context.fail(_this, `Value is an empty Object`, input);
63
73
  }
64
74
  }
65
- context.fail(_this, `{{label}} mustn't be empty`, input);
75
+ context.fail(_this, `Value is empty`, input);
66
76
  }, options);
67
77
  }
68
78
  exports.isNotEmpty = isNotEmpty;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lengthMax = exports.lengthMin = exports.isLte = exports.isLt = exports.isGte = exports.isGt = exports.range = void 0;
4
+ const index_js_1 = require("../../core/index.js");
5
+ const get_length_js_1 = require("../utility-rules/get-length.js");
6
+ const pipe_js_1 = require("../utility-rules/pipe.js");
7
+ /**
8
+ * Checks if value is between minValue and maxValue
9
+ * @validator range
10
+ */
11
+ function range(minValue, maxValue, options) {
12
+ return (0, index_js_1.validator)('range', function (input, context, _this) {
13
+ if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
14
+ (typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
15
+ (typeof input === 'number' || typeof input === 'bigint') &&
16
+ input >= minValue &&
17
+ input <= maxValue)
18
+ return input;
19
+ if (minValue instanceof Date &&
20
+ maxValue instanceof Date &&
21
+ input instanceof Date &&
22
+ input >= minValue &&
23
+ input <= maxValue)
24
+ return input;
25
+ if (typeof minValue === 'string' &&
26
+ typeof maxValue === 'string' &&
27
+ typeof input === 'string' &&
28
+ input >= minValue &&
29
+ input <= maxValue)
30
+ return input;
31
+ context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
32
+ }, options);
33
+ }
34
+ exports.range = range;
35
+ function isGt(minValue, options) {
36
+ return (0, index_js_1.validator)('isGt', function (input, context, _this) {
37
+ if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
38
+ (typeof input === 'number' || typeof input === 'bigint') &&
39
+ input > minValue)
40
+ return input;
41
+ if (minValue instanceof Date && input instanceof Date && input > minValue)
42
+ return input;
43
+ if (typeof minValue === 'string' &&
44
+ typeof input === 'string' &&
45
+ (input > minValue || (options?.caseInsensitive && input.toLowerCase() > minValue.toLowerCase())))
46
+ return input;
47
+ context.fail(_this, `{{label}} must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
48
+ }, options);
49
+ }
50
+ exports.isGt = isGt;
51
+ function isGte(minValue, options) {
52
+ return (0, index_js_1.validator)('isGte', function (input, context, _this) {
53
+ if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
54
+ (typeof input === 'number' || typeof input === 'bigint') &&
55
+ input >= minValue)
56
+ return input;
57
+ if (minValue instanceof Date && input instanceof Date && input >= minValue)
58
+ return input;
59
+ if (typeof minValue === 'string' &&
60
+ typeof input === 'string' &&
61
+ (input >= minValue || (options?.caseInsensitive && input.toLowerCase() >= minValue.toLowerCase())))
62
+ return input;
63
+ context.fail(_this, `{{label}} must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
64
+ }, options);
65
+ }
66
+ exports.isGte = isGte;
67
+ function isLt(maxValue, options) {
68
+ return (0, index_js_1.validator)('isLt', function (input, context, _this) {
69
+ if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
70
+ (typeof input === 'number' || typeof input === 'bigint') &&
71
+ input < maxValue)
72
+ return input;
73
+ if (maxValue instanceof Date && input instanceof Date && input < maxValue)
74
+ return input;
75
+ if (typeof maxValue === 'string' &&
76
+ typeof input === 'string' &&
77
+ (input < maxValue || (options?.caseInsensitive && input.toLowerCase() < maxValue.toLowerCase())))
78
+ return input;
79
+ context.fail(_this, `{{label}} must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
80
+ }, options);
81
+ }
82
+ exports.isLt = isLt;
83
+ function isLte(maxValue, options) {
84
+ return (0, index_js_1.validator)('isLte', function (input, context, _this) {
85
+ if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
86
+ (typeof input === 'number' || typeof input === 'bigint') &&
87
+ input <= maxValue)
88
+ return input;
89
+ if (maxValue instanceof Date && input instanceof Date && input <= maxValue)
90
+ return input;
91
+ if (typeof maxValue === 'string' &&
92
+ typeof input === 'string' &&
93
+ (input <= maxValue || (options?.caseInsensitive && input.toLowerCase() <= maxValue.toLowerCase())))
94
+ return input;
95
+ context.fail(_this, `{{label}} must be lover than or equal to ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
96
+ }, options);
97
+ }
98
+ exports.isLte = isLte;
99
+ /**
100
+ * Checks the length is at least "minValue"
101
+ * @validator lengthMin
102
+ */
103
+ const lengthMin = (minValue) => (0, pipe_js_1.allOf)((0, pipe_js_1.pipe)((0, get_length_js_1.getLength)(), isGte(minValue, {
104
+ onFail: () => `The length of {{label}} must be at least ${minValue}`,
105
+ })));
106
+ exports.lengthMin = lengthMin;
107
+ /**
108
+ * Checks if the length is at most "maxValue"
109
+ * @validator lengthMax
110
+ */
111
+ const lengthMax = (maxValue) => (0, pipe_js_1.allOf)((0, pipe_js_1.pipe)((0, get_length_js_1.getLength)(), isLte(maxValue, {
112
+ onFail: () => `The length of {{label}} must be at most ${maxValue}`,
113
+ })));
114
+ exports.lengthMax = lengthMax;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isAny = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Does nothing, just returns original input value.
7
7
  * @validator isAny
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isArray = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "array" and applies validation for each item.
7
7
  * Converts input value to array if coerce option is set to 'true'.
@@ -9,10 +9,11 @@ const index_js_1 = require("../core/index.js");
9
9
  */
10
10
  function isArray(itemValidator, options) {
11
11
  return (0, index_js_1.validator)('isArray', function (input, context, _this) {
12
- if (input != null && context.coerce && !Array.isArray(input))
12
+ const coerce = options?.coerce || context.coerce;
13
+ if (input != null && coerce && !Array.isArray(input))
13
14
  input = [input];
14
15
  if (!Array.isArray(input)) {
15
- context.fail(_this, `{{label}} must be an array`, input);
16
+ context.fail(_this, `"{{value}}" is not an array value`, input);
16
17
  return;
17
18
  }
18
19
  if (!itemValidator)
@@ -27,9 +28,7 @@ function isArray(itemValidator, options) {
27
28
  v = input[i];
28
29
  itemContext.scope = input;
29
30
  // itemContext.location = location + '[' + i + ']';
30
- itemContext.location = context.location
31
- ? context.location + `[${i}]`
32
- : `<Array>[${i}]`;
31
+ itemContext.location = context.location ? context.location + `[${i}]` : `<Array>[${i}]`;
33
32
  itemContext.index = i;
34
33
  v = itemValidator(v, itemContext);
35
34
  out.push(v);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isBigint = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "BigInt".
7
7
  * Converts input value to number if coerce option is set to 'true'.
@@ -9,12 +9,13 @@ const index_js_1 = require("../core/index.js");
9
9
  */
10
10
  function isBigint(options) {
11
11
  return (0, index_js_1.validator)('isBigint', function (input, context, _this) {
12
+ const coerce = options?.coerce || context.coerce;
12
13
  if (typeof input === 'bigint')
13
14
  return input;
14
- if ((typeof input === 'number' && !isNaN(input)) ||
15
- (typeof input === 'string' && context.coerce))
15
+ if ((typeof input === 'number' && !isNaN(input)) || (typeof input === 'string' && coerce))
16
16
  return BigInt(input);
17
- context.fail(_this, `{{label}} must be an integer number`, input);
17
+ const t = typeof input === 'string' ? 'String ' : '';
18
+ context.fail(_this, `${t}"{{value}}" is not a valid BigInt value`, input);
18
19
  }, options);
19
20
  }
20
21
  exports.isBigint = isBigint;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isBoolean = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  const TRUE_PATTERN = /^true|t|1|yes|y$/i;
6
6
  const FALSE_PATTERN = /^false|f|0|no|n$/i;
7
7
  /**
@@ -11,7 +11,8 @@ const FALSE_PATTERN = /^false|f|0|no|n$/i;
11
11
  */
12
12
  function isBoolean(options) {
13
13
  return (0, index_js_1.validator)('isBoolean', function (input, context, _this) {
14
- if (input != null && typeof input !== 'boolean' && context.coerce) {
14
+ const coerce = options?.coerce || context.coerce;
15
+ if (input != null && typeof input !== 'boolean' && coerce) {
15
16
  if (typeof input === 'string') {
16
17
  if (TRUE_PATTERN.test(input))
17
18
  return true;
@@ -24,7 +25,8 @@ function isBoolean(options) {
24
25
  }
25
26
  if (typeof input === 'boolean')
26
27
  return input;
27
- context.fail(_this, `{{label}} must be a boolean`, input);
28
+ const t = typeof input === 'string' ? 'String ' : '';
29
+ context.fail(_this, `${t}"{{value}}" is not a valid boolean value`, input);
28
30
  }, options);
29
31
  }
30
32
  exports.isBoolean = isBoolean;
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isDateString = exports.isDate = void 0;
4
4
  const date_fns_1 = require("date-fns");
5
- const index_js_1 = require("../core/index.js");
5
+ const index_js_1 = require("../../core/index.js");
6
6
  /* eslint-disable-next-line max-len */ // noinspection RegExpUnnecessaryNonCapturingGroup
7
- const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
7
+ const DATE_PATTERN =
8
+ // eslint-disable-next-line max-len
9
+ /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[T ](([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?(?:\.(\d{0,3}))?)?((?:[+-](0[0-9]|1[0-2])(?::(\d{2}))?)|Z)?)?$/;
8
10
  /**
9
11
  * Validates if value is instance of "Date".
10
12
  * Converts input value to Date if coerce option is set to 'true'.
@@ -13,11 +15,12 @@ const DATE_PATTERN = /^(\d{4})(?:-(0[0-9]|1[0-2]))?(?:-([0-2][0-9]|3[0-1]))?(?:[
13
15
  function isDate(options) {
14
16
  const precision = options?.precision;
15
17
  return (0, index_js_1.validator)('isDate', function (input, context, _this) {
18
+ const coerce = options?.coerce || context.coerce;
16
19
  let d;
17
20
  if (input instanceof Date)
18
21
  d = input;
19
- else if (input != null && context.coerce) {
20
- if (typeof input === 'string' && context.coerce) {
22
+ else if (input != null && coerce) {
23
+ if (typeof input === 'string' && coerce) {
21
24
  d = (0, date_fns_1.parseISO)(input);
22
25
  }
23
26
  else if (typeof input === 'number')
@@ -36,7 +39,7 @@ function isDate(options) {
36
39
  d.setHours(0, 0, 0, 0);
37
40
  return d;
38
41
  }
39
- context.fail(_this, `{{label}} must be a Date instance or a date string`, input);
42
+ context.fail(_this, `"{{value}}" is not a valid date value`, input, { ...options });
40
43
  }, options);
41
44
  }
42
45
  exports.isDate = isDate;
@@ -49,6 +52,7 @@ function isDateString(options) {
49
52
  const precision = options?.precision;
50
53
  const trim = options?.trim;
51
54
  return (0, index_js_1.validator)('isDateString', function (input, context, _this) {
55
+ const coerce = options?.coerce || context.coerce;
52
56
  if (typeof input === 'string') {
53
57
  const m = DATE_PATTERN.exec(input);
54
58
  if (m) {
@@ -59,7 +63,7 @@ function isDateString(options) {
59
63
  (precision === 'month' && m[2]) ||
60
64
  (precision === 'date' && m[2] && m[3]) ||
61
65
  (precision === 'time' && m[2] && m[3] && m[4])) {
62
- if (!context.coerce)
66
+ if (!coerce)
63
67
  return input;
64
68
  let s = m[1];
65
69
  if (m[2])
@@ -83,11 +87,9 @@ function isDateString(options) {
83
87
  }
84
88
  }
85
89
  else if (input instanceof Date) {
86
- return trim === 'date'
87
- ? (0, date_fns_1.formatISO)(input, { representation: 'date' })
88
- : (0, date_fns_1.formatISO)(input).substring(0, 19);
90
+ return trim === 'date' ? (0, date_fns_1.formatISO)(input, { representation: 'date' }) : (0, date_fns_1.formatISO)(input).substring(0, 19);
89
91
  }
90
- context.fail(_this, `{{label}} is not a valid date string`, input, { ...options });
92
+ context.fail(_this, `"{{value}}" is not a valid date string`, input, { ...options });
91
93
  }, options);
92
94
  }
93
95
  exports.isDateString = isDateString;
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEnum = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if given value is one of enum values.
7
7
  * @validator isEnum
8
8
  */
9
9
  function isEnum(values, options) {
10
- const caseInSensitive = !!(options?.caseInSensitive);
10
+ const caseInSensitive = !!options?.caseInSensitive;
11
11
  const enumName = options?.enumName;
12
12
  // Prepare an object for fast lookup
13
- const valObj = (Array.isArray(values) ? values : [values])
14
- .reduce((a, v) => {
13
+ const valObj = (Array.isArray(values) ? values : [values]).reduce((a, v) => {
15
14
  if (typeof v === 'string' && caseInSensitive)
16
15
  a[v.toUpperCase()] = true;
17
16
  else
@@ -21,7 +20,9 @@ function isEnum(values, options) {
21
20
  return (0, index_js_1.validator)('isEnum', function (input, context, _this) {
22
21
  if (input != null && valObj[typeof input === 'string' && caseInSensitive ? input.toUpperCase() : input])
23
22
  return input;
24
- context.fail(_this, `Value must be one of enumeration member${enumName ? ` (${enumName})` : ''}`, input, { enum: enumName });
23
+ context.fail(_this, `Value must be one of enumeration member${enumName ? ` (${enumName})` : ''}`, input, {
24
+ enum: enumName,
25
+ });
25
26
  }, options);
26
27
  }
27
28
  exports.isEnum = isEnum;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isInteger = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "integer".
7
7
  * Converts input value to integer number if coerce option is set to 'true'.
@@ -9,7 +9,8 @@ const index_js_1 = require("../core/index.js");
9
9
  */
10
10
  function isInteger(options) {
11
11
  return (0, index_js_1.validator)('isInteger', function (input, context, _this) {
12
- if (input != null && typeof input !== 'number' && context.coerce) {
12
+ const coerce = options?.coerce || context.coerce;
13
+ if (input != null && typeof input !== 'number' && coerce) {
13
14
  if (typeof input === 'string')
14
15
  input = parseFloat(input);
15
16
  if (typeof input === 'bigint') {
@@ -20,7 +21,8 @@ function isInteger(options) {
20
21
  }
21
22
  if (typeof input === 'number' && !isNaN(input) && Number.isInteger(input))
22
23
  return input;
23
- context.fail(_this, `{{label}} must be an integer number`, input);
24
+ const t = typeof input === 'bigint' ? 'BigInt ' : typeof input === 'string' ? 'String ' : '';
25
+ context.fail(_this, `${t}"{{value}}" is not a valid integer value`, input);
24
26
  }, options);
25
27
  }
26
28
  exports.isInteger = isInteger;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNullish = exports.isNull = void 0;
4
+ const index_js_1 = require("../../core/index.js");
5
+ /**
6
+ * Validates if value is "null".
7
+ * @validator isNull
8
+ */
9
+ function isNull(options) {
10
+ return (0, index_js_1.validator)('isNull', function (input, context, _this) {
11
+ if (input === null)
12
+ return input;
13
+ const coerce = options?.coerce || context.coerce;
14
+ if (coerce)
15
+ return null;
16
+ context.fail(_this, `"{{value}}" is not null`, input);
17
+ }, options);
18
+ }
19
+ exports.isNull = isNull;
20
+ /**
21
+ * Validates if value is "null" or "undefined".
22
+ * @validator isNull
23
+ */
24
+ function isNullish(options) {
25
+ return (0, index_js_1.validator)('isNullish', function (input, context, _this) {
26
+ if (input == null)
27
+ return input;
28
+ const coerce = options?.coerce || context.coerce;
29
+ if (coerce)
30
+ return null;
31
+ context.fail(_this, `"{{value}}" is not nullish`, input);
32
+ }, options);
33
+ }
34
+ exports.isNullish = isNullish;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNumber = void 0;
4
- const index_js_1 = require("../core/index.js");
4
+ const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "number".
7
7
  * Converts input value to number if coerce option is set to 'true'.
@@ -9,18 +9,20 @@ const index_js_1 = require("../core/index.js");
9
9
  */
10
10
  function isNumber(options) {
11
11
  return (0, index_js_1.validator)('isNumber', function (input, context, _this) {
12
- if (input != null && typeof input !== 'number' && context.coerce) {
12
+ const coerce = options?.coerce || context.coerce;
13
+ if (input != null && typeof input !== 'number' && coerce) {
13
14
  if (typeof input === 'string')
14
15
  input = parseFloat(input);
15
16
  if (typeof input === 'bigint') {
16
17
  const v = Number(input);
17
18
  if (input === BigInt(v))
18
- input = v;
19
+ return v;
19
20
  }
20
21
  }
21
22
  if (typeof input === 'number' && !isNaN(input))
22
23
  return input;
23
- context.fail(_this, `{{label}} must be a number`, input);
24
+ const t = typeof input === 'bigint' ? 'BigInt ' : typeof input === 'string' ? 'String ' : '';
25
+ context.fail(_this, `${t}"{{value}}" is not a valid number value`, input);
24
26
  }, options);
25
27
  }
26
28
  exports.isNumber = isNumber;