valgen 5.4.0 → 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 +17 -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 +4 -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 +2 -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 +2 -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,10 +1,10 @@
1
- import { validator } from '../../core/index.js';
1
+ import { validator, } from '../../core/index.js';
2
2
  /**
3
3
  * Makes sub-rule optional
4
4
  * @validator optional
5
5
  */
6
6
  export function optional(nested, options) {
7
- return validator('optional', function (input, context) {
7
+ return validator('optional', (input, context) => {
8
8
  if (input == null)
9
9
  return input;
10
10
  return nested(input, context);
@@ -1,4 +1,4 @@
1
- import { validator } from '../../core/index.js';
1
+ import { validator, } from '../../core/index.js';
2
2
  /**
3
3
  *
4
4
  * @validator pipe
@@ -6,11 +6,11 @@ import { validator } from '../../core/index.js';
6
6
  export function pipe(rules, options) {
7
7
  const l = rules.length;
8
8
  const returnIndex = options?.returnIndex;
9
- return validator('pipe', function (input, context) {
9
+ return validator('pipe', (input, context) => {
10
10
  let i;
11
11
  let c;
12
12
  let v = input;
13
- let returnValue;
13
+ let returnValue = input;
14
14
  for (i = 0; i < l; i++) {
15
15
  c = rules[i];
16
16
  v = c(v, context);
@@ -27,7 +27,7 @@ export function pipe(rules, options) {
27
27
  * @validator allOf
28
28
  */
29
29
  export function allOf(rules) {
30
- return validator('allOf', function (input, context) {
30
+ return validator('allOf', (input, context) => {
31
31
  let i;
32
32
  let c;
33
33
  const l = rules.length;
@@ -1,10 +1,10 @@
1
- import { validator } from '../../core/index.js';
1
+ import { validator, } from '../../core/index.js';
2
2
  /**
3
3
  * Makes sub-rule required
4
4
  * @validator required
5
5
  */
6
6
  export function required(nested, options) {
7
- return validator('required', function (input, context, _this) {
7
+ return validator('required', (input, context, _this) => {
8
8
  if (input == null) {
9
9
  context.fail(_this, `{{label}} is required`, input);
10
10
  return;
@@ -4,7 +4,7 @@ import { validator } from '../../core/index.js';
4
4
  */
5
5
  export function union(codecs) {
6
6
  const l = codecs.length;
7
- return validator('union', function (input, context, _this) {
7
+ return validator('union', (input, context, _this) => {
8
8
  let i;
9
9
  let c;
10
10
  let v;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valgen",
3
3
  "description": "Fast runtime type validator, converter and io (encoding/decoding) library",
4
- "version": "5.4.0",
4
+ "version": "5.5.0",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -12,7 +12,7 @@
12
12
  "url": "https://github.com/panates/valgen.git"
13
13
  },
14
14
  "dependencies": {
15
- "@types/validator": "^13.11.10",
15
+ "@types/validator": "^13.12.0",
16
16
  "date-fns": "^3.6.0",
17
17
  "ts-gems": "^3.4.0",
18
18
  "validator": "^13.12.0"
@@ -1,7 +1,7 @@
1
- export * from './context.js';
2
1
  export * from './constants.js';
2
+ export * from './context.js';
3
3
  export * from './types.js';
4
+ export * from './utilities.js';
4
5
  export * from './validation-error.js';
5
6
  export * from './validator.js';
6
- export * from './utilities.js';
7
- export { Nullish, Type, Maybe } from 'ts-gems';
7
+ export { Maybe, Nullish, Type } from 'ts-gems';
@@ -11,7 +11,7 @@ export interface ErrorIssue {
11
11
  label?: string;
12
12
  [key: string]: any;
13
13
  }
14
- export type OnFailFunction = (issue: ErrorIssue, context: Context, _super?: OnFailFunction) => string | Omit<ErrorIssue, 'id' | 'input'>;
14
+ export type OnFailFunction = (issue: ErrorIssue, context: Context) => string | Omit<ErrorIssue, 'id' | 'input'>;
15
15
  export interface ValidationOptions {
16
16
  onFail?: OnFailFunction;
17
17
  coerce?: boolean;
@@ -53,8 +53,9 @@ declare const isHex: import("./core/validator.js").Validator<string, string, imp
53
53
  declare const toArray: import("./core/validator.js").Validator<any[], any, import("./core/types.js").ExecutionOptions>;
54
54
  declare const toBoolean: import("./core/validator.js").Validator<boolean | undefined, unknown, import("./core/types.js").ExecutionOptions>;
55
55
  declare const toDate: import("./core/validator.js").Validator<Date, string | number | Date, import("./core/types.js").ExecutionOptions>;
56
+ declare const toBigint: import("./core/validator.js").Validator<bigint, unknown, import("./core/types.js").ExecutionOptions>;
56
57
  declare const toDateString: import("./core/validator.js").Validator<string, string | number | Date, import("./core/types.js").ExecutionOptions>;
57
58
  declare const toInteger: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
58
59
  declare const toNumber: import("./core/validator.js").Validator<number, unknown, import("./core/types.js").ExecutionOptions>;
59
60
  declare const toString: import("./core/validator.js").Validator<string, unknown, import("./core/types.js").ExecutionOptions>;
60
- export { vg, isAny, isArray, isBigint, isBoolean, isDate, isDateString, isEmpty, isNotEmpty, isInteger, isNull, isNullish, isDefined, isUndefined, isNumber, isObject, isObjectId, isString, isUUID, isUUID1, isUUID2, isUUID3, isUUID4, isUUID5, isEmail, isMobilePhone, isIP, isIPRange, isMACAddress, isPort, isURL, isBase64, isSWIFT, isCreditCard, isIBAN, isEAN, isFQDN, isISSN, isBtcAddress, isETHAddress, isHexColor, isJWT, isLowercase, isUppercase, isAlpha, isAlphanumeric, isAscii, isDecimal, isHex, toArray, toBoolean, toDate, toDateString, toInteger, toNumber, toString, };
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, };
@@ -1,16 +1,3 @@
1
- export * from './type-rules/is-any.js';
2
- export * from './type-rules/is-array.js';
3
- export * from './type-rules/is-bigint.js';
4
- export * from './type-rules/is-boolean.js';
5
- export * from './type-rules/is-date.js';
6
- export * from './type-rules/is-enum.js';
7
- export * from './type-rules/is-integer.js';
8
- export * from './type-rules/is-null.js';
9
- export * from './type-rules/is-number.js';
10
- export * from './type-rules/is-object.js';
11
- export * from './type-rules/is-record.js';
12
- export * from './type-rules/is-string.js';
13
- export * from './type-rules/is-tuple.js';
14
1
  export * from './format-rules/is-alpha.js';
15
2
  export * from './format-rules/is-ascii.js';
16
3
  export * from './format-rules/is-base64.js';
@@ -41,6 +28,20 @@ export * from './format-rules/matches.js';
41
28
  export * from './logical-rules/is-defined.js';
42
29
  export * from './logical-rules/is-empty.js';
43
30
  export * from './logical-rules/range.js';
31
+ export * from './type-rules/is-any.js';
32
+ export * from './type-rules/is-array.js';
33
+ export * from './type-rules/is-bigint.js';
34
+ export * from './type-rules/is-boolean.js';
35
+ export * from './type-rules/is-date.js';
36
+ export * from './type-rules/is-enum.js';
37
+ export * from './type-rules/is-integer.js';
38
+ export * from './type-rules/is-null.js';
39
+ export * from './type-rules/is-number.js';
40
+ export * from './type-rules/is-object.js';
41
+ export * from './type-rules/is-record.js';
42
+ export * from './type-rules/is-string.js';
43
+ export * from './type-rules/is-tuple.js';
44
+ export * from './type-rules/is-undefined.js';
44
45
  export * from './utility-rules/exists.js';
45
46
  export * from './utility-rules/get-length.js';
46
47
  export * from './utility-rules/optional.js';
@@ -4,8 +4,3 @@ import { ValidationOptions } from '../../core/index.js';
4
4
  * @validator isDefined
5
5
  */
6
6
  export declare function isDefined(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
7
- /**
8
- * Validates if value is "undefined"
9
- * @validator isUndefined
10
- */
11
- export declare function isUndefined(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
@@ -7,9 +7,25 @@ import { ValidationOptions, Validator } from '../../core/index.js';
7
7
  export declare function isTuple<T1, I1>(items: [Validator<T1, I1>], options?: ValidationOptions): Validator<[T1], [I1]>;
8
8
  export declare function isTuple<T1, I1, T2, I2>(items: [Validator<T1, I1>, Validator<T2, I2>], options?: ValidationOptions): Validator<[T1, T2], [I1, I2]>;
9
9
  export declare function isTuple<T1, I1, T2, I2, T3, I3>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>], options?: ValidationOptions): Validator<[T1, T2, T3], [I1, I2, I3]>;
10
- export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>, Validator<T4, I4>], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
11
- export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>, Validator<T4, I4>], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
12
- export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>, Validator<T4, I4>, Validator<T5, I5>], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5], [I1, I2, I3, I4, I5]>;
10
+ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [
11
+ Validator<T1, I1>,
12
+ Validator<T2, I2>,
13
+ Validator<T3, I3>,
14
+ Validator<T4, I4>
15
+ ], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
16
+ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [
17
+ Validator<T1, I1>,
18
+ Validator<T2, I2>,
19
+ Validator<T3, I3>,
20
+ Validator<T4, I4>
21
+ ], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
22
+ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5>(items: [
23
+ Validator<T1, I1>,
24
+ Validator<T2, I2>,
25
+ Validator<T3, I3>,
26
+ Validator<T4, I4>,
27
+ Validator<T5, I5>
28
+ ], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5], [I1, I2, I3, I4, I5]>;
13
29
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(items: [
14
30
  Validator<T1, I1>,
15
31
  Validator<T2, I2>,
@@ -18,4 +34,20 @@ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(
18
34
  Validator<T5, I5>,
19
35
  Validator<T6, I6>,
20
36
  ...Validator[]
21
- ], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5, T6, ...any[]], [I1, I2, I3, I4, I5, I5, ...any[]]>;
37
+ ], options?: ValidationOptions): Validator<[
38
+ T1,
39
+ T2,
40
+ T3,
41
+ T4,
42
+ T5,
43
+ T6,
44
+ ...any[]
45
+ ], [
46
+ I1,
47
+ I2,
48
+ I3,
49
+ I4,
50
+ I5,
51
+ I5,
52
+ ...any[]
53
+ ]>;
@@ -0,0 +1,6 @@
1
+ import { ValidationOptions } from '../../core/index.js';
2
+ /**
3
+ * Validates if value is "undefined"
4
+ * @validator isUndefined
5
+ */
6
+ export declare function isUndefined(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;