valgen 5.5.0 → 5.7.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 (163) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/cjs/core/index.js +7 -20
  3. package/cjs/factories.js +2 -15
  4. package/cjs/index.js +10 -31
  5. package/cjs/rules/format-rules/is-alpha.js +2 -24
  6. package/cjs/rules/format-rules/is-ascii.js +2 -24
  7. package/cjs/rules/format-rules/is-base64.js +2 -24
  8. package/cjs/rules/format-rules/is-btc-address.js +2 -24
  9. package/cjs/rules/format-rules/is-credit-card.js +2 -24
  10. package/cjs/rules/format-rules/is-decimal.js +2 -24
  11. package/cjs/rules/format-rules/is-ean.js +2 -24
  12. package/cjs/rules/format-rules/is-email.js +2 -24
  13. package/cjs/rules/format-rules/is-eth-address.js +2 -24
  14. package/cjs/rules/format-rules/is-fqdn.js +2 -24
  15. package/cjs/rules/format-rules/is-hash.js +2 -24
  16. package/cjs/rules/format-rules/is-hex-color.js +2 -24
  17. package/cjs/rules/format-rules/is-hex.js +2 -24
  18. package/cjs/rules/format-rules/is-iban.js +2 -24
  19. package/cjs/rules/format-rules/is-ip.js +2 -24
  20. package/cjs/rules/format-rules/is-issn.js +2 -24
  21. package/cjs/rules/format-rules/is-jwt.js +2 -24
  22. package/cjs/rules/format-rules/is-lowercase.js +2 -24
  23. package/cjs/rules/format-rules/is-mac-address.js +2 -24
  24. package/cjs/rules/format-rules/is-mobile-phone.js +2 -24
  25. package/cjs/rules/format-rules/is-object-id.js +2 -4
  26. package/cjs/rules/format-rules/is-passport-number.js +2 -24
  27. package/cjs/rules/format-rules/is-port.js +2 -24
  28. package/cjs/rules/format-rules/is-url.js +2 -24
  29. package/cjs/rules/format-rules/is-uuid.js +2 -24
  30. package/cjs/rules/format-rules/is-vat-number.js +2 -24
  31. package/cjs/rules/index.js +51 -64
  32. package/cjs/rules/type-rules/is-null.js +30 -3
  33. package/esm/constants.js +5 -2
  34. package/esm/core/constants.js +5 -2
  35. package/esm/core/context.js +9 -5
  36. package/esm/core/index.js +9 -6
  37. package/esm/core/types.js +2 -1
  38. package/esm/core/utilities.js +10 -6
  39. package/esm/core/validation-error.js +5 -1
  40. package/esm/core/validator.js +18 -14
  41. package/esm/factories.js +4 -1
  42. package/esm/helpers/object.utils.js +6 -2
  43. package/esm/helpers/omit-undefined.js +4 -1
  44. package/esm/helpers/string.utils.js +4 -1
  45. package/esm/index.js +69 -4
  46. package/esm/rules/format-rules/is-alpha.js +11 -6
  47. package/esm/rules/format-rules/is-ascii.js +8 -4
  48. package/esm/rules/format-rules/is-base64.js +8 -4
  49. package/esm/rules/format-rules/is-btc-address.js +8 -4
  50. package/esm/rules/format-rules/is-credit-card.js +8 -4
  51. package/esm/rules/format-rules/is-decimal.js +8 -4
  52. package/esm/rules/format-rules/is-ean.js +8 -4
  53. package/esm/rules/format-rules/is-email.js +8 -4
  54. package/esm/rules/format-rules/is-eth-address.js +8 -4
  55. package/esm/rules/format-rules/is-fqdn.js +8 -4
  56. package/esm/rules/format-rules/is-hash.js +8 -4
  57. package/esm/rules/format-rules/is-hex-color.js +8 -4
  58. package/esm/rules/format-rules/is-hex.js +8 -4
  59. package/esm/rules/format-rules/is-iban.js +11 -6
  60. package/esm/rules/format-rules/is-ip.js +11 -6
  61. package/esm/rules/format-rules/is-issn.js +8 -4
  62. package/esm/rules/format-rules/is-jwt.js +8 -4
  63. package/esm/rules/format-rules/is-lowercase.js +11 -6
  64. package/esm/rules/format-rules/is-mac-address.js +8 -4
  65. package/esm/rules/format-rules/is-mobile-phone.js +8 -4
  66. package/esm/rules/format-rules/is-object-id.js +9 -5
  67. package/esm/rules/format-rules/is-passport-number.js +8 -4
  68. package/esm/rules/format-rules/is-port.js +8 -4
  69. package/esm/rules/format-rules/is-url.js +8 -4
  70. package/esm/rules/format-rules/is-uuid.js +8 -4
  71. package/esm/rules/format-rules/is-vat-number.js +8 -4
  72. package/esm/rules/format-rules/matches.js +6 -3
  73. package/esm/rules/index.js +53 -50
  74. package/esm/rules/logical-rules/is-defined.js +6 -3
  75. package/esm/rules/logical-rules/is-empty.js +9 -5
  76. package/esm/rules/logical-rules/range.js +29 -19
  77. package/esm/rules/type-rules/is-any.js +6 -2
  78. package/esm/rules/type-rules/is-array.js +6 -3
  79. package/esm/rules/type-rules/is-bigint.js +6 -3
  80. package/esm/rules/type-rules/is-boolean.js +6 -3
  81. package/esm/rules/type-rules/is-date.js +14 -10
  82. package/esm/rules/type-rules/is-enum.js +6 -3
  83. package/esm/rules/type-rules/is-integer.js +6 -3
  84. package/esm/rules/type-rules/is-null.js +39 -8
  85. package/esm/rules/type-rules/is-number.js +6 -3
  86. package/esm/rules/type-rules/is-object.js +14 -11
  87. package/esm/rules/type-rules/is-record.js +6 -3
  88. package/esm/rules/type-rules/is-string.js +22 -13
  89. package/esm/rules/type-rules/is-tuple.js +6 -3
  90. package/esm/rules/type-rules/is-undefined.js +6 -3
  91. package/esm/rules/utility-rules/exists.js +6 -3
  92. package/esm/rules/utility-rules/get-length.js +6 -3
  93. package/esm/rules/utility-rules/optional.js +6 -3
  94. package/esm/rules/utility-rules/pipe.js +9 -5
  95. package/esm/rules/utility-rules/required.js +6 -3
  96. package/esm/rules/utility-rules/union.js +6 -3
  97. package/package.json +16 -16
  98. package/{typings → types}/index.d.ts +3 -1
  99. package/types/rules/type-rules/is-null.d.ts +21 -0
  100. package/cjs/package.json +0 -3
  101. package/typings/rules/type-rules/is-null.d.ts +0 -11
  102. /package/{typings → types}/constants.d.ts +0 -0
  103. /package/{typings → types}/core/constants.d.ts +0 -0
  104. /package/{typings → types}/core/context.d.ts +0 -0
  105. /package/{typings → types}/core/index.d.ts +0 -0
  106. /package/{typings → types}/core/types.d.ts +0 -0
  107. /package/{typings → types}/core/utilities.d.ts +0 -0
  108. /package/{typings → types}/core/validation-error.d.ts +0 -0
  109. /package/{typings → types}/core/validator.d.ts +0 -0
  110. /package/{typings → types}/factories.d.ts +0 -0
  111. /package/{typings → types}/helpers/object.utils.d.ts +0 -0
  112. /package/{typings → types}/helpers/omit-undefined.d.ts +0 -0
  113. /package/{typings → types}/helpers/string.utils.d.ts +0 -0
  114. /package/{typings → types}/rules/format-rules/is-alpha.d.ts +0 -0
  115. /package/{typings → types}/rules/format-rules/is-ascii.d.ts +0 -0
  116. /package/{typings → types}/rules/format-rules/is-base64.d.ts +0 -0
  117. /package/{typings → types}/rules/format-rules/is-btc-address.d.ts +0 -0
  118. /package/{typings → types}/rules/format-rules/is-credit-card.d.ts +0 -0
  119. /package/{typings → types}/rules/format-rules/is-decimal.d.ts +0 -0
  120. /package/{typings → types}/rules/format-rules/is-ean.d.ts +0 -0
  121. /package/{typings → types}/rules/format-rules/is-email.d.ts +0 -0
  122. /package/{typings → types}/rules/format-rules/is-eth-address.d.ts +0 -0
  123. /package/{typings → types}/rules/format-rules/is-fqdn.d.ts +0 -0
  124. /package/{typings → types}/rules/format-rules/is-hash.d.ts +0 -0
  125. /package/{typings → types}/rules/format-rules/is-hex-color.d.ts +0 -0
  126. /package/{typings → types}/rules/format-rules/is-hex.d.ts +0 -0
  127. /package/{typings → types}/rules/format-rules/is-iban.d.ts +0 -0
  128. /package/{typings → types}/rules/format-rules/is-ip.d.ts +0 -0
  129. /package/{typings → types}/rules/format-rules/is-issn.d.ts +0 -0
  130. /package/{typings → types}/rules/format-rules/is-jwt.d.ts +0 -0
  131. /package/{typings → types}/rules/format-rules/is-lowercase.d.ts +0 -0
  132. /package/{typings → types}/rules/format-rules/is-mac-address.d.ts +0 -0
  133. /package/{typings → types}/rules/format-rules/is-mobile-phone.d.ts +0 -0
  134. /package/{typings → types}/rules/format-rules/is-object-id.d.ts +0 -0
  135. /package/{typings → types}/rules/format-rules/is-passport-number.d.ts +0 -0
  136. /package/{typings → types}/rules/format-rules/is-port.d.ts +0 -0
  137. /package/{typings → types}/rules/format-rules/is-url.d.ts +0 -0
  138. /package/{typings → types}/rules/format-rules/is-uuid.d.ts +0 -0
  139. /package/{typings → types}/rules/format-rules/is-vat-number.d.ts +0 -0
  140. /package/{typings → types}/rules/format-rules/matches.d.ts +0 -0
  141. /package/{typings → types}/rules/index.d.ts +0 -0
  142. /package/{typings → types}/rules/logical-rules/is-defined.d.ts +0 -0
  143. /package/{typings → types}/rules/logical-rules/is-empty.d.ts +0 -0
  144. /package/{typings → types}/rules/logical-rules/range.d.ts +0 -0
  145. /package/{typings → types}/rules/type-rules/is-any.d.ts +0 -0
  146. /package/{typings → types}/rules/type-rules/is-array.d.ts +0 -0
  147. /package/{typings → types}/rules/type-rules/is-bigint.d.ts +0 -0
  148. /package/{typings → types}/rules/type-rules/is-boolean.d.ts +0 -0
  149. /package/{typings → types}/rules/type-rules/is-date.d.ts +0 -0
  150. /package/{typings → types}/rules/type-rules/is-enum.d.ts +0 -0
  151. /package/{typings → types}/rules/type-rules/is-integer.d.ts +0 -0
  152. /package/{typings → types}/rules/type-rules/is-number.d.ts +0 -0
  153. /package/{typings → types}/rules/type-rules/is-object.d.ts +0 -0
  154. /package/{typings → types}/rules/type-rules/is-record.d.ts +0 -0
  155. /package/{typings → types}/rules/type-rules/is-string.d.ts +0 -0
  156. /package/{typings → types}/rules/type-rules/is-tuple.d.ts +0 -0
  157. /package/{typings → types}/rules/type-rules/is-undefined.d.ts +0 -0
  158. /package/{typings → types}/rules/utility-rules/exists.d.ts +0 -0
  159. /package/{typings → types}/rules/utility-rules/get-length.d.ts +0 -0
  160. /package/{typings → types}/rules/utility-rules/optional.d.ts +0 -0
  161. /package/{typings → types}/rules/utility-rules/pipe.d.ts +0 -0
  162. /package/{typings → types}/rules/utility-rules/required.d.ts +0 -0
  163. /package/{typings → types}/rules/utility-rules/union.d.ts +0 -0
