valgen 5.4.1 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/cjs/core/context.js +13 -10
  3. package/cjs/core/index.js +2 -2
  4. package/cjs/core/utilities.js +4 -5
  5. package/cjs/core/validator.js +10 -7
  6. package/cjs/helpers/object.utils.js +2 -3
  7. package/cjs/helpers/omit-undefined.js +1 -2
  8. package/cjs/helpers/string.utils.js +2 -5
  9. package/cjs/index.js +2 -2
  10. package/cjs/rules/format-rules/is-alpha.js +6 -6
  11. package/cjs/rules/format-rules/is-ascii.js +2 -3
  12. package/cjs/rules/format-rules/is-base64.js +4 -4
  13. package/cjs/rules/format-rules/is-btc-address.js +4 -4
  14. package/cjs/rules/format-rules/is-credit-card.js +5 -4
  15. package/cjs/rules/format-rules/is-decimal.js +4 -4
  16. package/cjs/rules/format-rules/is-ean.js +2 -3
  17. package/cjs/rules/format-rules/is-email.js +4 -4
  18. package/cjs/rules/format-rules/is-eth-address.js +4 -4
  19. package/cjs/rules/format-rules/is-fqdn.js +4 -4
  20. package/cjs/rules/format-rules/is-hash.js +4 -4
  21. package/cjs/rules/format-rules/is-hex-color.js +4 -4
  22. package/cjs/rules/format-rules/is-hex.js +4 -4
  23. package/cjs/rules/format-rules/is-iban.js +4 -5
  24. package/cjs/rules/format-rules/is-ip.js +12 -7
  25. package/cjs/rules/format-rules/is-issn.js +4 -4
  26. package/cjs/rules/format-rules/is-jwt.js +2 -3
  27. package/cjs/rules/format-rules/is-lowercase.js +8 -7
  28. package/cjs/rules/format-rules/is-mac-address.js +6 -4
  29. package/cjs/rules/format-rules/is-mobile-phone.js +5 -4
  30. package/cjs/rules/format-rules/is-object-id.js +7 -5
  31. package/cjs/rules/format-rules/is-passport-number.js +5 -4
  32. package/cjs/rules/format-rules/is-port.js +6 -4
  33. package/cjs/rules/format-rules/is-url.js +6 -4
  34. package/cjs/rules/format-rules/is-uuid.js +6 -4
  35. package/cjs/rules/format-rules/is-vat-number.js +4 -4
  36. package/cjs/rules/format-rules/matches.js +2 -3
  37. package/cjs/rules/index.js +14 -13
  38. package/cjs/rules/logical-rules/is-defined.js +2 -17
  39. package/cjs/rules/logical-rules/is-empty.js +4 -5
  40. package/cjs/rules/logical-rules/range.js +57 -26
  41. package/cjs/rules/type-rules/is-any.js +1 -3
  42. package/cjs/rules/type-rules/is-array.js +5 -4
  43. package/cjs/rules/type-rules/is-bigint.js +5 -4
  44. package/cjs/rules/type-rules/is-boolean.js +2 -3
  45. package/cjs/rules/type-rules/is-date.js +13 -8
  46. package/cjs/rules/type-rules/is-enum.js +7 -4
  47. package/cjs/rules/type-rules/is-integer.js +11 -5
  48. package/cjs/rules/type-rules/is-null.js +4 -11
  49. package/cjs/rules/type-rules/is-number.js +7 -4
  50. package/cjs/rules/type-rules/is-object.js +20 -12
  51. package/cjs/rules/type-rules/is-record.js +2 -3
  52. package/cjs/rules/type-rules/is-string.js +11 -11
  53. package/cjs/rules/type-rules/is-tuple.js +7 -5
  54. package/cjs/rules/type-rules/is-undefined.js +17 -0
  55. package/cjs/rules/utility-rules/exists.js +6 -4
  56. package/cjs/rules/utility-rules/get-length.js +10 -5
  57. package/cjs/rules/utility-rules/optional.js +2 -3
  58. package/cjs/rules/utility-rules/pipe.js +5 -6
  59. package/cjs/rules/utility-rules/required.js +2 -3
  60. package/cjs/rules/utility-rules/union.js +2 -3
  61. package/esm/core/context.js +13 -10
  62. package/esm/core/index.js +2 -2
  63. package/esm/core/utilities.js +3 -3
  64. package/esm/core/validator.js +8 -4
  65. package/esm/helpers/string.utils.js +1 -3
  66. package/esm/index.js +1 -1
  67. package/esm/rules/format-rules/is-alpha.js +4 -3
  68. package/esm/rules/format-rules/is-ascii.js +1 -1
  69. package/esm/rules/format-rules/is-base64.js +3 -2
  70. package/esm/rules/format-rules/is-btc-address.js +3 -2
  71. package/esm/rules/format-rules/is-credit-card.js +4 -2
  72. package/esm/rules/format-rules/is-decimal.js +3 -2
  73. package/esm/rules/format-rules/is-ean.js +1 -1
  74. package/esm/rules/format-rules/is-email.js +3 -2
  75. package/esm/rules/format-rules/is-eth-address.js +3 -2
  76. package/esm/rules/format-rules/is-fqdn.js +3 -2
  77. package/esm/rules/format-rules/is-hash.js +3 -2
  78. package/esm/rules/format-rules/is-hex-color.js +3 -2
  79. package/esm/rules/format-rules/is-hex.js +3 -2
  80. package/esm/rules/format-rules/is-iban.js +2 -2
  81. package/esm/rules/format-rules/is-ip.js +10 -4
  82. package/esm/rules/format-rules/is-issn.js +3 -2
  83. package/esm/rules/format-rules/is-jwt.js +1 -1
  84. package/esm/rules/format-rules/is-lowercase.js +6 -4
  85. package/esm/rules/format-rules/is-mac-address.js +5 -2
  86. package/esm/rules/format-rules/is-mobile-phone.js +4 -2
  87. package/esm/rules/format-rules/is-object-id.js +7 -4
  88. package/esm/rules/format-rules/is-passport-number.js +4 -2
  89. package/esm/rules/format-rules/is-port.js +5 -2
  90. package/esm/rules/format-rules/is-url.js +5 -2
  91. package/esm/rules/format-rules/is-uuid.js +5 -2
  92. package/esm/rules/format-rules/is-vat-number.js +3 -2
  93. package/esm/rules/format-rules/matches.js +2 -2
  94. package/esm/rules/index.js +14 -13
  95. package/esm/rules/logical-rules/is-defined.js +1 -14
  96. package/esm/rules/logical-rules/is-empty.js +2 -2
  97. package/esm/rules/logical-rules/range.js +52 -21
  98. package/esm/rules/type-rules/is-any.js +1 -3
  99. package/esm/rules/type-rules/is-array.js +5 -3
  100. package/esm/rules/type-rules/is-bigint.js +4 -2
  101. package/esm/rules/type-rules/is-boolean.js +2 -2
  102. package/esm/rules/type-rules/is-date.js +11 -5
  103. package/esm/rules/type-rules/is-enum.js +7 -3
  104. package/esm/rules/type-rules/is-integer.js +11 -4
  105. package/esm/rules/type-rules/is-null.js +2 -8
  106. package/esm/rules/type-rules/is-number.js +6 -2
  107. package/esm/rules/type-rules/is-object.js +19 -10
  108. package/esm/rules/type-rules/is-record.js +2 -2
  109. package/esm/rules/type-rules/is-string.js +7 -7
  110. package/esm/rules/type-rules/is-tuple.js +7 -4
  111. package/esm/rules/type-rules/is-undefined.js +14 -0
  112. package/esm/rules/utility-rules/exists.js +5 -2
  113. package/esm/rules/utility-rules/get-length.js +9 -3
  114. package/esm/rules/utility-rules/optional.js +2 -2
  115. package/esm/rules/utility-rules/pipe.js +4 -4
  116. package/esm/rules/utility-rules/required.js +2 -2
  117. package/esm/rules/utility-rules/union.js +1 -1
  118. package/package.json +2 -2
  119. package/typings/core/index.d.ts +3 -3
  120. package/typings/core/types.d.ts +1 -1
  121. package/typings/index.d.ts +1 -1
  122. package/typings/rules/index.d.ts +14 -13
  123. package/typings/rules/logical-rules/is-defined.d.ts +0 -5
  124. package/typings/rules/type-rules/is-tuple.d.ts +36 -4
  125. package/typings/rules/type-rules/is-undefined.d.ts +6 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBigint = void 0;
