valgen 5.18.2 → 5.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/{types/constants.d.ts → constants.d.ts} +1 -0
  2. package/{esm/constants.js → constants.js} +1 -0
  3. package/{esm/core → core}/context.js +12 -2
  4. package/{esm/core → core}/validation-error.js +1 -1
  5. package/package.json +9 -25
  6. package/{types/rules → rules}/type-rules/is-date.d.ts +1 -0
  7. package/{esm/rules → rules}/type-rules/is-date.js +21 -10
  8. package/CHANGELOG.md +0 -384
  9. package/cjs/constants.js +0 -7
  10. package/cjs/core/constants.js +0 -5
  11. package/cjs/core/context.js +0 -74
  12. package/cjs/core/index.js +0 -9
  13. package/cjs/core/types.js +0 -2
  14. package/cjs/core/utilities.js +0 -30
  15. package/cjs/core/validation-error.js +0 -12
  16. package/cjs/core/validator.js +0 -71
  17. package/cjs/factories.js +0 -4
  18. package/cjs/helpers/object.utils.js +0 -18
  19. package/cjs/helpers/omit-undefined.js +0 -14
  20. package/cjs/helpers/string.utils.js +0 -6
  21. package/cjs/index.js +0 -129
  22. package/cjs/package.json +0 -3
  23. package/cjs/rules/format-rules/is-alpha.js +0 -30
  24. package/cjs/rules/format-rules/is-ascii.js +0 -17
  25. package/cjs/rules/format-rules/is-base64.js +0 -18
  26. package/cjs/rules/format-rules/is-btc-address.js +0 -18
  27. package/cjs/rules/format-rules/is-credit-card.js +0 -19
  28. package/cjs/rules/format-rules/is-decimal.js +0 -19
  29. package/cjs/rules/format-rules/is-ean.js +0 -17
  30. package/cjs/rules/format-rules/is-email.js +0 -66
  31. package/cjs/rules/format-rules/is-eth-address.js +0 -18
  32. package/cjs/rules/format-rules/is-fqdn.js +0 -21
  33. package/cjs/rules/format-rules/is-hash.js +0 -18
  34. package/cjs/rules/format-rules/is-hex-color.js +0 -18
  35. package/cjs/rules/format-rules/is-hex.js +0 -18
  36. package/cjs/rules/format-rules/is-iban.js +0 -29
  37. package/cjs/rules/format-rules/is-ip.js +0 -35
  38. package/cjs/rules/format-rules/is-issn.js +0 -21
  39. package/cjs/rules/format-rules/is-jwt.js +0 -17
  40. package/cjs/rules/format-rules/is-lowercase.js +0 -31
  41. package/cjs/rules/format-rules/is-mac-address.js +0 -24
  42. package/cjs/rules/format-rules/is-mobile-phone.js +0 -22
  43. package/cjs/rules/format-rules/is-object-id.js +0 -28
  44. package/cjs/rules/format-rules/is-passport-number.js +0 -19
  45. package/cjs/rules/format-rules/is-port.js +0 -22
  46. package/cjs/rules/format-rules/is-time.js +0 -51
  47. package/cjs/rules/format-rules/is-url.js +0 -20
  48. package/cjs/rules/format-rules/is-uuid.js +0 -20
  49. package/cjs/rules/format-rules/is-vat-number.js +0 -18
  50. package/cjs/rules/format-rules/matches.js +0 -22
  51. package/cjs/rules/index.js +0 -56
  52. package/cjs/rules/logical-rules/is-defined.js +0 -15
  53. package/cjs/rules/logical-rules/is-empty.js +0 -110
  54. package/cjs/rules/logical-rules/is-equal.js +0 -32
  55. package/cjs/rules/logical-rules/range.js +0 -175
  56. package/cjs/rules/type-rules/is-any.js +0 -10
  57. package/cjs/rules/type-rules/is-array.js +0 -45
  58. package/cjs/rules/type-rules/is-bigint.js +0 -21
  59. package/cjs/rules/type-rules/is-boolean.js +0 -31
  60. package/cjs/rules/type-rules/is-date.js +0 -180
  61. package/cjs/rules/type-rules/is-enum.js +0 -31
  62. package/cjs/rules/type-rules/is-integer.js +0 -30
  63. package/cjs/rules/type-rules/is-null.js +0 -54
  64. package/cjs/rules/type-rules/is-number.js +0 -27
  65. package/cjs/rules/type-rules/is-object.js +0 -113
  66. package/cjs/rules/type-rules/is-record.js +0 -42
  67. package/cjs/rules/type-rules/is-string.js +0 -81
  68. package/cjs/rules/type-rules/is-tuple.js +0 -38
  69. package/cjs/rules/type-rules/is-undefined.js +0 -17
  70. package/cjs/rules/utility-rules/all-of.js +0 -20
  71. package/cjs/rules/utility-rules/exists.js +0 -18
  72. package/cjs/rules/utility-rules/get-length.js +0 -29
  73. package/cjs/rules/utility-rules/one-of.js +0 -59
  74. package/cjs/rules/utility-rules/optional.js +0 -15
  75. package/cjs/rules/utility-rules/pipe.js +0 -28
  76. package/cjs/rules/utility-rules/required.js +0 -19
  77. package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
  78. package/esm/package.json +0 -3
  79. package/esm/tsconfig-build-esm.tsbuildinfo +0 -1
  80. package/types/index.d.cts +0 -65
  81. /package/{types/core → core}/constants.d.ts +0 -0
  82. /package/{esm/core → core}/constants.js +0 -0
  83. /package/{types/core → core}/context.d.ts +0 -0
  84. /package/{types/core → core}/index.d.ts +0 -0
  85. /package/{esm/core → core}/index.js +0 -0
  86. /package/{types/core → core}/types.d.ts +0 -0
  87. /package/{esm/core → core}/types.js +0 -0
  88. /package/{types/core → core}/utilities.d.ts +0 -0
  89. /package/{esm/core → core}/utilities.js +0 -0
  90. /package/{types/core → core}/validation-error.d.ts +0 -0
  91. /package/{types/core → core}/validator.d.ts +0 -0
  92. /package/{esm/core → core}/validator.js +0 -0
  93. /package/{types/factories.d.ts → factories.d.ts} +0 -0
  94. /package/{esm/factories.js → factories.js} +0 -0
  95. /package/{types/helpers → helpers}/object.utils.d.ts +0 -0
  96. /package/{esm/helpers → helpers}/object.utils.js +0 -0
  97. /package/{types/helpers → helpers}/omit-undefined.d.ts +0 -0
  98. /package/{esm/helpers → helpers}/omit-undefined.js +0 -0
  99. /package/{types/helpers → helpers}/string.utils.d.ts +0 -0
  100. /package/{esm/helpers → helpers}/string.utils.js +0 -0
  101. /package/{types/index.d.ts → index.d.ts} +0 -0
  102. /package/{esm/index.js → index.js} +0 -0
  103. /package/{types/rules → rules}/format-rules/is-alpha.d.ts +0 -0
  104. /package/{esm/rules → rules}/format-rules/is-alpha.js +0 -0
  105. /package/{types/rules → rules}/format-rules/is-ascii.d.ts +0 -0
  106. /package/{esm/rules → rules}/format-rules/is-ascii.js +0 -0
  107. /package/{types/rules → rules}/format-rules/is-base64.d.ts +0 -0
  108. /package/{esm/rules → rules}/format-rules/is-base64.js +0 -0
  109. /package/{types/rules → rules}/format-rules/is-btc-address.d.ts +0 -0
  110. /package/{esm/rules → rules}/format-rules/is-btc-address.js +0 -0
  111. /package/{types/rules → rules}/format-rules/is-credit-card.d.ts +0 -0
  112. /package/{esm/rules → rules}/format-rules/is-credit-card.js +0 -0
  113. /package/{types/rules → rules}/format-rules/is-decimal.d.ts +0 -0
  114. /package/{esm/rules → rules}/format-rules/is-decimal.js +0 -0
  115. /package/{types/rules → rules}/format-rules/is-ean.d.ts +0 -0
  116. /package/{esm/rules → rules}/format-rules/is-ean.js +0 -0
  117. /package/{types/rules → rules}/format-rules/is-email.d.ts +0 -0
  118. /package/{esm/rules → rules}/format-rules/is-email.js +0 -0
  119. /package/{types/rules → rules}/format-rules/is-eth-address.d.ts +0 -0
  120. /package/{esm/rules → rules}/format-rules/is-eth-address.js +0 -0
  121. /package/{types/rules → rules}/format-rules/is-fqdn.d.ts +0 -0
  122. /package/{esm/rules → rules}/format-rules/is-fqdn.js +0 -0
  123. /package/{types/rules → rules}/format-rules/is-hash.d.ts +0 -0
  124. /package/{esm/rules → rules}/format-rules/is-hash.js +0 -0
  125. /package/{types/rules → rules}/format-rules/is-hex-color.d.ts +0 -0
  126. /package/{esm/rules → rules}/format-rules/is-hex-color.js +0 -0
  127. /package/{types/rules → rules}/format-rules/is-hex.d.ts +0 -0
  128. /package/{esm/rules → rules}/format-rules/is-hex.js +0 -0
  129. /package/{types/rules → rules}/format-rules/is-iban.d.ts +0 -0
  130. /package/{esm/rules → rules}/format-rules/is-iban.js +0 -0
  131. /package/{types/rules → rules}/format-rules/is-ip.d.ts +0 -0
  132. /package/{esm/rules → rules}/format-rules/is-ip.js +0 -0
  133. /package/{types/rules → rules}/format-rules/is-issn.d.ts +0 -0
  134. /package/{esm/rules → rules}/format-rules/is-issn.js +0 -0
  135. /package/{types/rules → rules}/format-rules/is-jwt.d.ts +0 -0
  136. /package/{esm/rules → rules}/format-rules/is-jwt.js +0 -0
  137. /package/{types/rules → rules}/format-rules/is-lowercase.d.ts +0 -0
  138. /package/{esm/rules → rules}/format-rules/is-lowercase.js +0 -0
  139. /package/{types/rules → rules}/format-rules/is-mac-address.d.ts +0 -0
  140. /package/{esm/rules → rules}/format-rules/is-mac-address.js +0 -0
  141. /package/{types/rules → rules}/format-rules/is-mobile-phone.d.ts +0 -0
  142. /package/{esm/rules → rules}/format-rules/is-mobile-phone.js +0 -0
  143. /package/{types/rules → rules}/format-rules/is-object-id.d.ts +0 -0
  144. /package/{esm/rules → rules}/format-rules/is-object-id.js +0 -0
  145. /package/{types/rules → rules}/format-rules/is-passport-number.d.ts +0 -0
  146. /package/{esm/rules → rules}/format-rules/is-passport-number.js +0 -0
  147. /package/{types/rules → rules}/format-rules/is-port.d.ts +0 -0
  148. /package/{esm/rules → rules}/format-rules/is-port.js +0 -0
  149. /package/{types/rules → rules}/format-rules/is-time.d.ts +0 -0
  150. /package/{esm/rules → rules}/format-rules/is-time.js +0 -0
  151. /package/{types/rules → rules}/format-rules/is-url.d.ts +0 -0
  152. /package/{esm/rules → rules}/format-rules/is-url.js +0 -0
  153. /package/{types/rules → rules}/format-rules/is-uuid.d.ts +0 -0
  154. /package/{esm/rules → rules}/format-rules/is-uuid.js +0 -0
  155. /package/{types/rules → rules}/format-rules/is-vat-number.d.ts +0 -0
  156. /package/{esm/rules → rules}/format-rules/is-vat-number.js +0 -0
  157. /package/{types/rules → rules}/format-rules/matches.d.ts +0 -0
  158. /package/{esm/rules → rules}/format-rules/matches.js +0 -0
  159. /package/{types/rules → rules}/index.d.ts +0 -0
  160. /package/{esm/rules → rules}/index.js +0 -0
  161. /package/{types/rules → rules}/logical-rules/is-defined.d.ts +0 -0
  162. /package/{esm/rules → rules}/logical-rules/is-defined.js +0 -0
  163. /package/{types/rules → rules}/logical-rules/is-empty.d.ts +0 -0
  164. /package/{esm/rules → rules}/logical-rules/is-empty.js +0 -0
  165. /package/{types/rules → rules}/logical-rules/is-equal.d.ts +0 -0
  166. /package/{esm/rules → rules}/logical-rules/is-equal.js +0 -0
  167. /package/{types/rules → rules}/logical-rules/range.d.ts +0 -0
  168. /package/{esm/rules → rules}/logical-rules/range.js +0 -0
  169. /package/{types/rules → rules}/type-rules/is-any.d.ts +0 -0
  170. /package/{esm/rules → rules}/type-rules/is-any.js +0 -0
  171. /package/{types/rules → rules}/type-rules/is-array.d.ts +0 -0
  172. /package/{esm/rules → rules}/type-rules/is-array.js +0 -0
  173. /package/{types/rules → rules}/type-rules/is-bigint.d.ts +0 -0
  174. /package/{esm/rules → rules}/type-rules/is-bigint.js +0 -0
  175. /package/{types/rules → rules}/type-rules/is-boolean.d.ts +0 -0
  176. /package/{esm/rules → rules}/type-rules/is-boolean.js +0 -0
  177. /package/{types/rules → rules}/type-rules/is-enum.d.ts +0 -0
  178. /package/{esm/rules → rules}/type-rules/is-enum.js +0 -0
  179. /package/{types/rules → rules}/type-rules/is-integer.d.ts +0 -0
  180. /package/{esm/rules → rules}/type-rules/is-integer.js +0 -0
  181. /package/{types/rules → rules}/type-rules/is-null.d.ts +0 -0
  182. /package/{esm/rules → rules}/type-rules/is-null.js +0 -0
  183. /package/{types/rules → rules}/type-rules/is-number.d.ts +0 -0
  184. /package/{esm/rules → rules}/type-rules/is-number.js +0 -0
  185. /package/{types/rules → rules}/type-rules/is-object.d.ts +0 -0
  186. /package/{esm/rules → rules}/type-rules/is-object.js +0 -0
  187. /package/{types/rules → rules}/type-rules/is-record.d.ts +0 -0
  188. /package/{esm/rules → rules}/type-rules/is-record.js +0 -0
  189. /package/{types/rules → rules}/type-rules/is-string.d.ts +0 -0
  190. /package/{esm/rules → rules}/type-rules/is-string.js +0 -0
  191. /package/{types/rules → rules}/type-rules/is-tuple.d.ts +0 -0
  192. /package/{esm/rules → rules}/type-rules/is-tuple.js +0 -0
  193. /package/{types/rules → rules}/type-rules/is-undefined.d.ts +0 -0
  194. /package/{esm/rules → rules}/type-rules/is-undefined.js +0 -0
  195. /package/{types/rules → rules}/utility-rules/all-of.d.ts +0 -0
  196. /package/{esm/rules → rules}/utility-rules/all-of.js +0 -0
  197. /package/{types/rules → rules}/utility-rules/exists.d.ts +0 -0
  198. /package/{esm/rules → rules}/utility-rules/exists.js +0 -0
  199. /package/{types/rules → rules}/utility-rules/get-length.d.ts +0 -0
  200. /package/{esm/rules → rules}/utility-rules/get-length.js +0 -0
  201. /package/{types/rules → rules}/utility-rules/one-of.d.ts +0 -0
  202. /package/{esm/rules → rules}/utility-rules/one-of.js +0 -0
  203. /package/{types/rules → rules}/utility-rules/optional.d.ts +0 -0
  204. /package/{esm/rules → rules}/utility-rules/optional.js +0 -0
  205. /package/{types/rules → rules}/utility-rules/pipe.d.ts +0 -0
  206. /package/{esm/rules → rules}/utility-rules/pipe.js +0 -0
  207. /package/{types/rules → rules}/utility-rules/required.d.ts +0 -0
  208. /package/{esm/rules → rules}/utility-rules/required.js +0 -0
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isObject = isObject;
4
- const constants_js_1 = require("../../constants.js");
5
- const index_js_1 = require("../../core/index.js");
6
- /**
7
- * Validates object according to schema
8
- * Converts properties according to schema rules if coerce option is set to 'true'.
9
- * @validator isObject
10
- */
11
- function isObject(schema, options) {
12
- const ctor = options?.ctor;
13
- const ctorName = options?.name || ctor?.name;
14
- const additionalFields = options?.additionalFields ?? !schema;
15
- const caseInSensitive = !!options?.caseInSensitive;
16
- const detectCircular = !!options?.detectCircular;
17
- const propertyRules = {};
18
- const propertyOptions = {};
19
- schema = schema || {};
20
- const schemaKeys = Object.keys(schema);
21
- for (const k of schemaKeys) {
22
- const n = schema[k];
23
- const key = caseInSensitive ? k.toLowerCase() : k;
24
- if (Array.isArray(n)) {
25
- if (!(0, index_js_1.isValidator)(n[0])) {
26
- throw new TypeError(`Invalid tuple definition in validation schema (${k})`);
27
- }
28
- propertyRules[key] = n[0];
29
- propertyOptions[key] = { as: k, ...n[1] };
30
- }
31
- else if ((0, index_js_1.isValidator)(n)) {
32
- propertyRules[key] = n;
33
- propertyOptions[key] = { as: k };
34
- }
35
- else {
36
- throw new TypeError(`Invalid definition in validation schema (${k})`);
37
- }
38
- }
39
- const _rule = (0, index_js_1.validator)('isObject', (input, context, _this) => {
40
- let output = input;
41
- if (ctor && ctor[constants_js_1.preValidation]) {
42
- output = ctor[constants_js_1.preValidation](output, context, _this);
43
- }
44
- const coerce = options?.coerce ?? context.coerce;
45
- if (typeof output === 'string' && coerce)
46
- output = JSON.parse(output);
47
- if (!(output && typeof output === 'object')) {
48
- context.fail(_this, `Value must be an object`, input);
49
- return;
50
- }
51
- const keys = Array.from(new Set([...Object.keys(output), ...schemaKeys]));
52
- const l = keys.length;
53
- let i = 0;
54
- let inputKey;
55
- let schemaKey;
56
- let v;
57
- let _propRule;
58
- const out = {};
59
- if (ctor)
60
- Object.setPrototypeOf(out, ctor.prototype);
61
- if (detectCircular) {
62
- context.circMap = context.circMap || new Map();
63
- if (context.circMap.has(output)) {
64
- return context.circMap.get(output);
65
- }
66
- context.circMap.set(output, out);
67
- }
68
- if (context.root == null)
69
- context.root = context.root || ctorName || '';
70
- const location = context.location || '';
71
- const processedSchemaKeys = {};
72
- // Iterate object keys and perform rules
73
- for (i = 0; i < l; i++) {
74
- inputKey = keys[i];
75
- schemaKey = caseInSensitive ? inputKey.toLowerCase() : inputKey;
76
- v = output[inputKey];
77
- _propRule =
78
- propertyRules[schemaKey] ||
79
- ((0, index_js_1.isValidator)(additionalFields) ? additionalFields : undefined);
80
- if (_propRule) {
81
- if (processedSchemaKeys[schemaKey])
82
- continue;
83
- processedSchemaKeys[schemaKey] = true;
84
- const subCtx = context.extend();
85
- subCtx.scope = output;
86
- subCtx.context = ctorName;
87
- subCtx.location = location + (location ? '.' : '') + schemaKey;
88
- subCtx.property = schemaKey;
89
- if (propertyOptions[schemaKey]?.label) {
90
- subCtx.label = propertyOptions[schemaKey]?.label;
91
- }
92
- v = _propRule(v, subCtx);
93
- }
94
- else if (v !== undefined) {
95
- if (!additionalFields)
96
- continue;
97
- if (additionalFields === 'error') {
98
- context.fail(_propRule, `${ctorName || 'Object'} has no field '${inputKey}' and does not accept additional fields`, v);
99
- }
100
- }
101
- if (v !== undefined) {
102
- out[propertyOptions[schemaKey]?.as || schemaKey] = v;
103
- }
104
- }
105
- if (ctor && ctor[constants_js_1.postValidation]) {
106
- ctor[constants_js_1.postValidation](out, context, _this);
107
- return out;
108
- }
109
- return out;
110
- }, options);
111
- _rule.schema = schema;
112
- return _rule;
113
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRecord = isRecord;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- * Validates record object according to given "key" and "value" rules
7
- * Converts properties according to rules if coerce option is set to 'true'.
8
- * @validator isRecord
9
- */
10
- function isRecord(keyRule, valueRule, options) {
11
- return (0, index_js_1.validator)('isRecord', (input, context, _this) => {
12
- if (!(input && typeof input === 'object')) {
13
- context.fail(_this, `Value must be an object`, input);
14
- return;
15
- }
16
- const keyContext = context.extend();
17
- const valueContext = context.extend();
18
- const location = context.location || '';
19
- const keys = Object.keys(input);
20
- const l = keys.length;
21
- let i;
22
- let k;
23
- let v;
24
- const out = {};
25
- for (i = 0; i < l; i++) {
26
- k = keys[i];
27
- v = input[k];
28
- // Validate key
29
- k = keyRule(k, {
30
- onFail(issue) {
31
- return `${k} is not a valid key. ` + issue.message;
32
- },
33
- }, keyContext);
34
- // Validate value
35
- valueContext.property = k;
36
- valueContext.location = location + (location ? '.' : '') + k;
37
- v = valueRule(v, valueContext);
38
- out[k] = v;
39
- }
40
- return context.errors.length ? undefined : out;
41
- }, options);
42
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trimStart = exports.trimEnd = void 0;
4
- exports.isString = isString;
5
- exports.stringReplace = stringReplace;
6
- exports.stringSplit = stringSplit;
7
- exports.trim = trim;
8
- const index_js_1 = require("../../core/index.js");
9
- /**
10
- * Validates if value is "string".
11
- * Converts input value to string if coerce option is set to 'true'.
12
- * @validator isString
13
- */
14
- function isString(options) {
15
- return (0, index_js_1.validator)('isString', (input, context, _this) => {
16
- const coerce = options?.coerce ?? context.coerce;
17
- let output = input;
18
- if (output != null && typeof output !== 'string' && coerce) {
19
- if (typeof output === 'object') {
20
- if (typeof output.toJSON === 'function')
21
- output = output.toJSON();
22
- else
23
- output = JSON.stringify(output);
24
- }
25
- else
26
- output = String(output);
27
- }
28
- if (typeof output === 'string')
29
- return output;
30
- context.fail(_this, `Value must be a string`, input);
31
- }, options);
32
- }
33
- function stringReplace(searchValue, replacer) {
34
- return (0, index_js_1.validator)('stringReplace', (input) => {
35
- if (input == null)
36
- return input;
37
- return String(input).replace(searchValue, replacer);
38
- });
39
- }
40
- function stringSplit(splitter, limit) {
41
- return (0, index_js_1.validator)('stringSplit', (input) => {
42
- if (input == null)
43
- return input;
44
- return String(input).split(splitter, limit);
45
- });
46
- }
47
- /**
48
- * Removes whitespace from both ends of a string
49
- * @validator trim
50
- */
51
- function trim() {
52
- return (0, index_js_1.validator)('trim', (input) => {
53
- if (input == null)
54
- return input;
55
- return String(input).trim();
56
- });
57
- }
58
- // *************************************************************
59
- /**
60
- * Removes whitespace from the end of a string
61
- * @validator trimEnd
62
- */
63
- const trimEnd = () => trimEndRule;
64
- exports.trimEnd = trimEnd;
65
- const trimEndRule = (0, index_js_1.validator)('trimEnd', (input) => {
66
- if (input == null)
67
- return input;
68
- return String(input).trimEnd();
69
- });
70
- // *************************************************************
71
- /**
72
- * Removes whitespace from the beginning of a string
73
- * @validator trimStart
74
- */
75
- const trimStart = () => trimStartRule;
76
- exports.trimStart = trimStart;
77
- const trimStartRule = (0, index_js_1.validator)('trimStart', (input) => {
78
- if (input == null)
79
- return input;
80
- return String(input).trimStart();
81
- });
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isTuple = isTuple;
4
- const index_js_1 = require("../../core/index.js");
5
- function isTuple(items, options) {
6
- return (0, index_js_1.validator)('isTuple', (input, context, _this) => {
7
- const coerce = options?.coerce ?? context.coerce;
8
- let output = input;
9
- if (output != null && coerce && !Array.isArray(output))
10
- output = [output];
11
- if (!Array.isArray(input)) {
12
- context.fail(_this, `Value must be a tuple`, input);
13
- return;
14
- }
15
- const location = context.location || '';
16
- let itemRule;
17
- let i;
18
- let v;
19
- const l = output.length;
20
- const out = [];
21
- const nl = items.length;
22
- const itemContext = context.extend();
23
- for (i = 0; i < l && i < nl; i++) {
24
- itemRule = items[i];
25
- itemContext.scope = output;
26
- itemContext.label = context.label
27
- ? context.label + `[${i}]`
28
- : undefined;
29
- itemContext.index = i;
30
- itemContext.location = location + '[' + i + ']';
31
- itemContext.label =
32
- (itemContext.label || itemContext.property || 'Value at ') + `[${i}]`;
33
- v = itemRule(output[i], itemContext);
34
- out.push(v);
35
- }
36
- return context.errors.length ? undefined : out;
37
- }, options);
38
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUndefined = isUndefined;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- * Validates if value is "undefined"
7
- * @validator isUndefined
8
- */
9
- function isUndefined(options) {
10
- return (0, index_js_1.validator)('isUndefined', (input, context, _this) => {
11
- if (options?.coerce ?? context.coerce)
12
- return undefined;
13
- if (input === undefined)
14
- return;
15
- context.fail(_this, `Value must be undefined`, input);
16
- }, options);
17
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allOf = allOf;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- * Test given value against to all codecs and returns original input
7
- * @validator allOf
8
- */
9
- function allOf(rules) {
10
- return (0, index_js_1.validator)('allOf', (input, context) => {
11
- let i;
12
- let c;
13
- const l = rules.length;
14
- for (i = 0; i < l; i++) {
15
- c = rules[i];
16
- c(input, context);
17
- }
18
- return input;
19
- });
20
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exists = exists;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- * Validates if property exists
7
- * @validator exists
8
- */
9
- function exists(options) {
10
- return (0, index_js_1.validator)('exists', (input, context, _this) => {
11
- if (input !== undefined ||
12
- (context.scope &&
13
- Object.getOwnPropertyDescriptor(context.scope, input))) {
14
- return input;
15
- }
16
- context.fail(_this, `{{label}} must exist`, input);
17
- }, options);
18
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLength = getLength;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- * Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
7
- * @validator getLength
8
- */
9
- function getLength() {
10
- return (0, index_js_1.validator)('getLength', (input, context, _this) => {
11
- if (typeof input === 'string')
12
- return input.length;
13
- if (Array.isArray(input))
14
- return input.length;
15
- if (input instanceof ArrayBuffer)
16
- return input.byteLength;
17
- if (input &&
18
- typeof input === 'object' &&
19
- typeof input.length === 'number') {
20
- return input.length;
21
- }
22
- if (input &&
23
- typeof input === 'object' &&
24
- typeof input.size === 'number') {
25
- return input.size;
26
- }
27
- context.fail(_this, `Unable to get length`, input);
28
- });
29
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oneOf = oneOf;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- *
7
- */
8
- function oneOf(rules) {
9
- const l = rules.length;
10
- return (0, index_js_1.validator)('union', (input, context, _this) => {
11
- let i;
12
- let c;
13
- let discriminator;
14
- let v;
15
- let passed = false;
16
- // Mock fail method to prevent errors
17
- context.fail = () => (passed = false);
18
- for (i = 0; i < l; i++) {
19
- passed = true;
20
- if (Array.isArray(rules[i])) {
21
- c = rules[i][0];
22
- discriminator = rules[i][1];
23
- if (!(input &&
24
- typeof input === 'object' &&
25
- typeof discriminator === 'object')) {
26
- continue;
27
- }
28
- try {
29
- for (const k of Object.keys(discriminator)) {
30
- discriminator[k](input[k], context);
31
- if (!passed)
32
- break;
33
- }
34
- if (!passed)
35
- continue;
36
- }
37
- catch {
38
- continue;
39
- }
40
- }
41
- else
42
- c = rules[i];
43
- if (passed)
44
- try {
45
- v = c(input, context);
46
- if (passed)
47
- break;
48
- }
49
- catch {
50
- //
51
- }
52
- }
53
- // Restore fail method
54
- delete context.fail;
55
- if (passed)
56
- return v;
57
- context.fail(_this, `Value didn't match one of required rules`, input);
58
- });
59
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optional = optional;
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', (input, context) => {
11
- if (input == null)
12
- return input;
13
- return nested(input, context);
14
- }, options);
15
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pipe = pipe;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- *
7
- * @validator pipe
8
- */
9
- function pipe(rules, options) {
10
- const l = rules.length;
11
- const returnIndex = options?.returnIndex;
12
- return (0, index_js_1.validator)('pipe', (input, context) => {
13
- let i;
14
- let c;
15
- let v = input;
16
- let returnValue = input;
17
- const oldErrors = context.errors.length;
18
- for (i = 0; i < l; i++) {
19
- c = rules[i];
20
- v = c(v, context);
21
- if (returnIndex == null || i <= returnIndex)
22
- returnValue = v;
23
- if (context.errors.length > oldErrors)
24
- return;
25
- }
26
- return returnValue;
27
- }, options);
28
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.required = required;
4
- const index_js_1 = require("../../core/index.js");
5
- /**
6
- * Check if value is not nullish before calling nested rule
7
- * @validator required
8
- */
9
- function required(nested, options) {
10
- return (0, index_js_1.validator)('required', (input, context, _this) => {
11
- if (input == null)
12
- input = options?.default;
13
- if (input == null) {
14
- context.fail(_this, `Value required`, input);
15
- return;
16
- }
17
- return nested(input, context);
18
- }, options);
19
- }
@@ -1 +0,0 @@
1
- {"root":["../../src/constants.ts","../../src/factories.ts","../../src/index.ts","../../src/core/constants.ts","../../src/core/context.ts","../../src/core/index.ts","../../src/core/types.ts","../../src/core/utilities.ts","../../src/core/validation-error.ts","../../src/core/validator.ts","../../src/helpers/object.utils.ts","../../src/helpers/omit-undefined.ts","../../src/helpers/string.utils.ts","../../src/rules/index.ts","../../src/rules/format-rules/is-alpha.ts","../../src/rules/format-rules/is-ascii.ts","../../src/rules/format-rules/is-base64.ts","../../src/rules/format-rules/is-btc-address.ts","../../src/rules/format-rules/is-credit-card.ts","../../src/rules/format-rules/is-decimal.ts","../../src/rules/format-rules/is-ean.ts","../../src/rules/format-rules/is-email.ts","../../src/rules/format-rules/is-eth-address.ts","../../src/rules/format-rules/is-fqdn.ts","../../src/rules/format-rules/is-hash.ts","../../src/rules/format-rules/is-hex-color.ts","../../src/rules/format-rules/is-hex.ts","../../src/rules/format-rules/is-iban.ts","../../src/rules/format-rules/is-ip.ts","../../src/rules/format-rules/is-issn.ts","../../src/rules/format-rules/is-jwt.ts","../../src/rules/format-rules/is-lowercase.ts","../../src/rules/format-rules/is-mac-address.ts","../../src/rules/format-rules/is-mobile-phone.ts","../../src/rules/format-rules/is-object-id.ts","../../src/rules/format-rules/is-passport-number.ts","../../src/rules/format-rules/is-port.ts","../../src/rules/format-rules/is-time.ts","../../src/rules/format-rules/is-url.ts","../../src/rules/format-rules/is-uuid.ts","../../src/rules/format-rules/is-vat-number.ts","../../src/rules/format-rules/matches.ts","../../src/rules/logical-rules/is-defined.ts","../../src/rules/logical-rules/is-empty.ts","../../src/rules/logical-rules/is-equal.ts","../../src/rules/logical-rules/range.ts","../../src/rules/type-rules/is-any.ts","../../src/rules/type-rules/is-array.ts","../../src/rules/type-rules/is-bigint.ts","../../src/rules/type-rules/is-boolean.ts","../../src/rules/type-rules/is-date.ts","../../src/rules/type-rules/is-enum.ts","../../src/rules/type-rules/is-integer.ts","../../src/rules/type-rules/is-null.ts","../../src/rules/type-rules/is-number.ts","../../src/rules/type-rules/is-object.ts","../../src/rules/type-rules/is-record.ts","../../src/rules/type-rules/is-string.ts","../../src/rules/type-rules/is-tuple.ts","../../src/rules/type-rules/is-undefined.ts","../../src/rules/utility-rules/all-of.ts","../../src/rules/utility-rules/exists.ts","../../src/rules/utility-rules/get-length.ts","../../src/rules/utility-rules/one-of.ts","../../src/rules/utility-rules/optional.ts","../../src/rules/utility-rules/pipe.ts","../../src/rules/utility-rules/required.ts"],"version":"5.9.2"}
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1 +0,0 @@
1
- {"root":["../../src/constants.ts","../../src/factories.ts","../../src/index.ts","../../src/core/constants.ts","../../src/core/context.ts","../../src/core/index.ts","../../src/core/types.ts","../../src/core/utilities.ts","../../src/core/validation-error.ts","../../src/core/validator.ts","../../src/helpers/object.utils.ts","../../src/helpers/omit-undefined.ts","../../src/helpers/string.utils.ts","../../src/rules/index.ts","../../src/rules/format-rules/is-alpha.ts","../../src/rules/format-rules/is-ascii.ts","../../src/rules/format-rules/is-base64.ts","../../src/rules/format-rules/is-btc-address.ts","../../src/rules/format-rules/is-credit-card.ts","../../src/rules/format-rules/is-decimal.ts","../../src/rules/format-rules/is-ean.ts","../../src/rules/format-rules/is-email.ts","../../src/rules/format-rules/is-eth-address.ts","../../src/rules/format-rules/is-fqdn.ts","../../src/rules/format-rules/is-hash.ts","../../src/rules/format-rules/is-hex-color.ts","../../src/rules/format-rules/is-hex.ts","../../src/rules/format-rules/is-iban.ts","../../src/rules/format-rules/is-ip.ts","../../src/rules/format-rules/is-issn.ts","../../src/rules/format-rules/is-jwt.ts","../../src/rules/format-rules/is-lowercase.ts","../../src/rules/format-rules/is-mac-address.ts","../../src/rules/format-rules/is-mobile-phone.ts","../../src/rules/format-rules/is-object-id.ts","../../src/rules/format-rules/is-passport-number.ts","../../src/rules/format-rules/is-port.ts","../../src/rules/format-rules/is-time.ts","../../src/rules/format-rules/is-url.ts","../../src/rules/format-rules/is-uuid.ts","../../src/rules/format-rules/is-vat-number.ts","../../src/rules/format-rules/matches.ts","../../src/rules/logical-rules/is-defined.ts","../../src/rules/logical-rules/is-empty.ts","../../src/rules/logical-rules/is-equal.ts","../../src/rules/logical-rules/range.ts","../../src/rules/type-rules/is-any.ts","../../src/rules/type-rules/is-array.ts","../../src/rules/type-rules/is-bigint.ts","../../src/rules/type-rules/is-boolean.ts","../../src/rules/type-rules/is-date.ts","../../src/rules/type-rules/is-enum.ts","../../src/rules/type-rules/is-integer.ts","../../src/rules/type-rules/is-null.ts","../../src/rules/type-rules/is-number.ts","../../src/rules/type-rules/is-object.ts","../../src/rules/type-rules/is-record.ts","../../src/rules/type-rules/is-string.ts","../../src/rules/type-rules/is-tuple.ts","../../src/rules/type-rules/is-undefined.ts","../../src/rules/utility-rules/all-of.ts","../../src/rules/utility-rules/exists.ts","../../src/rules/utility-rules/get-length.ts","../../src/rules/utility-rules/one-of.ts","../../src/rules/utility-rules/optional.ts","../../src/rules/utility-rules/pipe.ts","../../src/rules/utility-rules/required.ts"],"version":"5.9.2"}
package/types/index.d.cts DELETED
@@ -1,65 +0,0 @@
1
- import * as vg from './rules/index.js';
2
- export * from './constants.js';
3
- export * from './core/index.js';
4
- export type { IsObject } from './rules/type-rules/is-object.js';
5
- declare const isAlpha: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
6
- declare const isAlphanumeric: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
7
- declare const isAny: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
8
- declare const isArray: import("./core/validator.js").Validator<unknown[], unknown, import("./core/types.js").ExecutionOptions>;
9
- declare const isAscii: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
10
- declare const isBase64: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
11
- declare const isBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
12
- declare const isBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
13
- declare const isBtcAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
14
- declare const isCreditCard: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
15
- declare const isDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
16
- declare const isDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
17
- declare const isDecimal: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
18
- declare const isDefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
19
- declare const isEAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
20
- declare const isEmail: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
21
- declare const isEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
22
- declare const isETHAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
23
- declare const isFQDN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
24
- declare const isHex: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
25
- declare const isHexColor: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
26
- declare const isIBAN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
27
- declare const isInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
28
- declare const isIP: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
29
- declare const isIPRange: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
30
- declare const isISSN: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
31
- declare const isJWT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
32
- declare const isLowercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
33
- declare const isMACAddress: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
34
- declare const isMobilePhone: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
35
- declare const isNotEmpty: import("./core/validator.js").Validator<any, any, import("./core/types.js").ExecutionOptions>;
36
- declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
37
- declare const isNotNullish: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
38
- declare const isNull: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
39
- declare const isNullish: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
40
- declare const isNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
41
- declare const isObject: vg.IsObject.Validator<object, string | object>;
42
- declare const isObjectId: import("./core/validator.js").Validator<string | vg.ObjectIdLike | Uint8Array<ArrayBufferLike>, unknown, import("./core/types.js").ExecutionOptions>;
43
- declare const isPort: import("./core/validator.js").Validator<number, string | number, import("./core/types.js").ExecutionOptions>;
44
- declare const isString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
45
- declare const isSWIFT: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
46
- declare const isTime: import("./core/validator.js").Validator<string, string | Date, import("./core/types.js").ExecutionOptions>;
47
- declare const isUndefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
48
- declare const isUppercase: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
49
- declare const isURL: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
50
- declare const isUUID: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
51
- declare const isUUID1: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
52
- declare const isUUID2: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
53
- declare const isUUID3: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
54
- declare const isUUID4: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
55
- declare const isUUID5: import("./core/validator.js").Validator<string, string, import("./core/types.js").ExecutionOptions>;
56
- declare const toArray: import("./core/validator.js").Validator<any[], any, import("./core/types.js").ExecutionOptions>;
57
- declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
58
- declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
59
- declare const toDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
60
- declare const toDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
61
- declare const toInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
62
- declare const toNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
63
- declare const toString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
64
- declare const toTime: import("./core/validator.js").Validator<string, string | Date, import("./core/types.js").ExecutionOptions>;
65
- export { isAlpha, isAlphanumeric, isAny, isArray, isAscii, isBase64, isBigint, isBoolean, isBtcAddress, isCreditCard, isDate, isDateString, isDecimal, isDefined, isEAN, isEmail, isEmpty, isETHAddress, isFQDN, isHex, isHexColor, isIBAN, isInteger, isIP, isIPRange, isISSN, isJWT, isLowercase, isMACAddress, isMobilePhone, isNotEmpty, isNotNull, isNotNullish, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isTime, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, toTime, vg, };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes