valgen 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/cjs/core/context.js +2 -3
  3. package/cjs/core/validator.js +4 -4
  4. package/cjs/index.js +5 -5
  5. package/cjs/rules/format-rules/is-alpha.js +52 -0
  6. package/cjs/rules/format-rules/is-ascii.js +40 -0
  7. package/cjs/rules/format-rules/is-base64.js +40 -0
  8. package/cjs/rules/format-rules/is-btc-address.js +40 -0
  9. package/cjs/rules/format-rules/is-credit-card.js +40 -0
  10. package/cjs/rules/format-rules/is-decimal.js +41 -0
  11. package/cjs/rules/format-rules/is-ean.js +40 -0
  12. package/cjs/rules/format-rules/is-email.js +97 -0
  13. package/cjs/rules/format-rules/is-eth-address.js +40 -0
  14. package/cjs/rules/format-rules/is-fqdn.js +44 -0
  15. package/cjs/rules/format-rules/is-hash.js +40 -0
  16. package/cjs/rules/format-rules/is-hex-color.js +40 -0
  17. package/cjs/rules/format-rules/is-hex.js +40 -0
  18. package/cjs/rules/format-rules/is-iban.js +52 -0
  19. package/cjs/rules/format-rules/is-ip.js +52 -0
  20. package/cjs/rules/format-rules/is-issn.js +44 -0
  21. package/cjs/rules/format-rules/is-jwt.js +40 -0
  22. package/cjs/rules/format-rules/is-lowercase.js +52 -0
  23. package/cjs/rules/format-rules/is-mac-address.js +45 -0
  24. package/cjs/rules/format-rules/is-mobile-phone.js +43 -0
  25. package/cjs/rules/{is-object-id.js → format-rules/is-object-id.js} +3 -3
  26. package/cjs/rules/format-rules/is-passport-number.js +40 -0
  27. package/cjs/rules/format-rules/is-port.js +40 -0
  28. package/cjs/rules/format-rules/is-url.js +40 -0
  29. package/cjs/rules/format-rules/is-uuid.js +40 -0
  30. package/cjs/rules/format-rules/is-vat-number.js +40 -0
  31. package/cjs/rules/{is-regexp.js → format-rules/matches.js} +8 -5
  32. package/cjs/rules/index.js +49 -22
  33. package/cjs/rules/logical-rules/is-defined.js +30 -0
  34. package/cjs/rules/{is-empty.js → logical-rules/is-empty.js} +1 -1
  35. package/cjs/rules/{range.js → logical-rules/range.js} +63 -38
  36. package/cjs/rules/{is-any.js → type-rules/is-any.js} +1 -1
  37. package/cjs/rules/{is-array.js → type-rules/is-array.js} +2 -4
  38. package/cjs/rules/{is-bigint.js → type-rules/is-bigint.js} +2 -3
  39. package/cjs/rules/{is-boolean.js → type-rules/is-boolean.js} +1 -1
  40. package/cjs/rules/{is-date.js → type-rules/is-date.js} +5 -5
  41. package/cjs/rules/{is-enum.js → type-rules/is-enum.js} +6 -5
  42. package/cjs/rules/{is-integer.js → type-rules/is-integer.js} +2 -3
  43. package/cjs/rules/{is-null.js → type-rules/is-null.js} +2 -28
  44. package/cjs/rules/{is-number.js → type-rules/is-number.js} +2 -3
  45. package/cjs/rules/{is-object.js → type-rules/is-object.js} +3 -4
  46. package/cjs/rules/{is-record.js → type-rules/is-record.js} +1 -1
  47. package/cjs/rules/{is-string.js → type-rules/is-string.js} +1 -1
  48. package/cjs/rules/{is-tuple.js → type-rules/is-tuple.js} +2 -3
  49. package/cjs/rules/utility-rules/exists.js +16 -0
  50. package/cjs/rules/utility-rules/get-length.js +24 -0
  51. package/cjs/rules/utility-rules/optional.js +16 -0
  52. package/cjs/rules/{pipe.js → utility-rules/pipe.js} +1 -1
  53. package/cjs/rules/utility-rules/required.js +18 -0
  54. package/cjs/rules/{union.js → utility-rules/union.js} +2 -2
  55. package/esm/core/context.js +2 -3
  56. package/esm/core/validator.js +4 -4
  57. package/esm/index.js +3 -3
  58. package/esm/rules/format-rules/is-alpha.js +24 -0
  59. package/esm/rules/format-rules/is-ascii.js +13 -0
  60. package/esm/rules/format-rules/is-base64.js +13 -0
  61. package/esm/rules/format-rules/is-btc-address.js +13 -0
  62. package/esm/rules/format-rules/is-credit-card.js +13 -0
  63. package/esm/rules/format-rules/is-decimal.js +14 -0
  64. package/esm/rules/format-rules/is-ean.js +13 -0
  65. package/esm/rules/format-rules/is-email.js +70 -0
  66. package/esm/rules/format-rules/is-eth-address.js +13 -0
  67. package/esm/rules/format-rules/is-fqdn.js +17 -0
  68. package/esm/rules/format-rules/is-hash.js +13 -0
  69. package/esm/rules/format-rules/is-hex-color.js +13 -0
  70. package/esm/rules/format-rules/is-hex.js +13 -0
  71. package/esm/rules/format-rules/is-iban.js +24 -0
  72. package/esm/rules/format-rules/is-ip.js +24 -0
  73. package/esm/rules/format-rules/is-issn.js +17 -0
  74. package/esm/rules/format-rules/is-jwt.js +13 -0
  75. package/esm/rules/format-rules/is-lowercase.js +24 -0
  76. package/esm/rules/format-rules/is-mac-address.js +18 -0
  77. package/esm/rules/format-rules/is-mobile-phone.js +16 -0
  78. package/esm/rules/{is-object-id.js → format-rules/is-object-id.js} +3 -3
  79. package/esm/rules/format-rules/is-passport-number.js +13 -0
  80. package/esm/rules/format-rules/is-port.js +13 -0
  81. package/esm/rules/format-rules/is-url.js +13 -0
  82. package/esm/rules/format-rules/is-uuid.js +13 -0
  83. package/esm/rules/format-rules/is-vat-number.js +13 -0
  84. package/esm/rules/{is-regexp.js → format-rules/matches.js} +6 -3
  85. package/esm/rules/index.js +49 -22
  86. package/esm/rules/logical-rules/is-defined.js +25 -0
  87. package/esm/rules/{is-empty.js → logical-rules/is-empty.js} +1 -1
  88. package/esm/rules/{range.js → logical-rules/range.js} +59 -36
  89. package/esm/rules/{is-any.js → type-rules/is-any.js} +1 -1
  90. package/esm/rules/{is-array.js → type-rules/is-array.js} +2 -4
  91. package/esm/rules/{is-bigint.js → type-rules/is-bigint.js} +2 -3
  92. package/esm/rules/{is-boolean.js → type-rules/is-boolean.js} +1 -1
  93. package/esm/rules/{is-date.js → type-rules/is-date.js} +5 -5
  94. package/esm/rules/{is-enum.js → type-rules/is-enum.js} +6 -5
  95. package/esm/rules/{is-integer.js → type-rules/is-integer.js} +2 -3
  96. package/esm/rules/{is-null.js → type-rules/is-null.js} +1 -25
  97. package/esm/rules/{is-number.js → type-rules/is-number.js} +2 -3
  98. package/esm/rules/{is-object.js → type-rules/is-object.js} +3 -4
  99. package/esm/rules/{is-record.js → type-rules/is-record.js} +1 -1
  100. package/esm/rules/{is-string.js → type-rules/is-string.js} +1 -1
  101. package/esm/rules/{is-tuple.js → type-rules/is-tuple.js} +2 -3
  102. package/esm/rules/utility-rules/exists.js +12 -0
  103. package/esm/rules/utility-rules/get-length.js +20 -0
  104. package/esm/rules/utility-rules/optional.js +12 -0
  105. package/esm/rules/{pipe.js → utility-rules/pipe.js} +1 -1
  106. package/esm/rules/utility-rules/required.js +14 -0
  107. package/esm/rules/{union.js → utility-rules/union.js} +2 -2
  108. package/package.json +3 -3
  109. package/typings/index.d.ts +4 -4
  110. package/typings/rules/format-rules/is-alpha.d.ts +11 -0
  111. package/typings/rules/format-rules/is-ascii.d.ts +6 -0
  112. package/typings/rules/format-rules/is-base64.d.ts +9 -0
  113. package/typings/rules/format-rules/is-btc-address.d.ts +6 -0
  114. package/typings/rules/format-rules/is-credit-card.d.ts +9 -0
  115. package/typings/rules/format-rules/is-decimal.d.ts +7 -0
  116. package/typings/rules/format-rules/is-ean.d.ts +6 -0
  117. package/typings/rules/format-rules/is-email.d.ts +62 -0
  118. package/typings/rules/format-rules/is-eth-address.d.ts +6 -0
  119. package/typings/rules/format-rules/is-fqdn.d.ts +13 -0
  120. package/typings/rules/format-rules/is-hash.d.ts +8 -0
  121. package/typings/rules/format-rules/is-hex-color.d.ts +6 -0
  122. package/typings/rules/format-rules/is-hex.d.ts +6 -0
  123. package/typings/rules/format-rules/is-iban.d.ts +11 -0
  124. package/typings/rules/format-rules/is-ip.d.ts +11 -0
  125. package/typings/rules/format-rules/is-issn.d.ts +14 -0
  126. package/typings/rules/format-rules/is-jwt.d.ts +6 -0
  127. package/typings/rules/format-rules/is-lowercase.d.ts +11 -0
  128. package/typings/rules/format-rules/is-mac-address.d.ts +21 -0
  129. package/typings/rules/format-rules/is-mobile-phone.d.ts +20 -0
  130. package/typings/rules/{is-object-id.d.ts → format-rules/is-object-id.d.ts} +2 -2
  131. package/typings/rules/format-rules/is-passport-number.d.ts +6 -0
  132. package/typings/rules/format-rules/is-port.d.ts +6 -0
  133. package/typings/rules/format-rules/is-url.d.ts +9 -0
  134. package/typings/rules/format-rules/is-uuid.d.ts +6 -0
  135. package/typings/rules/format-rules/is-vat-number.d.ts +6 -0
  136. package/typings/rules/format-rules/matches.d.ts +9 -0
  137. package/typings/rules/index.d.ts +49 -22
  138. package/typings/rules/logical-rules/is-defined.d.ts +11 -0
  139. package/typings/rules/{is-empty.d.ts → logical-rules/is-empty.d.ts} +3 -3
  140. package/typings/rules/{range.d.ts → logical-rules/range.d.ts} +14 -4
  141. package/typings/rules/type-rules/is-any.d.ts +5 -0
  142. package/typings/rules/{is-array.d.ts → type-rules/is-array.d.ts} +2 -2
  143. package/typings/rules/{is-bigint.d.ts → type-rules/is-bigint.d.ts} +2 -2
  144. package/typings/rules/{is-boolean.d.ts → type-rules/is-boolean.d.ts} +2 -2
  145. package/typings/rules/{is-date.d.ts → type-rules/is-date.d.ts} +3 -3
  146. package/typings/rules/{is-enum.d.ts → type-rules/is-enum.d.ts} +1 -1
  147. package/typings/rules/{is-integer.d.ts → type-rules/is-integer.d.ts} +2 -2
  148. package/typings/rules/type-rules/is-null.d.ts +11 -0
  149. package/typings/rules/{is-number.d.ts → type-rules/is-number.d.ts} +2 -2
  150. package/typings/rules/{is-object.d.ts → type-rules/is-object.d.ts} +1 -1
  151. package/typings/rules/{is-record.d.ts → type-rules/is-record.d.ts} +2 -2
  152. package/typings/rules/{is-string.d.ts → type-rules/is-string.d.ts} +5 -5
  153. package/typings/rules/{is-tuple.d.ts → type-rules/is-tuple.d.ts} +2 -8
  154. package/typings/rules/utility-rules/exists.d.ts +6 -0
  155. package/typings/rules/utility-rules/get-length.d.ts +11 -0
  156. package/typings/rules/utility-rules/optional.d.ts +7 -0
  157. package/typings/rules/{pipe.d.ts → utility-rules/pipe.d.ts} +1 -1
  158. package/typings/rules/utility-rules/required.d.ts +7 -0
  159. package/typings/rules/utility-rules/union.d.ts +5 -0
  160. package/cjs/rules/length.js +0 -41
  161. package/cjs/rules/optional.js +0 -44
  162. package/cjs/rules/string-formats.js +0 -377
  163. package/esm/rules/length.js +0 -35
  164. package/esm/rules/optional.js +0 -38
  165. package/esm/rules/string-formats.js +0 -322
  166. package/typings/rules/is-any.d.ts +0 -5
  167. package/typings/rules/is-null.d.ts +0 -21
  168. package/typings/rules/is-regexp.d.ts +0 -9
  169. package/typings/rules/length.d.ts +0 -21
  170. package/typings/rules/optional.d.ts +0 -17
  171. package/typings/rules/string-formats.d.ts +0 -166
  172. package/typings/rules/union.d.ts +0 -5