@@ -1,5 +1,9 @@
1
- import { formatISO, parseISO } from 'date-fns';
2
- import { validator } from '../../core/index.js';
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");
3
7
  /* eslint-disable-next-line max-len */ // noinspection RegExpUnnecessaryNonCapturingGroup
4
8
  const DATE_PATTERN =
5
9
  // eslint-disable-next-line max-len
@@ -9,16 +13,16 @@ const DATE_PATTERN =
9
13
  * Converts input value to Date if coerce option is set to 'true'.
10
14
  * @validator isDate
11
15
  */
12
- export function isDate(options) {
16
+ function isDate(options) {
13
17
  const precision = options?.precision;
14
- return validator('isDate', (input, context, _this) => {
18
+ return (0, index_js_1.validator)('isDate', (input, context, _this) => {
15
19
  const coerce = options?.coerce || context.coerce;
16
20
  let d;
17
21
  if (input instanceof Date)
18
22
  d = input;
19
23
  else if (input != null && coerce) {
20
24
  if (typeof input === 'string' && coerce) {
21
- d = parseISO(input);
25
+ d = (0, date_fns_1.parseISO)(input);
22
26
  }
23
27
  else if (typeof input === 'number')
24
28
  d = new Date(input);
@@ -46,15 +50,15 @@ export function isDate(options) {
46
50
  * Converts input value to DFS if coerce option is set to 'true'.
47
51
  * @validator isDateString
48
52
  */
49
- export function isDateString(options) {
53
+ function isDateString(options) {
50
54
  const precision = options?.precision;
51
55
  const trim = options?.trim;
52
- return validator('isDateString', (input, context, _this) => {
56
+ return (0, index_js_1.validator)('isDateString', (input, context, _this) => {
53
57
  const coerce = options?.coerce || context.coerce;
54
58
  if (typeof input === 'string') {
55
59
  const m = DATE_PATTERN.exec(input);
56
60
  if (m) {
57
- const d = parseISO(input);
61
+ const d = (0, date_fns_1.parseISO)(input);
58
62
  if (d && !isNaN(d.getTime())) {
59
63
  if (!precision ||
60
64
  precision === 'year' ||
@@ -86,8 +90,8 @@ export function isDateString(options) {
86
90
  }
87
91
  else if (input instanceof Date) {
88
92
  return trim === 'date'
89
- ? formatISO(input, { representation: 'date' })
90
- : formatISO(input).substring(0, 19);
93
+ ? (0, date_fns_1.formatISO)(input, { representation: 'date' })
94
+ : (0, date_fns_1.formatISO)(input).substring(0, 19);
91
95
  }
92
96
  context.fail(_this, `"{{value}}" is not a valid date string`, input, {
93
97
  ...options,
@@ -1,9 +1,12 @@
1
- import { validator, } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEnum = isEnum;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Validates if given value is one of enum values.
4
7
  * @validator isEnum
5
8
  */
6
- export function isEnum(values, options) {
9
+ function isEnum(values, options) {
7
10
  const caseInSensitive = !!options?.caseInSensitive;
8
11
  const enumName = options?.enumName;
9
12
  // Prepare an object for fast lookup
@@ -14,7 +17,7 @@ export function isEnum(values, options) {
14
17
  a[v] = true;
15
18
  return a;
16
19
  }, {});
17
- return validator('isEnum', (input, context, _this) => {
20
+ return (0, index_js_1.validator)('isEnum', (input, context, _this) => {
18
21
  if (input != null &&
19
22
  valObj[typeof input === 'string' && caseInSensitive
20
23
  ? input.toUpperCase()
@@ -1,11 +1,14 @@
1
- import { validator, } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isInteger = isInteger;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Validates if value is "integer".
4
7
  * Converts input value to integer number if coerce option is set to 'true'.
5
8
  * @validator isInteger
6
9
  */
7
- export function isInteger(options) {
8
- return validator('isInteger', (input, context, _this) => {
10
+ function isInteger(options) {
11
+ return (0, index_js_1.validator)('isInteger', (input, context, _this) => {
9
12
  const coerce = options?.coerce || context.coerce;
10
13
  let output = input;
11
14
  if (output != null && typeof output !== 'number' && coerce) {
@@ -1,23 +1,54 @@
1
- import { validator } from '../../core/index.js';
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");
2
8
  /**
3
9
  * Validates if value is "null".
4
10
  * @validator isNull
5
11
  */
6
- export function isNull(options) {
7
- return validator('isNull', (input, context, _this) => {
12
+ function isNull(options) {
13
+ return (0, index_js_1.validator)('isNull', (input, context, _this) => {
8
14
  if (input === null)
9
15
  return input;
10
- context.fail(_this, `"{{value}}" is not null`, input);
16
+ context.fail(_this, `{{label}} is not null`, input);
17
+ }, options);
18
+ }
19
+ /**
20
+ * Validates if value is not "null".
21
+ * @validator isNotNull
22
+ */
23
+ function isNotNull(options) {
24
+ return (0, index_js_1.validator)('isNotNull', (input, context, _this) => {
25
+ if (input !== null)
26
+ return input;
27
+ context.fail(_this, `{{label}} is null`, input);
11
28
  }, options);
12
29
  }
13
30
  /**
14
31
  * Validates if value is "null" or "undefined".
15
- * @validator isNull
32
+ * @validator isNullish
16
33
  */
17
- export function isNullish(options) {
18
- return validator('isNullish', (input, context, _this) => {
34
+ function isNullish(options) {
35
+ return (0, index_js_1.validator)('isNullish', (input, context, _this) => {
19
36
  if (input == null)
20
37
  return input;
21
- context.fail(_this, `"{{value}}" is not nullish`, input);
38
+ context.fail(_this, `{{label}} is not nullish`, input);
39
+ }, options);
40
+ }
41
+ /**
42
+ * Validates if value is not "null" nor "undefined".
43
+ * @validator isNotNullish
44
+ */
45
+ function isNotNullish(options) {
46
+ return (0, index_js_1.validator)('isNotNullish', (input, context, _this) => {
47
+ if (input != null)
48
+ return input;
49
+ if (input === null)
50
+ context.fail(_this, `{{label}} is null`, input);
51
+ else
52
+ context.fail(_this, `{{label}} is undefined`, input);
22
53
  }, options);
23
54
  }
@@ -1,11 +1,14 @@
1
- import { validator } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNumber = isNumber;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Validates if value is "number".
4
7
  * Converts input value to number if coerce option is set to 'true'.
5
8
  * @validator isNumber
6
9
  */
7
- export function isNumber(options) {
8
- return validator('isNumber', (input, context, _this) => {
10
+ function isNumber(options) {
11
+ return (0, index_js_1.validator)('isNumber', (input, context, _this) => {
9
12
  const coerce = options?.coerce || context.coerce;
10
13
  let output = input;
11
14
  if (output != null && typeof output !== 'number' && coerce) {
@@ -1,11 +1,14 @@
1
- import { postValidation, preValidation } from '../../constants.js';
2
- import { isValidator, validator, } from '../../core/index.js';
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");
3
6
  /**
4
7
  * Validates object according to schema
5
8
  * Converts properties according to schema rules if coerce option is set to 'true'.
6
9
  * @validator isObject
7
10
  */
8
- export function isObject(schema, options) {
11
+ function isObject(schema, options) {
9
12
  const ctor = options?.ctor;
10
13
  const ctorName = options?.name || ctor?.name;
11
14
  const additionalFields = options?.additionalFields ?? !schema;
@@ -19,13 +22,13 @@ export function isObject(schema, options) {
19
22
  const n = schema[k];
20
23
  const key = caseInSensitive ? k.toLowerCase() : k;
21
24
  if (Array.isArray(n)) {
22
- if (!isValidator(n[0])) {
25
+ if (!(0, index_js_1.isValidator)(n[0])) {
23
26
  throw new TypeError(`Invalid tuple definition in validation schema (${k})`);
24
27
  }
25
28
  propertyRules[key] = n[0];
26
29
  propertyOptions[key] = { as: k, ...n[1] };
27
30
  }
28
- else if (isValidator(n)) {
31
+ else if ((0, index_js_1.isValidator)(n)) {
29
32
  propertyRules[key] = n;
30
33
  propertyOptions[key] = { as: k };
31
34
  }
@@ -33,10 +36,10 @@ export function isObject(schema, options) {
33
36
  throw new TypeError(`Invalid definition in validation schema (${k})`);
34
37
  }
35
38
  }
36
- const _rule = validator('isObject', (input, context, _this) => {
39
+ const _rule = (0, index_js_1.validator)('isObject', (input, context, _this) => {
37
40
  let output = input;
38
- if (ctor && ctor[preValidation]) {
39
- output = ctor[preValidation](output, context, _this);
41
+ if (ctor && ctor[constants_js_1.preValidation]) {
42
+ output = ctor[constants_js_1.preValidation](output, context, _this);
40
43
  }
41
44
  const coerce = options?.coerce || context.coerce;
42
45
  if (typeof output === 'string' && coerce)
@@ -73,7 +76,7 @@ export function isObject(schema, options) {
73
76
  v = output[inputKey];
74
77
  _propRule =
75
78
  propertyRules[schemaKey] ||
76
- (isValidator(additionalFields) ? additionalFields : undefined);
79
+ ((0, index_js_1.isValidator)(additionalFields) ? additionalFields : undefined);
77
80
  if (_propRule) {
78
81
  if (processedSchemaKeys[schemaKey])
79
82
  continue;
@@ -101,8 +104,8 @@ export function isObject(schema, options) {
101
104
  }
102
105
  if (context.errors.length)
103
106
  return undefined;
104
- if (ctor && ctor[postValidation]) {
105
- ctor[postValidation](out, context, _this);
107
+ if (ctor && ctor[constants_js_1.postValidation]) {
108
+ ctor[constants_js_1.postValidation](out, context, _this);
106
109
  return out;
107
110
  }
108
111
  return out;
@@ -1,11 +1,14 @@
1
- import { validator, } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRecord = isRecord;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Validates record object according to given "key" and "value" rules
4
7
  * Converts properties according to rules if coerce option is set to 'true'.
5
8
  * @validator isRecord
6
9
  */
7
- export function isRecord(keyRule, valueRule, options) {
8
- return validator('isRecord', (input, context, _this) => {
10
+ function isRecord(keyRule, valueRule, options) {
11
+ return (0, index_js_1.validator)('isRecord', (input, context, _this) => {
9
12
  if (!(input && typeof input === 'object')) {
10
13
  context.fail(_this, `{{label}} must be an object`, input);
11
14
  return;
@@ -1,11 +1,18 @@
1
- import { validator, } from '../../core/index.js';
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");
2
9
  /**
3
10
  * Validates if value is "string".
4
11
  * Converts input value to string if coerce option is set to 'true'.
5
12
  * @validator isString
6
13
  */
7
- export function isString(options) {
8
- return validator('isString', (input, context, _this) => {
14
+ function isString(options) {
15
+ return (0, index_js_1.validator)('isString', (input, context, _this) => {
9
16
  const coerce = options?.coerce || context.coerce;
10
17
  let output = input;
11
18
  if (output != null && typeof output !== 'string' && coerce) {
@@ -23,15 +30,15 @@ export function isString(options) {
23
30
  context.fail(_this, `"{{value}}" is not a string`, input);
24
31
  }, options);
25
32
  }
26
- export function stringReplace(searchValue, replacer) {
27
- return validator('stringReplace', (input) => {
33
+ function stringReplace(searchValue, replacer) {
34
+ return (0, index_js_1.validator)('stringReplace', (input) => {
28
35
  if (input == null)
29
36
  return input;
30
37
  return String(input).replace(searchValue, replacer);
31
38
  });
32
39
  }
33
- export function stringSplit(splitter, limit) {
34
- return validator('stringSplit', (input) => {
40
+ function stringSplit(splitter, limit) {
41
+ return (0, index_js_1.validator)('stringSplit', (input) => {
35
42
  if (input == null)
36
43
  return input;
37
44
  return String(input).split(splitter, limit);
@@ -41,8 +48,8 @@ export function stringSplit(splitter, limit) {
41
48
  * Removes whitespace from both ends of a string
42
49
  * @validator trim
43
50
  */
44
- export function trim() {
45
- return validator('trim', (input) => {
51
+ function trim() {
52
+ return (0, index_js_1.validator)('trim', (input) => {
46
53
  if (input == null)
47
54
  return input;
48
55
  return String(input).trim();
@@ -53,8 +60,9 @@ export function trim() {
53
60
  * Removes whitespace from the end of a string
54
61
  * @validator trimEnd
55
62
  */
56
- export const trimEnd = () => trimEndRule;
57
- const trimEndRule = validator('trimEnd', (input) => {
63
+ const trimEnd = () => trimEndRule;
64
+ exports.trimEnd = trimEnd;
65
+ const trimEndRule = (0, index_js_1.validator)('trimEnd', (input) => {
58
66
  if (input == null)
59
67
  return input;
60
68
  return String(input).trimEnd();
@@ -64,8 +72,9 @@ const trimEndRule = validator('trimEnd', (input) => {
64
72
  * Removes whitespace from the beginning of a string
65
73
  * @validator trimStart
66
74
  */
67
- export const trimStart = () => trimStartRule;
68
- const trimStartRule = validator('trimStart', (input) => {
75
+ const trimStart = () => trimStartRule;
76
+ exports.trimStart = trimStart;
77
+ const trimStartRule = (0, index_js_1.validator)('trimStart', (input) => {
69
78
  if (input == null)
70
79
  return input;
71
80
  return String(input).trimStart();
@@ -1,6 +1,9 @@
1
- import { validator, } from '../../core/index.js';
2
- export function isTuple(items, options) {
3
- return validator('isTuple', (input, context, _this) => {
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) => {
4
7
  const coerce = options?.coerce || context.coerce;
5
8
  let output = input;
6
9
  if (output != null && coerce && !Array.isArray(output))
@@ -1,10 +1,13 @@
1
- import { validator, } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUndefined = isUndefined;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Validates if value is "undefined"
4
7
  * @validator isUndefined
5
8
  */
6
- export function isUndefined(options) {
7
- return validator('isUndefined', (input, context, _this) => {
9
+ function isUndefined(options) {
10
+ return (0, index_js_1.validator)('isUndefined', (input, context, _this) => {
8
11
  if (options?.coerce || context.coerce)
9
12
  return undefined;
10
13
  if (input === undefined)
@@ -1,10 +1,13 @@
1
- import { validator } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exists = exists;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Validates if property exists
4
7
  * @validator exists
5
8
  */
6
- export function exists(options) {
7
- return validator('exists', (input, context, _this) => {
9
+ function exists(options) {
10
+ return (0, index_js_1.validator)('exists', (input, context, _this) => {
8
11
  if (input !== undefined ||
9
12
  (context.scope &&
10
13
  Object.getOwnPropertyDescriptor(context.scope, input))) {
@@ -1,10 +1,13 @@
1
- import { validator } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLength = getLength;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Returns length of an Array, String, ArrayBuffer, Buffer or any object with the "length" property.
4
7
  * @validator getLength
5
8
  */
6
- export function getLength() {
7
- return validator('getLength', (input, context, _this) => {
9
+ function getLength() {
10
+ return (0, index_js_1.validator)('getLength', (input, context, _this) => {
8
11
  if (typeof input === 'string')
9
12
  return input.length;
10
13
  if (Array.isArray(input))
@@ -1,10 +1,13 @@
1
- import { validator, } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.optional = optional;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Makes sub-rule optional
4
7
  * @validator optional
5
8
  */
6
- export function optional(nested, options) {
7
- return validator('optional', (input, context) => {
9
+ function optional(nested, options) {
10
+ return (0, index_js_1.validator)('optional', (input, context) => {
8
11
  if (input == null)
9
12
  return input;
10
13
  return nested(input, context);
@@ -1,12 +1,16 @@
1
- import { validator, } from '../../core/index.js';
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");
2
6
  /**
3
7
  *
4
8
  * @validator pipe
5
9
  */
6
- export function pipe(rules, options) {
10
+ function pipe(rules, options) {
7
11
  const l = rules.length;
8
12
  const returnIndex = options?.returnIndex;
9
- return validator('pipe', (input, context) => {
13
+ return (0, index_js_1.validator)('pipe', (input, context) => {
10
14
  let i;
11
15
  let c;
12
16
  let v = input;
@@ -26,8 +30,8 @@ export function pipe(rules, options) {
26
30
  * Test given value against to all codecs and returns original input
27
31
  * @validator allOf
28
32
  */
29
- export function allOf(rules) {
30
- return validator('allOf', (input, context) => {
33
+ function allOf(rules) {
34
+ return (0, index_js_1.validator)('allOf', (input, context) => {
31
35
  let i;
32
36
  let c;
33
37
  const l = rules.length;
@@ -1,10 +1,13 @@
1
- import { validator, } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.required = required;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  * Makes sub-rule required
4
7
  * @validator required
5
8
  */
6
- export function required(nested, options) {
7
- return validator('required', (input, context, _this) => {
9
+ function required(nested, options) {
10
+ return (0, index_js_1.validator)('required', (input, context, _this) => {
8
11
  if (input == null) {
9
12
  context.fail(_this, `{{label}} is required`, input);
10
13
  return;
@@ -1,10 +1,13 @@
1
- import { validator } from '../../core/index.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.union = union;
4
+ const index_js_1 = require("../../core/index.js");
2
5
  /**
3
6
  *
4
7
  */
5
- export function union(codecs) {
8
+ function union(codecs) {
6
9
  const l = codecs.length;
7
- return validator('union', (input, context, _this) => {
10
+ return (0, index_js_1.validator)('union', (input, context, _this) => {
8
11
  let i;
9
12
  let c;
10
13
  let v;
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
1
  {
2
2
  "name": "valgen",
3
3
  "description": "Fast runtime type validator, converter and io (encoding/decoding) library",
4
- "version": "5.5.0",
4
+ "version": "5.7.0",
5
5
  "author": "Panates",
6
- "contributors": [
7
- "Eray Hanoglu <e.hanoglu@panates.com>"
8
- ],
9
6
  "license": "MIT",
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/panates/valgen.git"
13
- },
14
7
  "dependencies": {
15
8
  "@types/validator": "^13.12.0",
16
9
  "date-fns": "^3.6.0",
17
- "ts-gems": "^3.4.0",
10
+ "ts-gems": "^3.5.0",
18
11
  "validator": "^13.12.0"
19
12
  },
20
- "type": "module",
21
- "types": "typings/index.d.ts",
13
+ "main": "./cjs/index.js",
14
+ "module": "./esm/index.js",
15
+ "types": "./types/index.d.ts",
22
16
  "exports": {
23
17
  ".": {
24
18
  "require": "./cjs/index.js",
25
- "default": "./esm/index.js"
26
- },
27
- "./cjs": "./cjs/index.js",
28
- "./esm": "./esm/index.js"
19
+ "import": "./esm/index.js",
20
+ "types": "./types/index.d.ts"
21
+ }
22
+ },
23
+ "contributors": [
24
+ "Eray Hanoglu <e.hanoglu@panates.com>"
25
+ ],
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/panates/valgen.git"
29
29
  },
30
30
  "engines": {
31
31
  "node": ">= 16.0"
@@ -33,7 +33,7 @@
33
33
  "files": [
34
34
  "cjs/",
35
35
  "esm/",
36
- "typings/",
36
+ "types/",
37
37
  "LICENSE",
38
38
  "README.md",
39
39
  "CHANGELOG.md"
@@ -12,7 +12,9 @@ declare const isEmpty: import("./core/validator.js").Validator<string | object |
12
12
  declare const isNotEmpty: import("./core/validator.js").Validator<string | object | any[] | Set<any> | Map<any, any>, string | object | any[] | Set<any> | Map<any, any>, import("./core/types.js").ExecutionOptions>;
13
13
  declare const isInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
14
14
  declare const isNull: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
15
+ declare const isNotNull: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
15
16
  declare const isNullish: import("./core/validator.js").Validator<null, unknown, import("./core/types.js").ExecutionOptions>;
17
+ declare const isNotNullish: import("./core/validator.js").Validator<unknown, unknown, import("./core/types.js").ExecutionOptions>;
16
18
  declare const isDefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
17
19
  declare const isUndefined: import("./core/validator.js").Validator<any, unknown, import("./core/types.js").ExecutionOptions>;
18
20
  declare const isNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
@@ -58,4 +60,4 @@ declare const toDateString: import("./core/validator.js").Validator<string, stri
58
60
  declare const toInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
59
61
  declare const toNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
60
62
  declare const toString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
61
- 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, isNull, isNullish, isNumber, isObject, isObjectId, isPort, isString, isSWIFT, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, vg, };
63
+ 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, isUndefined, isUppercase, isURL, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, toArray, toBigint, toBoolean, toDate, toDateString, toInteger, toNumber, toString, vg, };
@@ -0,0 +1,21 @@
1
+ import { ValidationOptions } from '../../core/index.js';
2
+ /**
3
+ * Validates if value is "null".
4
+ * @validator isNull
5
+ */
6
+ export declare function isNull(options?: ValidationOptions): import("../../core/validator.js").Validator<null, unknown, import("../../core/types.js").ExecutionOptions>;
7
+ /**
8
+ * Validates if value is not "null".
9
+ * @validator isNotNull
10
+ */
11
+ export declare function isNotNull(options?: ValidationOptions): import("../../core/validator.js").Validator<unknown, unknown, import("../../core/types.js").ExecutionOptions>;
12
+ /**
13
+ * Validates if value is "null" or "undefined".
14
+ * @validator isNullish
15
+ */
16
+ export declare function isNullish(options?: ValidationOptions): import("../../core/validator.js").Validator<null, unknown, import("../../core/types.js").ExecutionOptions>;
17
+ /**
18
+ * Validates if value is not "null" nor "undefined".
19
+ * @validator isNotNullish
20
+ */
21
+ export declare function isNotNullish(options?: ValidationOptions): import("../../core/validator.js").Validator<unknown, unknown, import("../../core/types.js").ExecutionOptions>;
package/cjs/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,11 +0,0 @@
1
- import { ValidationOptions } from '../../core/index.js';
2
- /**
3
- * Validates if value is "null".
4
- * @validator isNull
5
- */
6
- export declare function isNull(options?: ValidationOptions): import("../../core/validator.js").Validator<null, unknown, import("../../core/types.js").ExecutionOptions>;
7
- /**
8
- * Validates if value is "null" or "undefined".
9
- * @validator isNull
10
- */
11
- export declare function isNullish(options?: ValidationOptions): import("../../core/validator.js").Validator<null, unknown, import("../../core/types.js").ExecutionOptions>;
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