valgen 5.7.0 → 5.8.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 (66) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/esm/constants.js +2 -5
  3. package/esm/core/constants.js +2 -5
  4. package/esm/core/context.js +5 -9
  5. package/esm/core/index.js +6 -9
  6. package/esm/core/types.js +1 -2
  7. package/esm/core/utilities.js +6 -10
  8. package/esm/core/validation-error.js +1 -5
  9. package/esm/core/validator.js +14 -18
  10. package/esm/factories.js +1 -4
  11. package/esm/helpers/object.utils.js +2 -6
  12. package/esm/helpers/omit-undefined.js +1 -4
  13. package/esm/helpers/string.utils.js +1 -4
  14. package/esm/index.js +4 -67
  15. package/esm/rules/format-rules/is-alpha.js +6 -11
  16. package/esm/rules/format-rules/is-ascii.js +4 -8
  17. package/esm/rules/format-rules/is-base64.js +4 -8
  18. package/esm/rules/format-rules/is-btc-address.js +4 -8
  19. package/esm/rules/format-rules/is-credit-card.js +4 -8
  20. package/esm/rules/format-rules/is-decimal.js +4 -8
  21. package/esm/rules/format-rules/is-ean.js +4 -8
  22. package/esm/rules/format-rules/is-email.js +4 -8
  23. package/esm/rules/format-rules/is-eth-address.js +4 -8
  24. package/esm/rules/format-rules/is-fqdn.js +4 -8
  25. package/esm/rules/format-rules/is-hash.js +4 -8
  26. package/esm/rules/format-rules/is-hex-color.js +4 -8
  27. package/esm/rules/format-rules/is-hex.js +4 -8
  28. package/esm/rules/format-rules/is-iban.js +6 -11
  29. package/esm/rules/format-rules/is-ip.js +6 -11
  30. package/esm/rules/format-rules/is-issn.js +4 -8
  31. package/esm/rules/format-rules/is-jwt.js +4 -8
  32. package/esm/rules/format-rules/is-lowercase.js +6 -11
  33. package/esm/rules/format-rules/is-mac-address.js +4 -8
  34. package/esm/rules/format-rules/is-mobile-phone.js +4 -8
  35. package/esm/rules/format-rules/is-object-id.js +5 -9
  36. package/esm/rules/format-rules/is-passport-number.js +4 -8
  37. package/esm/rules/format-rules/is-port.js +4 -8
  38. package/esm/rules/format-rules/is-url.js +4 -8
  39. package/esm/rules/format-rules/is-uuid.js +4 -8
  40. package/esm/rules/format-rules/is-vat-number.js +4 -8
  41. package/esm/rules/format-rules/matches.js +3 -6
  42. package/esm/rules/index.js +50 -53
  43. package/esm/rules/logical-rules/is-defined.js +3 -6
  44. package/esm/rules/logical-rules/is-empty.js +5 -9
  45. package/esm/rules/logical-rules/range.js +19 -29
  46. package/esm/rules/type-rules/is-any.js +2 -6
  47. package/esm/rules/type-rules/is-array.js +3 -6
  48. package/esm/rules/type-rules/is-bigint.js +3 -6
  49. package/esm/rules/type-rules/is-boolean.js +3 -6
  50. package/esm/rules/type-rules/is-date.js +10 -14
  51. package/esm/rules/type-rules/is-enum.js +3 -6
  52. package/esm/rules/type-rules/is-integer.js +3 -6
  53. package/esm/rules/type-rules/is-null.js +9 -15
  54. package/esm/rules/type-rules/is-number.js +3 -6
  55. package/esm/rules/type-rules/is-object.js +11 -14
  56. package/esm/rules/type-rules/is-record.js +3 -6
  57. package/esm/rules/type-rules/is-string.js +13 -22
  58. package/esm/rules/type-rules/is-tuple.js +3 -6
  59. package/esm/rules/type-rules/is-undefined.js +3 -6
  60. package/esm/rules/utility-rules/exists.js +3 -6
  61. package/esm/rules/utility-rules/get-length.js +3 -6
  62. package/esm/rules/utility-rules/optional.js +3 -6
  63. package/esm/rules/utility-rules/pipe.js +5 -9
  64. package/esm/rules/utility-rules/required.js +3 -6
  65. package/esm/rules/utility-rules/union.js +3 -6
  66. package/package.json +1 -2