@@ -1,10 +1,10 @@
1
- import { ValidationOptions } from '../core/index.js';
1
+ import { ValidationOptions } from '../../core/index.js';
2
2
  /**
3
3
  * Validates if value is "string".
4
4
  * Converts input value to string if coerce option is set to 'true'.
5
5
  * @validator isString
6
6
  */
7
- export declare function isString(options?: ValidationOptions): import("../core/validator.js").Validator<string, unknown, import("../core/types.js").ExecutionOptions>;
7
+ export declare function isString(options?: ValidationOptions): import("../../core/validator.js").Validator<string, unknown, import("../../core/types.js").ExecutionOptions>;
8
8
  /**
9
9
  * Process "String.replace" method
10
10
  * @validator stringReplace
@@ -29,14 +29,14 @@ export declare function stringSplit(splitter: {
29
29
  * Removes whitespace from both ends of a string
30
30
  * @validator trim
31
31
  */
32
- export declare function trim(): import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
32
+ export declare function trim(): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
33
33
  /**
34
34
  * Removes whitespace from the end of a string
35
35
  * @validator trimEnd
36
36
  */
37
- export declare const trimEnd: () => import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
37
+ export declare const trimEnd: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
38
38
  /**
39
39
  * Removes whitespace from the beginning of a string
40
40
  * @validator trimStart
41
41
  */
