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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # v5.3.1
2
+ [2024-05-18]
3
+
4
+ ### Changes
5
+
6
+ * Reorganized many rules ([`e470fe7`](https://github.com/panates/valgen/commit/e470fe7b99dc23378253c6e549d1df7c219fbbc9))
7
+ * Updated code documentation ([`81e7ccf`](https://github.com/panates/valgen/commit/81e7ccf145075a0649cb7281062f422cd989dfa3))
8
+ * Fixed rule name ([`73d90d1`](https://github.com/panates/valgen/commit/73d90d14314d6d98d089c60134f05d651a2e4b0f))
9
+
10
+ # v5.3.0
11
+ [2024-05-06]
12
+
13
+ ### Changes
14
+
15
+ * Added validation generation option to enable coercing by default. ([`5b012ee`](https://github.com/panates/valgen/commit/5b012ee21b89e601ebb7d9f624d93042862da8ca))
16
+
1
17
  # v5.2.2
2
18
  [2024-03-29]
3
19
 
@@ -22,7 +22,7 @@ class Context {
22
22
  index: this.index,
23
23
  label: this.label,
24
24
  value,
25
- ...details
25
+ ...details,
26
26
  });
27
27
  issue.value = value;
28
28
  const onFail = this.onFail || rule[constants_js_1.kOptions].onFail;
@@ -37,14 +37,17 @@ class Context {
37
37
  else
38
38
  issue.message = String(x);
39
39
  }
40
- issue.message = ('' + issue.message)
41
- .replace(VARIABLE_REPLACE_PATTERN, (x, g) => {
40
+ issue.message = ('' + issue.message).replace(VARIABLE_REPLACE_PATTERN, (x, g) => {
42
41
  const m = OPTIONAL_VAR_PATTERN.exec(g);
43
42
  if (!m)
44
43
  return x;
45
44
  const k = m[1];
46
45
  let v = issue[k];
47
- if (!v && m[1] === 'label' && (this.location || this.property))
46
+ if (k === 'value') {
47
+ const s = String(issue.value);
48
+ return s.length < 30 ? s : s.substring(0, 30) + '..';
49
+ }
50
+ if (!v && k === 'label' && (this.location || this.property))
48
51
  v = '`' + (this.location || this.property) + '`';
49
52
  if (v != null)
50
53
  return v;
@@ -22,10 +22,10 @@ function validator(arg0, arg1, arg2) {
22
22
  throw new TypeError('You must provide a rule function argument');
23
23
  id = id || fn.name || 'unnamed-rule';
24
24
  const name = fn.name || (0, string_utils_js_1.camelCase)(id);
25
- const _rule = ({
25
+ const _rule = {
26
26
  [name](input, options) {
27
27
  const ctx = options instanceof context_js_1.Context ? options : undefined;
28
- const opts = (ctx ? undefined : options);
28
+ const opts = ctx ? undefined : options;
29
29
  const context = ctx || new context_js_1.Context(opts);
30
30
  let value;
31
31
  try {
@@ -39,8 +39,8 @@ function validator(arg0, arg1, arg2) {
39
39
  if (!ctx && context.errors.length)
40
40
  throw new validation_error_js_1.ValidationError(context.errors);
41
41
  return value;
42
- }
43
- })[name];
42
+ },
43
+ }[name];
44
44
  _rule.id = id;
45
45
  _rule[constants_js_1.kValidatorFn] = fn;
46
46
  _rule[constants_js_1.kOptions] = validatorOptions || {};
package/cjs/index.js CHANGED
@@ -26,7 +26,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.isHexadecimal = exports.isDecimal = exports.isAscii = exports.isAlphanumeric = exports.isAlpha = exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isETHAddress = exports.isBtcAddress = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isIBAN = exports.isCreditCard = exports.isBIC = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID5 = exports.isUUID4 = exports.isUUID3 = exports.isUUID2 = exports.isUUID1 = exports.isUUID = exports.isString = exports.isObjectId = exports.isObject = exports.isNumber = exports.isUndefined = exports.isDefined = exports.isNullish = exports.isNull = exports.isInteger = exports.isNotEmpty = exports.isEmpty = exports.isDateString = exports.isDate = exports.isBoolean = exports.isBigint = exports.isArray = exports.isAny = exports.vg = void 0;
29
+ exports.toArray = exports.isHex = exports.isDecimal = exports.isAscii = exports.isAlphanumeric = exports.isAlpha = exports.isUppercase = exports.isLowercase = exports.isJWT = exports.isHexColor = exports.isETHAddress = exports.isBtcAddress = exports.isISSN = exports.isFQDN = exports.isEAN = exports.isIBAN = exports.isCreditCard = exports.isSWIFT = exports.isBase64 = exports.isURL = exports.isPort = exports.isMACAddress = exports.isIPRange = exports.isIP = exports.isMobilePhone = exports.isEmail = exports.isUUID5 = exports.isUUID4 = exports.isUUID3 = exports.isUUID2 = exports.isUUID1 = exports.isUUID = exports.isString = exports.isObjectId = exports.isObject = exports.isNumber = exports.isUndefined = exports.isDefined = exports.isNullish = exports.isNull = exports.isInteger = exports.isNotEmpty = exports.isEmpty = exports.isDateString = exports.isDate = exports.isBoolean = exports.isBigint = exports.isArray = exports.isAny = exports.vg = void 0;
30
+ exports.toString = exports.toNumber = exports.toInteger = exports.toDateString = exports.toDate = exports.toBoolean = void 0;
30
31
  const vg = __importStar(require("./rules/index.js"));
31
32
  exports.vg = vg;
32
33
  __exportStar(require("./constants.js"), exports);
@@ -93,8 +94,8 @@ const isURL = vg.isURL();
93
94
  exports.isURL = isURL;
94
95
  const isBase64 = vg.isBase64();
95
96
  exports.isBase64 = isBase64;
96
- const isBIC = vg.isBIC();
97
- exports.isBIC = isBIC;
97
+ const isSWIFT = vg.isSWIFT();
98
+ exports.isSWIFT = isSWIFT;
98
99
  const isCreditCard = vg.isCreditCard();
99
100
  exports.isCreditCard = isCreditCard;
100
101
  const isIBAN = vg.isIBAN();
@@ -125,5 +126,19 @@ const isAscii = vg.isAscii();
125
126
  exports.isAscii = isAscii;
126
127
  const isDecimal = vg.isDecimal();
127
128
  exports.isDecimal = isDecimal;
128
- const isHexadecimal = vg.isHexadecimal();
129
- exports.isHexadecimal = isHexadecimal;
129
+ const isHex = vg.isHex();
130
+ exports.isHex = isHex;
131
+ const toArray = vg.isArray(isAny, { coerce: true });
132
+ exports.toArray = toArray;
133
+ const toBoolean = vg.isBoolean({ coerce: true });
134
+ exports.toBoolean = toBoolean;
135
+ const toDate = vg.isDate({ coerce: true });
136
+ exports.toDate = toDate;
137
+ const toDateString = vg.isDateString({ coerce: true });
138
+ exports.toDateString = toDateString;
139
+ const toInteger = vg.isInteger({ coerce: true });
140
+ exports.toInteger = toInteger;
141
+ const toNumber = vg.isNumber({ coerce: true });
142
+ exports.toNumber = toNumber;
143
+ const toString = vg.isString({ coerce: true });
144
+ exports.toString = toString;
@@ -0,0 +1,52 @@
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.isAlphanumeric = exports.isAlpha = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Check if the string contains only letters (a-zA-Z).
31
+ * @validator isAlpha
32
+ */
33
+ function isAlpha(options) {
34
+ return (0, index_js_1.validator)('isLowercase', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isAlpha(input))
36
+ return input;
37
+ context.fail(_this, `"{{value}}" is not an alpha string`, input);
38
+ }, options);
39
+ }
40
+ exports.isAlpha = isAlpha;
41
+ /**
42
+ * Check if the string contains only letters and numbers.
43
+ * @validator isAlphanumeric
44
+ */
45
+ function isAlphanumeric(options) {
46
+ return (0, index_js_1.validator)('isAlphanumeric', function (input, context, _this) {
47
+ if (typeof input === 'string' && validatorJS.isAlphanumeric(input))
48
+ return input;
49
+ context.fail(_this, `"{{value}}" is not an alphanumeric string`, input);
50
+ }, options);
51
+ }
52
+ exports.isAlphanumeric = isAlphanumeric;
@@ -0,0 +1,40 @@
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.isAscii = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Check if the string contains ASCII chars only.
31
+ * @validator isAscii
32
+ */
33
+ function isAscii(options) {
34
+ return (0, index_js_1.validator)('isAscii', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isAscii(input))
36
+ return input;
37
+ context.fail(_this, `Value is not an ascii string`, input);
38
+ }, options);
39
+ }
40
+ exports.isAscii = isAscii;
@@ -0,0 +1,40 @@
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.isBase64 = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value is a "Base64" string.
31
+ * @validator isBase64
32
+ */
33
+ function isBase64(options) {
34
+ return (0, index_js_1.validator)('isBase64', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isBase64(input, options))
36
+ return input;
37
+ context.fail(_this, `"{{value}}" is not a valid a Base64 string`, input);
38
+ }, options);
39
+ }
40
+ exports.isBase64 = isBase64;
@@ -0,0 +1,40 @@
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.isBtcAddress = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value is a BTC address.
31
+ * @validator isBtcAddress
32
+ */
33
+ function isBtcAddress(options) {
34
+ return (0, index_js_1.validator)('isBtcAddress', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isBtcAddress(input))
36
+ return input;
37
+ context.fail(_this, `Value is not a valid a BTC address`, input);
38
+ }, options);
39
+ }
40
+ exports.isBtcAddress = isBtcAddress;
@@ -0,0 +1,40 @@
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.isCreditCard = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value is a credit card number
31
+ * @validator isCreditCard
32
+ */
33
+ function isCreditCard(options) {
34
+ return (0, index_js_1.validator)('isCreditCard', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isCreditCard(input, options))
36
+ return input;
37
+ context.fail(_this, `"{{value}}" is not a valid Credit Card number`, input);
38
+ }, options);
39
+ }
40
+ exports.isCreditCard = isCreditCard;
@@ -0,0 +1,41 @@
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.isDecimal = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Check if the string represents a decimal number,
31
+ * such as `0.1`, `.3`, `1.1`, `1.00003`, `4.0` etc.
32
+ * @validator isDecimal
33
+ */
34
+ function isDecimal(options) {
35
+ return (0, index_js_1.validator)('isDecimal', function (input, context, _this) {
36
+ if (typeof input === 'string' && validatorJS.isDecimal(input))
37
+ return input;
38
+ context.fail(_this, `"{{value}}" is not an decimal number string`, input);
39
+ }, options);
40
+ }
41
+ exports.isDecimal = isDecimal;
@@ -0,0 +1,40 @@
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.isEAN = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value is an EAN (European Article Number)
31
+ * @validator isEAN
32
+ */
33
+ function isEAN(options) {
34
+ return (0, index_js_1.validator)('isEAN', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isEAN(input))
36
+ return input;
37
+ context.fail(_this, `"{{value}}" is not a valid EAN (European Article Number)`, input);
38
+ }, options);
39
+ }
40
+ exports.isEAN = isEAN;
@@ -0,0 +1,97 @@
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.isEmail = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value is a valid Email
31
+ * @validator isEmail
32
+ */
33
+ function isEmail(options) {
34
+ const emailOptions = {
35
+ // eslint-disable-next-line camelcase
36
+ allow_display_name: true,
37
+ // eslint-disable-next-line camelcase
38
+ allow_utf8_local_part: options?.utf8LocalPart,
39
+ // eslint-disable-next-line camelcase
40
+ ignore_max_length: true,
41
+ // eslint-disable-next-line camelcase
42
+ allow_ip_domain: options?.allowIpDomain,
43
+ };
44
+ return (0, index_js_1.validator)('isEmail', function (input, context, _this) {
45
+ if (typeof input === 'string' && validatorJS.isEmail(input, emailOptions)) {
46
+ if (options?.requireDisplayName) {
47
+ if (!validatorJS.isEmail(input, {
48
+ ...emailOptions,
49
+ // eslint-disable-next-line camelcase
50
+ require_display_name: true,
51
+ })) {
52
+ context.fail(_this, `Display name for the email is required. Etc. ( Name <me@tempuri.org> ) `, input);
53
+ return;
54
+ }
55
+ }
56
+ else if (!options?.allowDisplayName &&
57
+ !validatorJS.isEmail(input, {
58
+ ...emailOptions,
59
+ // eslint-disable-next-line camelcase
60
+ allow_display_name: false,
61
+ })) {
62
+ context.fail(_this, `Display name in email is not allowed`, input);
63
+ return;
64
+ }
65
+ if (options?.hostBlacklist &&
66
+ !validatorJS.isEmail(input, {
67
+ ...emailOptions,
68
+ // eslint-disable-next-line camelcase
69
+ host_blacklist: options.hostBlacklist,
70
+ })) {
71
+ context.fail(_this, `Email "{{value}}" is in black-list`, input);
72
+ return;
73
+ }
74
+ if (options?.hostWhitelist &&
75
+ !validatorJS.isEmail(input, {
76
+ ...emailOptions,
77
+ // eslint-disable-next-line camelcase
78
+ host_whitelist: options.hostWhitelist,
79
+ })) {
80
+ context.fail(_this, `Email "{{value}}" is in not white-list`, input);
81
+ return;
82
+ }
83
+ if (options?.blacklistedChars &&
84
+ !validatorJS.isEmail(input, {
85
+ ...emailOptions,
86
+ // eslint-disable-next-line camelcase
87
+ blacklisted_chars: options.blacklistedChars,
88
+ })) {
89
+ context.fail(_this, `Black listed characters (${options.blacklistedChars}) found in name part`, input);
90
+ return;
91
+ }
92
+ return input;
93
+ }
94
+ context.fail(_this, `"{{value}}" does not match required e-mail format`, input);
95
+ }, options);
96
+ }
97
+ exports.isEmail = isEmail;
@@ -0,0 +1,40 @@
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.isETHAddress = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value is a ETH (Ethereum) address.
31
+ * @validator isETHAddress
32
+ */
33
+ function isETHAddress(options) {
34
+ return (0, index_js_1.validator)('isETHAddress', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isEthereumAddress(input))
36
+ return input;
37
+ context.fail(_this, `Value is not a valid a ETH (Ethereum) address`, input);
38
+ }, options);
39
+ }
40
+ exports.isETHAddress = isETHAddress;
@@ -0,0 +1,44 @@
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.isFQDN = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value is an FQDN
31
+ * @validator isFQDN
32
+ */
33
+ function isFQDN(options) {
34
+ const opts = {
35
+ // eslint-disable-next-line camelcase
36
+ allow_wildcard: options?.allowWildcard,
37
+ };
38
+ return (0, index_js_1.validator)('isFQDN', function (input, context, _this) {
39
+ if (typeof input === 'string' && validatorJS.isFQDN(input, opts))
40
+ return input;
41
+ context.fail(_this, `"{{value}}" is not valid FQDN`, input);
42
+ }, options);
43
+ }
44
+ exports.isFQDN = isFQDN;
@@ -0,0 +1,40 @@
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.isHash = void 0;
27
+ const validatorJS = __importStar(require("validator"));
28
+ const index_js_1 = require("../../core/index.js");
29
+ /**
30
+ * Validates if value a hash of type algorithm
31
+ * @validator isHash
32
+ */
33
+ function isHash(algorithm, options) {
34
+ return (0, index_js_1.validator)('isHash', function (input, context, _this) {
35
+ if (typeof input === 'string' && validatorJS.isHash(input, algorithm))
36
+ return input;
37
+ context.fail(_this, `Value is not a valid ${algorithm} hash`, input);
38
+ }, options);
39
+ }
40
+ exports.isHash = isHash;