3
+ exports.isBigint = isBigint;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "BigInt".
@@ -8,14 +8,15 @@ const index_js_1 = require("../../core/index.js");
8
8
  * @validator isNumber
9
9
  */
10
10
  function isBigint(options) {
11
- return (0, index_js_1.validator)('isBigint', function (input, context, _this) {
11
+ return (0, index_js_1.validator)('isBigint', (input, context, _this) => {
12
12
  const coerce = options?.coerce || context.coerce;
13
13
  if (typeof input === 'bigint')
14
14
  return input;
15
- if ((typeof input === 'number' && !isNaN(input)) || (typeof input === 'string' && coerce))
15
+ if ((typeof input === 'number' && !isNaN(input)) ||
16
+ (typeof input === 'string' && coerce)) {
16
17
  return BigInt(input);
18
+ }
17
19
  const t = typeof input === 'string' ? 'String ' : '';
18
20
  context.fail(_this, `${t}"{{value}}" is not a valid BigInt value`, input);
19
21
  }, options);
20
22
  }
21
- exports.isBigint = isBigint;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBoolean = void 0;
3
+ exports.isBoolean = isBoolean;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  const TRUE_PATTERN = /^true|t|1|yes|y$/i;
6
6
  const FALSE_PATTERN = /^false|f|0|no|n$/i;
@@ -10,7 +10,7 @@ const FALSE_PATTERN = /^false|f|0|no|n$/i;
10
10
  * @validator isBoolean
11
11
  */
12
12
  function isBoolean(options) {
13
- return (0, index_js_1.validator)('isBoolean', function (input, context, _this) {
13
+ return (0, index_js_1.validator)('isBoolean', (input, context, _this) => {
14
14
  const coerce = options?.coerce || context.coerce;
15
15
  let output = input;
16
16
  if (output != null && typeof output !== 'boolean' && coerce) {
@@ -30,4 +30,3 @@ function isBoolean(options) {
30
30
  context.fail(_this, `${t}"{{value}}" is not a valid boolean value`, input);
31
31
  }, options);
32
32
  }
33
- exports.isBoolean = isBoolean;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDateString = exports.isDate = void 0;
3
+ exports.isDate = isDate;
4
+ exports.isDateString = isDateString;
4
5
  const date_fns_1 = require("date-fns");
5
6
  const index_js_1 = require("../../core/index.js");
6
7
  /* eslint-disable-next-line max-len */ // noinspection RegExpUnnecessaryNonCapturingGroup
@@ -14,7 +15,7 @@ const DATE_PATTERN =
14
15
  */
15
16
  function isDate(options) {
16
17
  const precision = options?.precision;
17
- return (0, index_js_1.validator)('isDate', function (input, context, _this) {
18
+ return (0, index_js_1.validator)('isDate', (input, context, _this) => {
18
19
  const coerce = options?.coerce || context.coerce;
19
20
  let d;
20
21
  if (input instanceof Date)
@@ -39,10 +40,11 @@ function isDate(options) {
39
40
  d.setHours(0, 0, 0, 0);
40
41
  return d;
41
42
  }
42
- context.fail(_this, `"{{value}}" is not a valid date value`, input, { ...options });
43
+ context.fail(_this, `"{{value}}" is not a valid date value`, input, {
44
+ ...options,
45
+ });
43
46
  }, options);
44
47
  }
45
- exports.isDate = isDate;
46
48
  /**
47
49
  * Validates if value is DFS (date formatted string).
48
50
  * Converts input value to DFS if coerce option is set to 'true'.
@@ -51,7 +53,7 @@ exports.isDate = isDate;
51
53
  function isDateString(options) {
52
54
  const precision = options?.precision;
53
55
  const trim = options?.trim;
54
- return (0, index_js_1.validator)('isDateString', function (input, context, _this) {
56
+ return (0, index_js_1.validator)('isDateString', (input, context, _this) => {
55
57
  const coerce = options?.coerce || context.coerce;
56
58
  if (typeof input === 'string') {
57
59
  const m = DATE_PATTERN.exec(input);
@@ -87,9 +89,12 @@ function isDateString(options) {
87
89
  }
88
90
  }
89
91
  else if (input instanceof Date) {
90
- return trim === 'date' ? (0, date_fns_1.formatISO)(input, { representation: 'date' }) : (0, date_fns_1.formatISO)(input).substring(0, 19);
92
+ return trim === 'date'
93
+ ? (0, date_fns_1.formatISO)(input, { representation: 'date' })
94
+ : (0, date_fns_1.formatISO)(input).substring(0, 19);
91
95
  }
92
- context.fail(_this, `"{{value}}" is not a valid date string`, input, { ...options });
96
+ context.fail(_this, `"{{value}}" is not a valid date string`, input, {
97
+ ...options,
98
+ });
93
99
  }, options);
94
100
  }
95
- exports.isDateString = isDateString;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEnum = void 0;
3
+ exports.isEnum = isEnum;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if given value is one of enum values.
@@ -17,12 +17,15 @@ function isEnum(values, options) {
17
17
  a[v] = true;
18
18
  return a;
19
19
  }, {});
20
- return (0, index_js_1.validator)('isEnum', function (input, context, _this) {
21
- if (input != null && valObj[typeof input === 'string' && caseInSensitive ? input.toUpperCase() : input])
20
+ return (0, index_js_1.validator)('isEnum', (input, context, _this) => {
21
+ if (input != null &&
22
+ valObj[typeof input === 'string' && caseInSensitive
23
+ ? input.toUpperCase()
24
+ : input]) {
22
25
  return input;
26
+ }
23
27
  context.fail(_this, `Value must be one of enumeration member${enumName ? ` (${enumName})` : ''}`, input, {
24
28
  enum: enumName,
25
29
  });
26
30
  }, options);
27
31
  }
28
- exports.isEnum = isEnum;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isInteger = void 0;
3
+ exports.isInteger = isInteger;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "integer".
@@ -8,7 +8,7 @@ const index_js_1 = require("../../core/index.js");
8
8
  * @validator isInteger
9
9
  */
10
10
  function isInteger(options) {
11
- return (0, index_js_1.validator)('isInteger', function (input, context, _this) {
11
+ return (0, index_js_1.validator)('isInteger', (input, context, _this) => {
12
12
  const coerce = options?.coerce || context.coerce;
13
13
  let output = input;
14
14
  if (output != null && typeof output !== 'number' && coerce) {
@@ -20,10 +20,16 @@ function isInteger(options) {
20
20
  input = output;
21
21
  }
22
22
  }
23
- if (typeof output === 'number' && !isNaN(output) && Number.isInteger(output))
23
+ if (typeof output === 'number' &&
24
+ !isNaN(output) &&
25
+ Number.isInteger(output)) {
24
26
  return output;
25
- const t = typeof input === 'bigint' ? 'BigInt ' : typeof input === 'string' ? 'String ' : '';
27
+ }
28
+ const t = typeof input === 'bigint'
29
+ ? 'BigInt '
30
+ : typeof input === 'string'
31
+ ? 'String '
32
+ : '';
26
33
  context.fail(_this, `${t}"{{value}}" is not a valid integer value`, input);
27
34
  }, options);
28
35
  }
29
- exports.isInteger = isInteger;
@@ -1,34 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNullish = exports.isNull = void 0;
3
+ exports.isNull = isNull;
4
+ exports.isNullish = isNullish;
4
5
  const index_js_1 = require("../../core/index.js");
5
6
  /**
6
7
  * Validates if value is "null".
7
8
  * @validator isNull
8
9
  */
9
10
  function isNull(options) {
10
- return (0, index_js_1.validator)('isNull', function (input, context, _this) {
11
+ return (0, index_js_1.validator)('isNull', (input, context, _this) => {
11
12
  if (input === null)
12
13
  return input;
13
- const coerce = options?.coerce || context.coerce;
14
- if (coerce)
15
- return null;
16
14
  context.fail(_this, `"{{value}}" is not null`, input);
17
15
  }, options);
18
16
  }
19
- exports.isNull = isNull;
20
17
  /**
21
18
  * Validates if value is "null" or "undefined".
22
19
  * @validator isNull
23
20
  */
24
21
  function isNullish(options) {
25
- return (0, index_js_1.validator)('isNullish', function (input, context, _this) {
22
+ return (0, index_js_1.validator)('isNullish', (input, context, _this) => {
26
23
  if (input == null)
27
24
  return input;
28
- const coerce = options?.coerce || context.coerce;
29
- if (coerce)
30
- return null;
31
25
  context.fail(_this, `"{{value}}" is not nullish`, input);
32
26
  }, options);
33
27
  }
34
- exports.isNullish = isNullish;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNumber = void 0;
3
+ exports.isNumber = isNumber;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if value is "number".
@@ -8,7 +8,7 @@ const index_js_1 = require("../../core/index.js");
8
8
  * @validator isNumber
9
9
  */
10
10
  function isNumber(options) {
11
- return (0, index_js_1.validator)('isNumber', function (input, context, _this) {
11
+ return (0, index_js_1.validator)('isNumber', (input, context, _this) => {
12
12
  const coerce = options?.coerce || context.coerce;
13
13
  let output = input;
14
14
  if (output != null && typeof output !== 'number' && coerce) {
@@ -22,8 +22,11 @@ function isNumber(options) {
22
22
  }
23
23
  if (typeof output === 'number' && !isNaN(output))
24
24
  return output;
25
- const t = typeof input === 'bigint' ? 'BigInt ' : typeof input === 'string' ? 'String ' : '';
25
+ const t = typeof input === 'bigint'
26
+ ? 'BigInt '
27
+ : typeof input === 'string'
28
+ ? 'String '
29
+ : '';
26
30
  context.fail(_this, `${t}"{{value}}" is not a valid number value`, input);
27
31
  }, options);
28
32
  }
29
- exports.isNumber = isNumber;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isObject = void 0;
3
+ exports.isObject = isObject;
4
4
  const constants_js_1 = require("../../constants.js");
5
5
  const index_js_1 = require("../../core/index.js");
6
6
  /**
@@ -22,8 +22,9 @@ function isObject(schema, options) {
22
22
  const n = schema[k];
23
23
  const key = caseInSensitive ? k.toLowerCase() : k;
24
24
  if (Array.isArray(n)) {
25
- if (!(0, index_js_1.isValidator)(n[0]))
25
+ if (!(0, index_js_1.isValidator)(n[0])) {
26
26
  throw new TypeError(`Invalid tuple definition in validation schema (${k})`);
27
+ }
27
28
  propertyRules[key] = n[0];
28
29
  propertyOptions[key] = { as: k, ...n[1] };
29
30
  }
@@ -31,18 +32,20 @@ function isObject(schema, options) {
31
32
  propertyRules[key] = n;
32
33
  propertyOptions[key] = { as: k };
33
34
  }
34
- else
35
+ else {
35
36
  throw new TypeError(`Invalid definition in validation schema (${k})`);
37
+ }
36
38
  }
37
- const _rule = (0, index_js_1.validator)('isObject', function (input, context, _this) {
39
+ const _rule = (0, index_js_1.validator)('isObject', (input, context, _this) => {
38
40
  let output = input;
39
- if (ctor && ctor[constants_js_1.preValidation])
41
+ if (ctor && ctor[constants_js_1.preValidation]) {
40
42
  output = ctor[constants_js_1.preValidation](output, context, _this);
43
+ }
41
44
  const coerce = options?.coerce || context.coerce;
42
45
  if (typeof output === 'string' && coerce)
43
46
  output = JSON.parse(output);
44
47
  if (!(output && typeof output === 'object')) {
45
- context.fail(_this, `{{label}} must be an object`, input);
48
+ context.fail(_this, `"{{value}}" is not an object`, input);
46
49
  return;
47
50
  }
48
51
  const keys = [...Object.keys(output), ...schemaKeys];
@@ -57,8 +60,9 @@ function isObject(schema, options) {
57
60
  Object.setPrototypeOf(out, ctor.prototype);
58
61
  if (detectCircular) {
59
62
  context.circMap = context.circMap || new Map();
60
- if (context.circMap.has(output))
63
+ if (context.circMap.has(output)) {
61
64
  return context.circMap.get(output);
65
+ }
62
66
  context.circMap.set(output, out);
63
67
  }
64
68
  if (context.root == null)
@@ -70,7 +74,9 @@ function isObject(schema, options) {
70
74
  inputKey = keys[i];
71
75
  schemaKey = caseInSensitive ? inputKey.toLowerCase() : inputKey;
72
76
  v = output[inputKey];
73
- _propRule = propertyRules[schemaKey] || ((0, index_js_1.isValidator)(additionalFields) ? additionalFields : undefined);
77
+ _propRule =
78
+ propertyRules[schemaKey] ||
79
+ ((0, index_js_1.isValidator)(additionalFields) ? additionalFields : undefined);
74
80
  if (_propRule) {
75
81
  if (processedSchemaKeys[schemaKey])
76
82
  continue;
@@ -80,18 +86,21 @@ function isObject(schema, options) {
80
86
  subCtx.context = ctorName;
81
87
  subCtx.location = location + (location ? '.' : '') + schemaKey;
82
88
  subCtx.property = schemaKey;
83
- if (propertyOptions[schemaKey]?.label)
89
+ if (propertyOptions[schemaKey]?.label) {
84
90
  subCtx.label = propertyOptions[schemaKey]?.label;
91
+ }
85
92
  v = _propRule(v, subCtx);
86
93
  }
87
94
  else if (v !== undefined) {
88
95
  if (!additionalFields)
89
96
  continue;
90
- if (additionalFields === 'error')
97
+ if (additionalFields === 'error') {
91
98
  context.fail(_propRule, `${ctorName || 'Object'} has no field '${inputKey}' and does not accept additional fields`, v);
99
+ }
92
100
  }
93
- if (v !== undefined)
101
+ if (v !== undefined) {
94
102
  out[propertyOptions[schemaKey]?.as || schemaKey] = v;
103
+ }
95
104
  }
96
105
  if (context.errors.length)
97
106
  return undefined;
@@ -104,4 +113,3 @@ function isObject(schema, options) {
104
113
  _rule.schema = schema;
105
114
  return _rule;
106
115
  }
107
- exports.isObject = isObject;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRecord = void 0;
3
+ exports.isRecord = isRecord;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates record object according to given "key" and "value" rules
@@ -8,7 +8,7 @@ const index_js_1 = require("../../core/index.js");
8
8
  * @validator isRecord
9
9
  */
10
10
  function isRecord(keyRule, valueRule, options) {
11
- return (0, index_js_1.validator)('isRecord', function (input, context, _this) {
11
+ return (0, index_js_1.validator)('isRecord', (input, context, _this) => {
12
12
  if (!(input && typeof input === 'object')) {
13
13
  context.fail(_this, `{{label}} must be an object`, input);
14
14
  return;
@@ -38,4 +38,3 @@ function isRecord(keyRule, valueRule, options) {
38
38
  return context.errors.length ? undefined : out;
39
39
  }, options);
40
40
  }
41
- exports.isRecord = isRecord;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trimStart = exports.trimEnd = exports.trim = exports.stringSplit = exports.stringReplace = exports.isString = void 0;
3
+ exports.trimStart = exports.trimEnd = void 0;
4
+ exports.isString = isString;
5
+ exports.stringReplace = stringReplace;
6
+ exports.stringSplit = stringSplit;
7
+ exports.trim = trim;
4
8
  const index_js_1 = require("../../core/index.js");
5
9
  /**
6
10
  * Validates if value is "string".
@@ -8,7 +12,7 @@ const index_js_1 = require("../../core/index.js");
8
12
  * @validator isString
9
13
  */
10
14
  function isString(options) {
11
- return (0, index_js_1.validator)('isString', function (input, context, _this) {
15
+ return (0, index_js_1.validator)('isString', (input, context, _this) => {
12
16
  const coerce = options?.coerce || context.coerce;
13
17
  let output = input;
14
18
  if (output != null && typeof output !== 'string' && coerce) {
@@ -26,35 +30,31 @@ function isString(options) {
26
30
  context.fail(_this, `"{{value}}" is not a string`, input);
27
31
  }, options);
28
32
  }
29
- exports.isString = isString;
30
33
  function stringReplace(searchValue, replacer) {
31
- return (0, index_js_1.validator)('stringReplace', function (input) {
34
+ return (0, index_js_1.validator)('stringReplace', (input) => {
32
35
  if (input == null)
33
36
  return input;
34
37
  return String(input).replace(searchValue, replacer);
35
38
  });
36
39
  }
37
- exports.stringReplace = stringReplace;
38
40
  function stringSplit(splitter, limit) {
39
- return (0, index_js_1.validator)('stringSplit', function (input) {
41
+ return (0, index_js_1.validator)('stringSplit', (input) => {
40
42
  if (input == null)
41
43
  return input;
42
44
  return String(input).split(splitter, limit);
43
45
  });
44
46
  }
45
- exports.stringSplit = stringSplit;
46
47
  /**
47
48
  * Removes whitespace from both ends of a string
48
49
  * @validator trim
49
50
  */
50
51
  function trim() {
51
- return (0, index_js_1.validator)('trim', function (input) {
52
+ return (0, index_js_1.validator)('trim', (input) => {
52
53
  if (input == null)
53
54
  return input;
54
55
  return String(input).trim();
55
56
  });
56
57
  }
57
- exports.trim = trim;
58
58
  // *************************************************************
59
59
  /**
60
60
  * Removes whitespace from the end of a string
@@ -62,7 +62,7 @@ exports.trim = trim;
62
62
  */
63
63
  const trimEnd = () => trimEndRule;
64
64
  exports.trimEnd = trimEnd;
65
- const trimEndRule = (0, index_js_1.validator)('trimEnd', function (input) {
65
+ const trimEndRule = (0, index_js_1.validator)('trimEnd', (input) => {
66
66
  if (input == null)
67
67
  return input;
68
68
  return String(input).trimEnd();
@@ -74,7 +74,7 @@ const trimEndRule = (0, index_js_1.validator)('trimEnd', function (input) {
74
74
  */
75
75
  const trimStart = () => trimStartRule;
76
76
  exports.trimStart = trimStart;
77
- const trimStartRule = (0, index_js_1.validator)('trimStart', function (input) {
77
+ const trimStartRule = (0, index_js_1.validator)('trimStart', (input) => {
78
78
  if (input == null)
79
79
  return input;
80
80
  return String(input).trimStart();
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isTuple = void 0;
3
+ exports.isTuple = isTuple;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  function isTuple(items, options) {
6
- return (0, index_js_1.validator)('isTuple', function (input, context, _this) {
6
+ return (0, index_js_1.validator)('isTuple', (input, context, _this) => {
7
7
  const coerce = options?.coerce || context.coerce;
8
8
  let output = input;
9
9
  if (output != null && coerce && !Array.isArray(output))
@@ -23,14 +23,16 @@ function isTuple(items, options) {
23
23
  for (i = 0; i < l && i < nl; i++) {
24
24
  itemRule = items[i];
25
25
  itemContext.scope = output;
26
- itemContext.label = context.label ? context.label + `[${i}]` : undefined;
26
+ itemContext.label = context.label
27
+ ? context.label + `[${i}]`
28
+ : undefined;
27
29
  itemContext.index = i;
28
30
  itemContext.location = location + '[' + i + ']';
29
- itemContext.label = (itemContext.label || itemContext.property || 'Value at ') + `[${i}]`;
31
+ itemContext.label =
32
+ (itemContext.label || itemContext.property || 'Value at ') + `[${i}]`;
30
33
  v = itemRule(output[i], itemContext);
31
34
  out.push(v);
32
35
  }
33
36
  return context.errors.length ? undefined : out;
34
37
  }, options);
35
38
  }
36
- exports.isTuple = isTuple;
@@ -0,0 +1,17 @@
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, `{{label}} mustn't be defined`, input);
16
+ }, options);
17
+ }
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exists = void 0;
3
+ exports.exists = exists;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Validates if property exists
7
7
  * @validator exists
8
8
  */
9
9
  function exists(options) {
10
- return (0, index_js_1.validator)('exists', function (input, context, _this) {
11
- if (input !== undefined || (context.scope && Object.getOwnPropertyDescriptor(context.scope, input)))
10
+ return (0, index_js_1.validator)('exists', (input, context, _this) => {
11
+ if (input !== undefined ||
12
+ (context.scope &&
13
+ Object.getOwnPropertyDescriptor(context.scope, input))) {
12
14
  return input;
15
+ }
13
16
  context.fail(_this, `{{label}} must exist`, input);
14
17
  }, options);
15
18
  }
16
- exports.exists = exists;
@@ -1,24 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLength = void 0;
3
+ exports.getLength = getLength;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
7
7
  * @validator getLength
8
8
  */
9
9
  function getLength() {
10
- return (0, index_js_1.validator)('getLength', function (input, context, _this) {
10
+ return (0, index_js_1.validator)('getLength', (input, context, _this) => {
11
11
  if (typeof input === 'string')
12
12
  return input.length;
13
13
  if (Array.isArray(input))
14
14
  return input.length;
15
15
  if (input instanceof ArrayBuffer)
16
16
  return input.byteLength;
17
- if (input && typeof input === 'object' && typeof input.length === 'number')
17
+ if (input &&
18
+ typeof input === 'object' &&
19
+ typeof input.length === 'number') {
18
20
  return input.length;
19
- if (input && typeof input === 'object' && typeof input.size === 'number')
21
+ }
22
+ if (input &&
23
+ typeof input === 'object' &&
24
+ typeof input.size === 'number') {
20
25
  return input.size;
26
+ }
21
27
  context.fail(_this, `Unable to get length of {{label}}`, input);
22
28
  });
23
29
  }
24
- exports.getLength = getLength;
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optional = void 0;
3
+ exports.optional = optional;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Makes sub-rule optional
7
7
  * @validator optional
8
8
  */
9
9
  function optional(nested, options) {
10
- return (0, index_js_1.validator)('optional', function (input, context) {
10
+ return (0, index_js_1.validator)('optional', (input, context) => {
11
11
  if (input == null)
12
12
  return input;
13
13
  return nested(input, context);
14
14
  }, options);
15
15
  }
16
- exports.optional = optional;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allOf = exports.pipe = void 0;
3
+ exports.pipe = pipe;
4
+ exports.allOf = allOf;
4
5
  const index_js_1 = require("../../core/index.js");
5
6
  /**
6
7
  *
@@ -9,11 +10,11 @@ const index_js_1 = require("../../core/index.js");
9
10
  function pipe(rules, options) {
10
11
  const l = rules.length;
11
12
  const returnIndex = options?.returnIndex;
12
- return (0, index_js_1.validator)('pipe', function (input, context) {
13
+ return (0, index_js_1.validator)('pipe', (input, context) => {
13
14
  let i;
14
15
  let c;
15
16
  let v = input;
16
- let returnValue;
17
+ let returnValue = input;
17
18
  for (i = 0; i < l; i++) {
18
19
  c = rules[i];
19
20
  v = c(v, context);
@@ -25,13 +26,12 @@ function pipe(rules, options) {
25
26
  return returnValue;
26
27
  }, options);
27
28
  }
28
- exports.pipe = pipe;
29
29
  /**
30
30
  * Test given value against to all codecs and returns original input
31
31
  * @validator allOf
32
32
  */
33
33
  function allOf(rules) {
34
- return (0, index_js_1.validator)('allOf', function (input, context) {
34
+ return (0, index_js_1.validator)('allOf', (input, context) => {
35
35
  let i;
36
36
  let c;
37
37
  const l = rules.length;
@@ -42,4 +42,3 @@ function allOf(rules) {
42
42
  return input;
43
43
  });
44
44
  }
45
- exports.allOf = allOf;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.required = void 0;
3
+ exports.required = required;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  * Makes sub-rule required
7
7
  * @validator required
8
8
  */
9
9
  function required(nested, options) {
10
- return (0, index_js_1.validator)('required', function (input, context, _this) {
10
+ return (0, index_js_1.validator)('required', (input, context, _this) => {
11
11
  if (input == null) {
12
12
  context.fail(_this, `{{label}} is required`, input);
13
13
  return;
@@ -15,4 +15,3 @@ function required(nested, options) {
15
15
  return nested(input, context);
16
16
  }, options);
17
17
  }
18
- exports.required = required;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.union = void 0;
3
+ exports.union = union;
4
4
  const index_js_1 = require("../../core/index.js");
5
5
  /**
6
6
  *
7
7
  */
8
8
  function union(codecs) {
9
9
  const l = codecs.length;
10
- return (0, index_js_1.validator)('union', function (input, context, _this) {
10
+ return (0, index_js_1.validator)('union', (input, context, _this) => {
11
11
  let i;
12
12
  let c;
13
13
  let v;
@@ -33,4 +33,3 @@ function union(codecs) {
33
33
  context.fail(_this, `Value didn't match any on union rules`, input);
34
34
  });
35
35
  }
36
- exports.union = union;