42
- export declare const trimStart: () => import("../core/validator.js").Validator<string, string, import("../core/types.js").ExecutionOptions>;
42
+ export declare const trimStart: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
@@ -1,4 +1,4 @@
1
- import { ValidationOptions, Validator } from '../core/index.js';
1
+ import { ValidationOptions, Validator } from '../../core/index.js';
2
2
  /**
3
3
  * Validates if value is "tuple" and applies validation for each item.
4
4
  * Converts input value to tuple if coerce option is set to 'true'.
@@ -9,13 +9,7 @@ export declare function isTuple<T1, I1, T2, I2>(items: [Validator<T1, I1>, Valid
9
9
  export declare function isTuple<T1, I1, T2, I2, T3, I3>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>], options?: ValidationOptions): Validator<[T1, T2, T3], [I1, I2, I3]>;
10
10
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>, Validator<T4, I4>], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
11
11
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>, Validator<T4, I4>], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
12
- export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5>(items: [
13
- Validator<T1, I1>,
14
- Validator<T2, I2>,
15
- Validator<T3, I3>,
16
- Validator<T4, I4>,
17
- Validator<T5, I5>
18
- ], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5], [I1, I2, I3, I4, I5]>;
12
+ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>, Validator<T4, I4>, Validator<T5, I5>], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5], [I1, I2, I3, I4, I5]>;
19
13
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(items: [
20
14
  Validator<T1, I1>,
21
15
  Validator<T2, I2>,
@@ -0,0 +1,6 @@
1
+ import { ValidationOptions } from '../../core/index.js';
2
+ /**
3
+ * Validates if property exists
4
+ * @validator exists
5
+ */
6
+ export declare function exists(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
@@ -0,0 +1,11 @@
1
+ type ExtractLengthInput = string | any[] | ArrayBuffer | {
2
+ length: number;
3
+ } | {
4
+ size: number;
5
+ };
6
+ /**
7
+ * Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
8
+ * @validator getLength
9
+ */
10
+ export declare function getLength(): import("../../core/validator.js").Validator<number, ExtractLengthInput, import("../../core/types.js").ExecutionOptions>;
11
+ export {};
@@ -0,0 +1,7 @@
1
+ import { Nullish } from 'ts-gems';
2
+ import { ValidationOptions, Validator } from '../../core/index.js';
3
+ /**
4
+ * Makes sub-rule optional
5
+ * @validator optional
6
+ */
7
+ export declare function optional<T, I>(nested: Validator<T, I>, options?: ValidationOptions): Validator<Nullish<T>, Nullish<I>, import("../../core/types.js").ExecutionOptions>;
@@ -1,4 +1,4 @@
1
- import { Validator } from '../core/index.js';
1
+ import { Validator } from '../../core/index.js';
2
2
  /**
3
3
  *
4
4
  * @validator pipe
@@ -0,0 +1,7 @@
1
+ import { Nullish } from 'ts-gems';
2
+ import { ValidationOptions, Validator } from '../../core/index.js';
3
+ /**
4
+ * Makes sub-rule required
5
+ * @validator required
6
+ */
7
+ export declare function required<T, I>(nested: Validator<T, I>, options?: ValidationOptions): Validator<Nullish<T>, I, import("../../core/types.js").ExecutionOptions>;
@@ -0,0 +1,5 @@
1
+ import { Validator } from '../../core/index.js';
2
+ /**
3
+ *
4
+ */
5
+ export declare function union<T, I>(codecs: Validator<T, I>[]): Validator<T, I, import("../../core/types.js").ExecutionOptions>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lengthMax = exports.lengthMin = exports.extractLength = void 0;
4
- const index_js_1 = require("../core/index.js");
5
- const pipe_js_1 = require("./pipe.js");
6
- const range_js_1 = require("./range.js");
7
- /**
8
- * Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
9
- * @validator getLength
10
- */
11
- const extractLength = () => extractLengthRule;
12
- exports.extractLength = extractLength;
13
- const extractLengthRule = (0, index_js_1.validator)('extractLength', function (input, context, _this) {
14
- if (typeof input === 'string')
15
- return input.length;
16
- if (Array.isArray(input))
17
- return input.length;
18
- if (input instanceof ArrayBuffer)
19
- return input.byteLength;
20
- if (input && typeof input === 'object' && typeof input.length === 'number')
21
- return input.length;
22
- if (input && typeof input === 'object' && typeof input.size === 'number')
23
- return input.size;
24
- context.fail(_this, `Unable to extract length of {{label}}`, input);
25
- });
26
- /**
27
- * Checks the length is at least "minValue"
28
- * @validator lengthMin
29
- */
30
- const lengthMin = (minValue) => (0, pipe_js_1.allOf)((0, pipe_js_1.pipe)((0, exports.extractLength)(), (0, range_js_1.isGte)(minValue, {
31
- onFail: () => `The length of {{label}} must be at least ${minValue}`
32
- })));
33
- exports.lengthMin = lengthMin;
34
- /**
35
- * Checks if the length is at most "maxValue"
36
- * @validator charLengthMax
37
- */
38
- const lengthMax = (maxValue) => (0, pipe_js_1.allOf)((0, pipe_js_1.pipe)((0, exports.extractLength)(), (0, range_js_1.isLte)(maxValue, {
39
- onFail: () => `The length of {{label}} must be at most ${maxValue}`
40
- })));
41
- exports.lengthMax = lengthMax;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exists = exports.required = exports.optional = void 0;
4
- const index_js_1 = require("../core/index.js");
5
- /**
6
- * Makes sub-rule optional
7
- * @validator optional
8
- */
9
- function optional(nested, options) {
10
- return (0, index_js_1.validator)('optional', function (input, context) {
11
- if (input == null)
12
- return input;
13
- return nested(input, context);
14
- }, options);
15
- }
16
- exports.optional = optional;
17
- /**
18
- * Makes sub-rule required
19
- * @validator required
20
- */
21
- function required(nested, options) {
22
- return (0, index_js_1.validator)('required', function (input, context, _this) {
23
- if (input == null) {
24
- context.fail(_this, `{{label}} is required`, input);
25
- return;
26
- }
27
- return nested(input, context);
28
- }, options);
29
- }
30
- exports.required = required;
31
- /**
32
- * Validates if property exists
33
- * @validator exists
34
- */
35
- function exists(options) {
36
- return (0, index_js_1.validator)('exists', function (input, context, _this) {
37
- if (input !== undefined ||
38
- (context.scope &&
39
- Object.getOwnPropertyDescriptor(context.scope, input)))
40
- return input;
41
- context.fail(_this, `{{label}} must exist`, input);
42
- }, options);
43
- }
44
- exports.exists = exists;
@@ -1,377 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isHexadecimal = exports.isDecimal = exports.isAscii = exports.isAlphanumeric = exports.isAlpha = exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isHash = exports.isETHAddress = exports.isBtcAddress = exports.isVAT = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isPassportNumber = exports.isIBAN = exports.isCreditCard = exports.isBIC = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID = void 0;
27
- const validatorJS = __importStar(require("validator"));
28
- const index_js_1 = require("../core/index.js");
29
- /**
30
- * Validates if value is an "UUID".
31
- * @validator isUUID
32
- */
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))
36
- return input;
37
- context.fail(_this, `{{label}} is not a valid UUID${version ? ' v' + version : ''}`, input);
38
- }, options);
39
- }
40
- exports.isUUID = isUUID;
41
- /**
42
- * Validates if value is a valid Email
43
- * @validator isEmail
44
- */
45
- function isEmail(options) {
46
- return (0, index_js_1.validator)('isEmail', function (input, context, _this) {
47
- if (typeof input === 'string' && validatorJS.isEmail(input, options))
48
- return input;
49
- context.fail(_this, `{{label}} is not a valid a EMail`, input);
50
- }, options);
51
- }
52
- exports.isEmail = isEmail;
53
- /**
54
- * Validates if value is a valid Email
55
- * @validator isMobilePhone
56
- */
57
- function isMobilePhone(options) {
58
- return (0, index_js_1.validator)('isMobilePhone', function (input, context, _this) {
59
- if (typeof input === 'string' && validatorJS.isMobilePhone(input, options?.locale, options))
60
- return input;
61
- context.fail(_this, `{{label}} is not a valid a Mobile Phone Number`, input);
62
- }, options);
63
- }
64
- exports.isMobilePhone = isMobilePhone;
65
- /**
66
- * Validates if value is an IP
67
- * @validator isIP
68
- */
69
- function isIP(version, options) {
70
- return (0, index_js_1.validator)('isIP', function (input, context, _this) {
71
- if (input != null && typeof input === 'string' && validatorJS.isIP(input, version))
72
- return input;
73
- context.fail(_this, `{{label}} is not a valid IP${version ? ' v' + version : ''}`, input);
74
- }, options);
75
- }
76
- exports.isIP = isIP;
77
- /**
78
- * Validates if value is an IP
79
- * @validator isUUID
80
- */
81
- function isIPRange(version, options) {
82
- return (0, index_js_1.validator)('isIPRange', function (input, context, _this) {
83
- if (input != null && typeof input === 'string' && validatorJS.isIPRange(input, version))
84
- return input;
85
- context.fail(_this, `{{label}} is not a valid IP${version ? ' v' + version : ''} range`, input);
86
- }, options);
87
- }
88
- exports.isIPRange = isIPRange;
89
- /**
90
- * Validates if value is an MACAddress
91
- * @validator isMACAddress
92
- */
93
- function isMACAddress(options) {
94
- return (0, index_js_1.validator)('isMACAddress', function (input, context, _this) {
95
- if (input != null && typeof input === 'string' && validatorJS.isMACAddress(input, options))
96
- return input;
97
- context.fail(_this, `{{label}} is not a valid MAC address`, input);
98
- }, options);
99
- }
100
- exports.isMACAddress = isMACAddress;
101
- /**
102
- * Validates if value is a port number
103
- * @validator isPort
104
- */
105
- function isPort(options) {
106
- return (0, index_js_1.validator)('isPort', function (input, context, _this) {
107
- if (input != null && typeof input === 'string' && validatorJS.isPort(input))
108
- return input;
109
- context.fail(_this, `{{label}} is not a valid port number`, input);
110
- }, options);
111
- }
112
- exports.isPort = isPort;
113
- /**
114
- * Validates if value is an MACAddress
115
- * @validator isURL
116
- */
117
- function isURL(options) {
118
- return (0, index_js_1.validator)('isURL', function (input, context, _this) {
119
- if (input != null && typeof input === 'string' && validatorJS.isURL(input, options))
120
- return input;
121
- context.fail(_this, `{{label}} is not a valid URL`, input);
122
- }, options);
123
- }
124
- exports.isURL = isURL;
125
- /**
126
- * Validates if value is a "Base64" string.
127
- * @validator isBase64
128
- */
129
- function isBase64(options) {
130
- return (0, index_js_1.validator)('isBase64', function (input, context, _this) {
131
- if (typeof input === 'string' && validatorJS.isBase64(input, options))
132
- return input;
133
- context.fail(_this, `{{label}} is not a valid a Base64 string`, input);
134
- }, options);
135
- }
136
- exports.isBase64 = isBase64;
137
- /**
138
- * Validates if value is a BIC (Bank Identification Code) or SWIFT code
139
- * @validator isBIC
140
- */
141
- function isBIC(options) {
142
- return (0, index_js_1.validator)('isBIC', function (input, context, _this) {
143
- if (typeof input === 'string' && validatorJS.isBIC(input))
144
- return input;
145
- context.fail(_this, `{{label}}is not a valid a BIC (Bank Identification Code) or SWIFT code`, input);
146
- }, options);
147
- }
148
- exports.isBIC = isBIC;
149
- /**
150
- * Validates if value is a "Base64" formatted string.
151
- * @validator isCreditCard
152
- */
153
- function isCreditCard(options) {
154
- return (0, index_js_1.validator)('isCreditCard', function (input, context, _this) {
155
- if (typeof input === 'string' && validatorJS.isCreditCard(input, options))
156
- return input;
157
- context.fail(_this, `{{label}} is not a valid Credit Card number`, input);
158
- }, options);
159
- }
160
- exports.isCreditCard = isCreditCard;
161
- /**
162
- * Validates if value is an IBAN (International Bank Account Number)
163
- * @validator isEAN
164
- */
165
- function isIBAN(options) {
166
- return (0, index_js_1.validator)('isIBAN', function (input, context, _this) {
167
- if (typeof input === 'string' && validatorJS.isIBAN(input))
168
- return input;
169
- context.fail(_this, `{{label}} is not a valid IBAN (International Bank Account Number)`, input);
170
- }, options);
171
- }
172
- exports.isIBAN = isIBAN;
173
- /**
174
- * Validates if value is an passport number
175
- * @validator isPassportNumber
176
- */
177
- function isPassportNumber(countryCode, options) {
178
- return (0, index_js_1.validator)('isPassportNumber', function (input, context, _this) {
179
- if (typeof input === 'string' && validatorJS.isPassportNumber(input, countryCode))
180
- return input;
181
- context.fail(_this, `{{label}} is not a valid ${countryCode} PassportNumber)`, input);
182
- }, options);
183
- }
184
- exports.isPassportNumber = isPassportNumber;
185
- /**
186
- * Validates if value is an EAN (European Article Number)
187
- * @validator isEAN
188
- */
189
- function isEAN(options) {
190
- return (0, index_js_1.validator)('isEAN', function (input, context, _this) {
191
- if (typeof input === 'string' && validatorJS.isEAN(input))
192
- return input;
193
- context.fail(_this, `{{label}} is not a valid EAN (European Article Number)`, input);
194
- }, options);
195
- }
196
- exports.isEAN = isEAN;
197
- /**
198
- * Validates if value is an FQDN
199
- * @validator isFQDN
200
- */
201
- function isFQDN(options) {
202
- return (0, index_js_1.validator)('isFQDN', function (input, context, _this) {
203
- if (typeof input === 'string' && validatorJS.isFQDN(input, options))
204
- return input;
205
- context.fail(_this, `{{label}} is not valid FQDN`, input);
206
- }, options);
207
- }
208
- exports.isFQDN = isFQDN;
209
- /**
210
- * Validates if value is an ISSN
211
- * @validator isISSN
212
- */
213
- function isISSN(options) {
214
- return (0, index_js_1.validator)('isISSN', function (input, context, _this) {
215
- if (typeof input === 'string' && validatorJS.isISSN(input, options))
216
- return input;
217
- context.fail(_this, `{{label}} is not a valid ISSN`, input);
218
- }, options);
219
- }
220
- exports.isISSN = isISSN;
221
- /**
222
- * Validates if value is an VAT number
223
- * @validator isVAT
224
- */
225
- function isVAT(countryCode, options) {
226
- return (0, index_js_1.validator)('isVAT', function (input, context, _this) {
227
- if (typeof input === 'string' && validatorJS.isVAT(input, countryCode))
228
- return input;
229
- context.fail(_this, `{{label}} is not a valid VAT number`, input);
230
- }, options);
231
- }
232
- exports.isVAT = isVAT;
233
- /**
234
- * Validates if value is a BTC address.
235
- * @validator isBtcAddress
236
- */
237
- function isBtcAddress(options) {
238
- return (0, index_js_1.validator)('isBtcAddress', function (input, context, _this) {
239
- if (typeof input === 'string' && validatorJS.isBtcAddress(input))
240
- return input;
241
- context.fail(_this, `{{label}} is not a valid a BTC address`, input);
242
- }, options);
243
- }
244
- exports.isBtcAddress = isBtcAddress;
245
- /**
246
- * Validates if value is a ETH (Ethereum) address.
247
- * @validator isBtcAddress
248
- */
249
- function isETHAddress(options) {
250
- return (0, index_js_1.validator)('isETHAddress', function (input, context, _this) {
251
- if (typeof input === 'string' && validatorJS.isEthereumAddress(input))
252
- return input;
253
- context.fail(_this, `{{label}} is not a valid a ETH (Ethereum) address`, input);
254
- }, options);
255
- }
256
- exports.isETHAddress = isETHAddress;
257
- /**
258
- * Validates if value a hash of type algorithm
259
- * @validator isHash
260
- */
261
- function isHash(algorithm, options) {
262
- return (0, index_js_1.validator)('isHash', function (input, context, _this) {
263
- if (typeof input === 'string' && validatorJS.isHash(input, algorithm))
264
- return input;
265
- context.fail(_this, `{{label}} is not a valid ${algorithm} hash`, input);
266
- }, options);
267
- }
268
- exports.isHash = isHash;
269
- /**
270
- * Validates if value is a Hex Color
271
- * @validator isHexColor
272
- */
273
- function isHexColor(options) {
274
- return (0, index_js_1.validator)('isHexColor', function (input, context, _this) {
275
- if (typeof input === 'string' && validatorJS.isHexColor(input))
276
- return input;
277
- context.fail(_this, `{{label}} is not a valid Hex Color`, input);
278
- }, options);
279
- }
280
- exports.isHexColor = isHexColor;
281
- /**
282
- * Validates if value a valid JWT token
283
- * @validator isHash
284
- */
285
- function isJWT(options) {
286
- return (0, index_js_1.validator)('isJWT', function (input, context, _this) {
287
- if (typeof input === 'string' && validatorJS.isJWT(input))
288
- return input;
289
- context.fail(_this, `{{label}} is not a valid JWT token`, input);
290
- }, options);
291
- }
292
- exports.isJWT = isJWT;
293
- /**
294
- * Validates if value a Lowercase string
295
- * @validator isLowercase
296
- */
297
- function isLowercase(options) {
298
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
299
- if (typeof input === 'string' && validatorJS.isLowercase(input))
300
- return input;
301
- context.fail(_this, `{{label}} is not a lowercase string`, input);
302
- }, options);
303
- }
304
- exports.isLowercase = isLowercase;
305
- /**
306
- * Validates if value a Uppercase string
307
- * @validator isUppercase
308
- */
309
- function isUppercase(options) {
310
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
311
- if (typeof input === 'string' && validatorJS.isUppercase(input))
312
- return input;
313
- context.fail(_this, `{{label}} is not an uppercase string`, input);
314
- }, options);
315
- }
316
- exports.isUppercase = isUppercase;
317
- /**
318
- * Check if the string contains only letters (a-zA-Z).
319
- * @validator isAlpha
320
- */
321
- function isAlpha(options) {
322
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
323
- if (typeof input === 'string' && validatorJS.isAlpha(input))
324
- return input;
325
- context.fail(_this, `{{label}} is not an alpha string`, input);
326
- }, options);
327
- }
328
- exports.isAlpha = isAlpha;
329
- /**
330
- * Check if the string contains only letters and numbers.
331
- * @validator isAlphanumeric
332
- */
333
- function isAlphanumeric(options) {
334
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
335
- if (typeof input === 'string' && validatorJS.isAlphanumeric(input))
336
- return input;
337
- context.fail(_this, `{{label}} is not an alphanumeric string`, input);
338
- }, options);
339
- }
340
- exports.isAlphanumeric = isAlphanumeric;
341
- /**
342
- * Check if the string contains ASCII chars only.
343
- * @validator isAscii
344
- */
345
- function isAscii(options) {
346
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
347
- if (typeof input === 'string' && validatorJS.isAscii(input))
348
- return input;
349
- context.fail(_this, `{{label}} is not an ascii string`, input);
350
- }, options);
351
- }
352
- exports.isAscii = isAscii;
353
- /**
354
- * Check if the string represents a decimal number,
355
- * such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
356
- * @validator isDecimal
357
- */
358
- function isDecimal(options) {
359
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
360
- if (typeof input === 'string' && validatorJS.isDecimal(input))
361
- return input;
362
- context.fail(_this, `{{label}} is not an decimal number string`, input);
363
- }, options);
364
- }
365
- exports.isDecimal = isDecimal;
366
- /**
367
- * Check if the string is a hexadecimal number.
368
- * @validator isHexadecimal
369
- */
370
- function isHexadecimal(options) {
371
- return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
372
- if (typeof input === 'string' && validatorJS.isHexadecimal(input))
373
- return input;
374
- context.fail(_this, `{{label}} is not an hexadecimal string`, input);
375
- }, options);
376
- }
377
- exports.isHexadecimal = isHexadecimal;
@@ -1,35 +0,0 @@
1
- import { validator } from '../core/index.js';
2
- import { allOf, pipe } from './pipe.js';
3
- import { isGte, isLte } from './range.js';
4
- /**
5
- * Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
6
- * @validator getLength
7
- */
8
- export const extractLength = () => extractLengthRule;
9
- const extractLengthRule = validator('extractLength', function (input, context, _this) {
10
- if (typeof input === 'string')
11
- return input.length;
12
- if (Array.isArray(input))
13
- return input.length;
14
- if (input instanceof ArrayBuffer)
15
- return input.byteLength;
16
- if (input && typeof input === 'object' && typeof input.length === 'number')
17
- return input.length;
18
- if (input && typeof input === 'object' && typeof input.size === 'number')
19
- return input.size;
20
- context.fail(_this, `Unable to extract length of {{label}}`, input);
21
- });
22
- /**
23
- * Checks the length is at least "minValue"
24
- * @validator lengthMin
25
- */
26
- export const lengthMin = (minValue) => allOf(pipe(extractLength(), isGte(minValue, {
27
- onFail: () => `The length of {{label}} must be at least ${minValue}`
28
- })));
29
- /**
30
- * Checks if the length is at most "maxValue"
31
- * @validator charLengthMax
32
- */
33
- export const lengthMax = (maxValue) => allOf(pipe(extractLength(), isLte(maxValue, {
34
- onFail: () => `The length of {{label}} must be at most ${maxValue}`
35
- })));
@@ -1,38 +0,0 @@
1
- import { validator } from '../core/index.js';
2
- /**
3
- * Makes sub-rule optional
4
- * @validator optional
5
- */
6
- export function optional(nested, options) {
7
- return validator('optional', function (input, context) {
8
- if (input == null)
9
- return input;
10
- return nested(input, context);
11
- }, options);
12
- }
13
- /**
14
- * Makes sub-rule required
15
- * @validator required
16
- */
17
- export function required(nested, options) {
18
- return validator('required', function (input, context, _this) {
19
- if (input == null) {
20
- context.fail(_this, `{{label}} is required`, input);
21
- return;
22
- }
23
- return nested(input, context);
24
- }, options);
25
- }
26
- /**
27
- * Validates if property exists
28
- * @validator exists
29
- */
30
- export function exists(options) {
31
- return validator('exists', function (input, context, _this) {
32
- if (input !== undefined ||
33
- (context.scope &&
34
- Object.getOwnPropertyDescriptor(context.scope, input)))
35
- return input;
36
- context.fail(_this, `{{label}} must exist`, input);
37
- }, options);
38
- }