@@ -1,20 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lengthMax = exports.lengthMin = void 0;
4
- exports.range = range;
5
- exports.isGt = isGt;
6
- exports.isGte = isGte;
7
- exports.isLt = isLt;
8
- exports.isLte = isLte;
9
- const index_js_1 = require("../../core/index.js");
10
- const get_length_js_1 = require("../utility-rules/get-length.js");
11
- const pipe_js_1 = require("../utility-rules/pipe.js");
1
+ import { validator, } from '../../core/index.js';
2
+ import { getLength } from '../utility-rules/get-length.js';
3
+ import { allOf, pipe } from '../utility-rules/pipe.js';
12
4
  /**
13
5
  * Checks if value is between minValue and maxValue
14
6
  * @validator range
15
7
  */
16
- function range(minValue, maxValue, options) {
17
- return (0, index_js_1.validator)('range', (input, context, _this) => {
8
+ export function range(minValue, maxValue, options) {
9
+ return validator('range', (input, context, _this) => {
18
10
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
19
11
  (typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
20
12
  (typeof input === 'number' || typeof input === 'bigint') &&
@@ -39,8 +31,8 @@ function range(minValue, maxValue, options) {
39
31
  context.fail(_this, `Value must be between ${minValue} and ${maxValue}`, input);
40
32
  }, options);
41
33
  }
42
- function isGt(minValue, options) {
43
- return (0, index_js_1.validator)('isGt', (input, context, _this) => {
34
+ export function isGt(minValue, options) {
35
+ return validator('isGt', (input, context, _this) => {
44
36
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
45
37
  (typeof input === 'number' || typeof input === 'bigint') &&
46
38
  input > minValue) {
@@ -61,8 +53,8 @@ function isGt(minValue, options) {
61
53
  context.fail(_this, `{{label}} must be greater than ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
62
54
  }, options);
63
55
  }
64
- function isGte(minValue, options) {
65
- return (0, index_js_1.validator)('isGte', (input, context, _this) => {
56
+ export function isGte(minValue, options) {
57
+ return validator('isGte', (input, context, _this) => {
66
58
  if ((typeof minValue === 'number' || typeof minValue === 'bigint') &&
67
59
  (typeof input === 'number' || typeof input === 'bigint') &&
68
60
  input >= minValue) {
@@ -83,8 +75,8 @@ function isGte(minValue, options) {
83
75
  context.fail(_this, `{{label}} must be greater than or equal to ${typeof minValue === 'string' ? `"${minValue}"` : minValue}`, input);
84
76
  }, options);
85
77
  }
86
- function isLt(maxValue, options) {
87
- return (0, index_js_1.validator)('isLt', (input, context, _this) => {
78
+ export function isLt(maxValue, options) {
79
+ return validator('isLt', (input, context, _this) => {
88
80
  if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
89
81
  (typeof input === 'number' || typeof input === 'bigint') &&
90
82
  input < maxValue) {
@@ -105,8 +97,8 @@ function isLt(maxValue, options) {
105
97
  context.fail(_this, `{{label}} must be lover than ${typeof maxValue === 'string' ? `"${maxValue}"` : maxValue}`, input);
106
98
  }, options);
107
99
  }
108
- function isLte(maxValue, options) {
109
- return (0, index_js_1.validator)('isLte', (input, context, _this) => {
100
+ export function isLte(maxValue, options) {
101
+ return validator('isLte', (input, context, _this) => {
110
102
  if ((typeof maxValue === 'number' || typeof maxValue === 'bigint') &&
111
103
  (typeof input === 'number' || typeof input === 'bigint') &&
112
104
  input <= maxValue) {
@@ -131,25 +123,23 @@ function isLte(maxValue, options) {
131
123
  * Checks the length is at least "minValue"
132
124
  * @validator lengthMin
133
125
  */
134
- const lengthMin = (minValue) => (0, pipe_js_1.allOf)([
135
- (0, pipe_js_1.pipe)([
136
- (0, get_length_js_1.getLength)(),
126
+ export const lengthMin = (minValue) => allOf([
127
+ pipe([
128
+ getLength(),
137
129
  isGte(minValue, {
138
130
  onFail: () => `The length of {{label}} must be at least ${minValue}`,
139
131
  }),
140
132
  ]),
141
133
  ]);
142
- exports.lengthMin = lengthMin;
143
134
  /**
144
135
  * Checks if the length is at most "maxValue"
145
136
  * @validator lengthMax
146
137
  */
147
- const lengthMax = (maxValue) => (0, pipe_js_1.allOf)([
148
- (0, pipe_js_1.pipe)([
149
- (0, get_length_js_1.getLength)(),
138
+ export const lengthMax = (maxValue) => allOf([
139
+ pipe([
140
+ getLength(),
150
141
  isLte(maxValue, {
151
142
  onFail: () => `The length of {{label}} must be at most ${maxValue}`,
152
143
  }),
153
144
  ]),
154
145
  ]);
155
- exports.lengthMax = lengthMax;
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAny = void 0;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator } from '../../core/index.js';
5
2
  /**
6
3
  * Does nothing, just returns original input value.
7
4
  * @validator isAny
8
5
  */
9
- const isAny = () => (0, index_js_1.validator)('is-any', (input) => input);
10
- exports.isAny = isAny;
6
+ export const isAny = () => validator('is-any', (input) => input);
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isArray = isArray;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  /**
6
3
  * Validates if value is "array" and applies validation for each item.
7
4
  * Converts input value to array if coerce option is set to 'true'.
8
5
  * @validator isArray
9
6
  */
10
- function isArray(itemValidator, options) {
11
- return (0, index_js_1.validator)('isArray', (input, context, _this) => {
7
+ export function isArray(itemValidator, options) {
8
+ return validator('isArray', (input, context, _this) => {
12
9
  const coerce = options?.coerce || context.coerce;
13
10
  let output = input;
14
11
  if (output != null && coerce && !Array.isArray(output))
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBigint = isBigint;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator } from '../../core/index.js';
5
2
  /**
6
3
  * Validates if value is "BigInt".
7
4
  * Converts input value to number if coerce option is set to 'true'.
8
5
  * @validator isNumber
9
6
  */
10
- function isBigint(options) {
11
- return (0, index_js_1.validator)('isBigint', (input, context, _this) => {
7
+ export function isBigint(options) {
8
+ return validator('isBigint', (input, context, _this) => {
12
9
  const coerce = options?.coerce || context.coerce;
13
10
  if (typeof input === 'bigint')
14
11
  return input;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBoolean = isBoolean;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  const TRUE_PATTERN = /^true|t|1|yes|y$/i;
6
3
  const FALSE_PATTERN = /^false|f|0|no|n$/i;
7
4
  /**
@@ -9,8 +6,8 @@ const FALSE_PATTERN = /^false|f|0|no|n$/i;
9
6
  * Converts input value to boolean if coerce option is set to 'true'.
10
7
  * @validator isBoolean
11
8
  */
12
- function isBoolean(options) {
13
- return (0, index_js_1.validator)('isBoolean', (input, context, _this) => {
9
+ export function isBoolean(options) {
10
+ return validator('isBoolean', (input, context, _this) => {
14
11
  const coerce = options?.coerce || context.coerce;
15
12
  let output = input;
16
13
  if (output != null && typeof output !== 'boolean' && coerce) {
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDate = isDate;
4
- exports.isDateString = isDateString;
5
- const date_fns_1 = require("date-fns");
6
- const index_js_1 = require("../../core/index.js");
1
+ import { formatISO, parseISO } from 'date-fns';
2
+ import { validator } from '../../core/index.js';
7
3
  /* eslint-disable-next-line max-len */ // noinspection RegExpUnnecessaryNonCapturingGroup
8
4
  const DATE_PATTERN =
9
5
  // eslint-disable-next-line max-len
@@ -13,16 +9,16 @@ const DATE_PATTERN =
13
9
  * Converts input value to Date if coerce option is set to 'true'.
14
10
  * @validator isDate
15
11
  */
16
- function isDate(options) {
12
+ export function isDate(options) {
17
13
  const precision = options?.precision;
18
- return (0, index_js_1.validator)('isDate', (input, context, _this) => {
14
+ return validator('isDate', (input, context, _this) => {
19
15
  const coerce = options?.coerce || context.coerce;
20
16
  let d;
21
17
  if (input instanceof Date)
22
18
  d = input;
23
19
  else if (input != null && coerce) {
24
20
  if (typeof input === 'string' && coerce) {
25
- d = (0, date_fns_1.parseISO)(input);
21
+ d = parseISO(input);
26
22
  }
27
23
  else if (typeof input === 'number')
28
24
  d = new Date(input);
@@ -50,15 +46,15 @@ function isDate(options) {
50
46
  * Converts input value to DFS if coerce option is set to 'true'.
51
47
  * @validator isDateString
52
48
  */
53
- function isDateString(options) {
49
+ export function isDateString(options) {
54
50
  const precision = options?.precision;
55
51
  const trim = options?.trim;
56
- return (0, index_js_1.validator)('isDateString', (input, context, _this) => {
52
+ return validator('isDateString', (input, context, _this) => {
57
53
  const coerce = options?.coerce || context.coerce;
58
54
  if (typeof input === 'string') {
59
55
  const m = DATE_PATTERN.exec(input);
60
56
  if (m) {
61
- const d = (0, date_fns_1.parseISO)(input);
57
+ const d = parseISO(input);
62
58
  if (d && !isNaN(d.getTime())) {
63
59
  if (!precision ||
64
60
  precision === 'year' ||
@@ -90,8 +86,8 @@ function isDateString(options) {
90
86
  }
91
87
  else if (input instanceof Date) {
92
88
  return trim === 'date'
93
- ? (0, date_fns_1.formatISO)(input, { representation: 'date' })
94
- : (0, date_fns_1.formatISO)(input).substring(0, 19);
89
+ ? formatISO(input, { representation: 'date' })
90
+ : formatISO(input).substring(0, 19);
95
91
  }
96
92
  context.fail(_this, `"{{value}}" is not a valid date string`, input, {
97
93
  ...options,
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEnum = isEnum;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  /**
6
3
  * Validates if given value is one of enum values.
7
4
  * @validator isEnum
8
5
  */
9
- function isEnum(values, options) {
6
+ export function isEnum(values, options) {
10
7
  const caseInSensitive = !!options?.caseInSensitive;
11
8
  const enumName = options?.enumName;
12
9
  // Prepare an object for fast lookup
@@ -17,7 +14,7 @@ function isEnum(values, options) {
17
14
  a[v] = true;
18
15
  return a;
19
16
  }, {});
20
- return (0, index_js_1.validator)('isEnum', (input, context, _this) => {
17
+ return validator('isEnum', (input, context, _this) => {
21
18
  if (input != null &&
22
19
  valObj[typeof input === 'string' && caseInSensitive
23
20
  ? input.toUpperCase()
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isInteger = isInteger;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  /**
6
3
  * Validates if value is "integer".
7
4
  * Converts input value to integer number if coerce option is set to 'true'.
8
5
  * @validator isInteger
9
6
  */
10
- function isInteger(options) {
11
- return (0, index_js_1.validator)('isInteger', (input, context, _this) => {
7
+ export function isInteger(options) {
8
+ return validator('isInteger', (input, context, _this) => {
12
9
  const coerce = options?.coerce || context.coerce;
13
10
  let output = input;
14
11
  if (output != null && typeof output !== 'number' && coerce) {
@@ -1,16 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNull = isNull;
4
- exports.isNotNull = isNotNull;
5
- exports.isNullish = isNullish;
6
- exports.isNotNullish = isNotNullish;
7
- const index_js_1 = require("../../core/index.js");
1
+ import { validator } from '../../core/index.js';
8
2
  /**
9
3
  * Validates if value is "null".
10
4
  * @validator isNull
11
5
  */
12
- function isNull(options) {
13
- return (0, index_js_1.validator)('isNull', (input, context, _this) => {
6
+ export function isNull(options) {
7
+ return validator('isNull', (input, context, _this) => {
14
8
  if (input === null)
15
9
  return input;
16
10
  context.fail(_this, `{{label}} is not null`, input);
@@ -20,8 +14,8 @@ function isNull(options) {
20
14
  * Validates if value is not "null".
21
15
  * @validator isNotNull
22
16
  */
23
- function isNotNull(options) {
24
- return (0, index_js_1.validator)('isNotNull', (input, context, _this) => {
17
+ export function isNotNull(options) {
18
+ return validator('isNotNull', (input, context, _this) => {
25
19
  if (input !== null)
26
20
  return input;
27
21
  context.fail(_this, `{{label}} is null`, input);
@@ -31,8 +25,8 @@ function isNotNull(options) {
31
25
  * Validates if value is "null" or "undefined".
32
26
  * @validator isNullish
33
27
  */
34
- function isNullish(options) {
35
- return (0, index_js_1.validator)('isNullish', (input, context, _this) => {
28
+ export function isNullish(options) {
29
+ return validator('isNullish', (input, context, _this) => {
36
30
  if (input == null)
37
31
  return input;
38
32
  context.fail(_this, `{{label}} is not nullish`, input);
@@ -42,8 +36,8 @@ function isNullish(options) {
42
36
  * Validates if value is not "null" nor "undefined".
43
37
  * @validator isNotNullish
44
38
  */
45
- function isNotNullish(options) {
46
- return (0, index_js_1.validator)('isNotNullish', (input, context, _this) => {
39
+ export function isNotNullish(options) {
40
+ return validator('isNotNullish', (input, context, _this) => {
47
41
  if (input != null)
48
42
  return input;
49
43
  if (input === null)
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNumber = isNumber;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator } from '../../core/index.js';
5
2
  /**
6
3
  * Validates if value is "number".
7
4
  * Converts input value to number if coerce option is set to 'true'.
8
5
  * @validator isNumber
9
6
  */
10
- function isNumber(options) {
11
- return (0, index_js_1.validator)('isNumber', (input, context, _this) => {
7
+ export function isNumber(options) {
8
+ return validator('isNumber', (input, context, _this) => {
12
9
  const coerce = options?.coerce || context.coerce;
13
10
  let output = input;
14
11
  if (output != null && typeof output !== 'number' && coerce) {
@@ -1,14 +1,11 @@
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");
1
+ import { postValidation, preValidation } from '../../constants.js';
2
+ import { isValidator, validator, } from '../../core/index.js';
6
3
  /**
7
4
  * Validates object according to schema
8
5
  * Converts properties according to schema rules if coerce option is set to 'true'.
9
6
  * @validator isObject
10
7
  */
11
- function isObject(schema, options) {
8
+ export function isObject(schema, options) {
12
9
  const ctor = options?.ctor;
13
10
  const ctorName = options?.name || ctor?.name;
14
11
  const additionalFields = options?.additionalFields ?? !schema;
@@ -22,13 +19,13 @@ function isObject(schema, options) {
22
19
  const n = schema[k];
23
20
  const key = caseInSensitive ? k.toLowerCase() : k;
24
21
  if (Array.isArray(n)) {
25
- if (!(0, index_js_1.isValidator)(n[0])) {
22
+ if (!isValidator(n[0])) {
26
23
  throw new TypeError(`Invalid tuple definition in validation schema (${k})`);
27
24
  }
28
25
  propertyRules[key] = n[0];
29
26
  propertyOptions[key] = { as: k, ...n[1] };
30
27
  }
31
- else if ((0, index_js_1.isValidator)(n)) {
28
+ else if (isValidator(n)) {
32
29
  propertyRules[key] = n;
33
30
  propertyOptions[key] = { as: k };
34
31
  }
@@ -36,10 +33,10 @@ function isObject(schema, options) {
36
33
  throw new TypeError(`Invalid definition in validation schema (${k})`);
37
34
  }
38
35
  }
39
- const _rule = (0, index_js_1.validator)('isObject', (input, context, _this) => {
36
+ const _rule = validator('isObject', (input, context, _this) => {
40
37
  let output = input;
41
- if (ctor && ctor[constants_js_1.preValidation]) {
42
- output = ctor[constants_js_1.preValidation](output, context, _this);
38
+ if (ctor && ctor[preValidation]) {
39
+ output = ctor[preValidation](output, context, _this);
43
40
  }
44
41
  const coerce = options?.coerce || context.coerce;
45
42
  if (typeof output === 'string' && coerce)
@@ -76,7 +73,7 @@ function isObject(schema, options) {
76
73
  v = output[inputKey];
77
74
  _propRule =
78
75
  propertyRules[schemaKey] ||
79
- ((0, index_js_1.isValidator)(additionalFields) ? additionalFields : undefined);
76
+ (isValidator(additionalFields) ? additionalFields : undefined);
80
77
  if (_propRule) {
81
78
  if (processedSchemaKeys[schemaKey])
82
79
  continue;
@@ -104,8 +101,8 @@ function isObject(schema, options) {
104
101
  }
105
102
  if (context.errors.length)
106
103
  return undefined;
107
- if (ctor && ctor[constants_js_1.postValidation]) {
108
- ctor[constants_js_1.postValidation](out, context, _this);
104
+ if (ctor && ctor[postValidation]) {
105
+ ctor[postValidation](out, context, _this);
109
106
  return out;
110
107
  }
111
108
  return out;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRecord = isRecord;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  /**
6
3
  * Validates record object according to given "key" and "value" rules
7
4
  * Converts properties according to rules if coerce option is set to 'true'.
8
5
  * @validator isRecord
9
6
  */
10
- function isRecord(keyRule, valueRule, options) {
11
- return (0, index_js_1.validator)('isRecord', (input, context, _this) => {
7
+ export function isRecord(keyRule, valueRule, options) {
8
+ return validator('isRecord', (input, context, _this) => {
12
9
  if (!(input && typeof input === 'object')) {
13
10
  context.fail(_this, `{{label}} must be an object`, input);
14
11
  return;
@@ -1,18 +1,11 @@
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");
1
+ import { validator, } from '../../core/index.js';
9
2
  /**
10
3
  * Validates if value is "string".
11
4
  * Converts input value to string if coerce option is set to 'true'.
12
5
  * @validator isString
13
6
  */
14
- function isString(options) {
15
- return (0, index_js_1.validator)('isString', (input, context, _this) => {
7
+ export function isString(options) {
8
+ return validator('isString', (input, context, _this) => {
16
9
  const coerce = options?.coerce || context.coerce;
17
10
  let output = input;
18
11
  if (output != null && typeof output !== 'string' && coerce) {
@@ -30,15 +23,15 @@ function isString(options) {
30
23
  context.fail(_this, `"{{value}}" is not a string`, input);
31
24
  }, options);
32
25
  }
33
- function stringReplace(searchValue, replacer) {
34
- return (0, index_js_1.validator)('stringReplace', (input) => {
26
+ export function stringReplace(searchValue, replacer) {
27
+ return validator('stringReplace', (input) => {
35
28
  if (input == null)
36
29
  return input;
37
30
  return String(input).replace(searchValue, replacer);
38
31
  });
39
32
  }
40
- function stringSplit(splitter, limit) {
41
- return (0, index_js_1.validator)('stringSplit', (input) => {
33
+ export function stringSplit(splitter, limit) {
34
+ return validator('stringSplit', (input) => {
42
35
  if (input == null)
43
36
  return input;
44
37
  return String(input).split(splitter, limit);
@@ -48,8 +41,8 @@ function stringSplit(splitter, limit) {
48
41
  * Removes whitespace from both ends of a string
49
42
  * @validator trim
50
43
  */
51
- function trim() {
52
- return (0, index_js_1.validator)('trim', (input) => {
44
+ export function trim() {
45
+ return validator('trim', (input) => {
53
46
  if (input == null)
54
47
  return input;
55
48
  return String(input).trim();
@@ -60,9 +53,8 @@ function trim() {
60
53
  * Removes whitespace from the end of a string
61
54
  * @validator trimEnd
62
55
  */
63
- const trimEnd = () => trimEndRule;
64
- exports.trimEnd = trimEnd;
65
- const trimEndRule = (0, index_js_1.validator)('trimEnd', (input) => {
56
+ export const trimEnd = () => trimEndRule;
57
+ const trimEndRule = validator('trimEnd', (input) => {
66
58
  if (input == null)
67
59
  return input;
68
60
  return String(input).trimEnd();
@@ -72,9 +64,8 @@ const trimEndRule = (0, index_js_1.validator)('trimEnd', (input) => {
72
64
  * Removes whitespace from the beginning of a string
73
65
  * @validator trimStart
74
66
  */
75
- const trimStart = () => trimStartRule;
76
- exports.trimStart = trimStart;
77
- const trimStartRule = (0, index_js_1.validator)('trimStart', (input) => {
67
+ export const trimStart = () => trimStartRule;
68
+ const trimStartRule = validator('trimStart', (input) => {
78
69
  if (input == null)
79
70
  return input;
80
71
  return String(input).trimStart();
@@ -1,9 +1,6 @@
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) => {
1
+ import { validator, } from '../../core/index.js';
2
+ export function isTuple(items, options) {
3
+ return validator('isTuple', (input, context, _this) => {
7
4
  const coerce = options?.coerce || context.coerce;
8
5
  let output = input;
9
6
  if (output != null && coerce && !Array.isArray(output))
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUndefined = isUndefined;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  /**
6
3
  * Validates if value is "undefined"
7
4
  * @validator isUndefined
8
5
  */
9
- function isUndefined(options) {
10
- return (0, index_js_1.validator)('isUndefined', (input, context, _this) => {
6
+ export function isUndefined(options) {
7
+ return validator('isUndefined', (input, context, _this) => {
11
8
  if (options?.coerce || context.coerce)
12
9
  return undefined;
13
10
  if (input === undefined)
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exists = exists;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator } from '../../core/index.js';
5
2
  /**
6
3
  * Validates if property exists
7
4
  * @validator exists
8
5
  */
9
- function exists(options) {
10
- return (0, index_js_1.validator)('exists', (input, context, _this) => {
6
+ export function exists(options) {
7
+ return validator('exists', (input, context, _this) => {
11
8
  if (input !== undefined ||
12
9
  (context.scope &&
13
10
  Object.getOwnPropertyDescriptor(context.scope, input))) {
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLength = getLength;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator } from '../../core/index.js';
5
2
  /**
6
3
  * Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
7
4
  * @validator getLength
8
5
  */
9
- function getLength() {
10
- return (0, index_js_1.validator)('getLength', (input, context, _this) => {
6
+ export function getLength() {
7
+ return validator('getLength', (input, context, _this) => {
11
8
  if (typeof input === 'string')
12
9
  return input.length;
13
10
  if (Array.isArray(input))
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optional = optional;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  /**
6
3
  * Makes sub-rule optional
7
4
  * @validator optional
8
5
  */
9
- function optional(nested, options) {
10
- return (0, index_js_1.validator)('optional', (input, context) => {
6
+ export function optional(nested, options) {
7
+ return validator('optional', (input, context) => {
11
8
  if (input == null)
12
9
  return input;
13
10
  return nested(input, context);
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pipe = pipe;
4
- exports.allOf = allOf;
5
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
6
2
  /**
7
3
  *
8
4
  * @validator pipe
9
5
  */
10
- function pipe(rules, options) {
6
+ export function pipe(rules, options) {
11
7
  const l = rules.length;
12
8
  const returnIndex = options?.returnIndex;
13
- return (0, index_js_1.validator)('pipe', (input, context) => {
9
+ return validator('pipe', (input, context) => {
14
10
  let i;
15
11
  let c;
16
12
  let v = input;
@@ -30,8 +26,8 @@ function pipe(rules, options) {
30
26
  * Test given value against to all codecs and returns original input
31
27
  * @validator allOf
32
28
  */
33
- function allOf(rules) {
34
- return (0, index_js_1.validator)('allOf', (input, context) => {
29
+ export function allOf(rules) {
30
+ return validator('allOf', (input, context) => {
35
31
  let i;
36
32
  let c;
37
33
  const l = rules.length;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.required = required;
4
- const index_js_1 = require("../../core/index.js");
1
+ import { validator, } from '../../core/index.js';
5
2
  /**
6
3
  * Makes sub-rule required
7
4
  * @validator required
8
5
  */
9
- function required(nested, options) {
10
- return (0, index_js_1.validator)('required', (input, context, _this) => {
6
+ export function required(nested, options) {
7
+ return validator('required', (input, context, _this) => {
11
8
  if (input == null) {
12
9
  context.fail(_this, `{{label}} is required`, input);
13
10
  return;