valgen 5.20.0 → 6.0.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 (97) hide show
  1. package/constants.js +1 -1
  2. package/index.d.ts +3 -6
  3. package/index.js +4 -4
  4. package/package.json +1 -1
  5. package/rules/format-rules/is-alpha.d.ts +5 -6
  6. package/rules/format-rules/is-alpha.js +1 -13
  7. package/rules/format-rules/is-alphanumeric.d.ts +10 -0
  8. package/rules/format-rules/is-alphanumeric.js +14 -0
  9. package/rules/format-rules/is-ascii.d.ts +5 -1
  10. package/rules/format-rules/is-base64.d.ts +5 -3
  11. package/rules/format-rules/is-btc-address.d.ts +5 -1
  12. package/rules/format-rules/is-credit-card.d.ts +5 -3
  13. package/rules/format-rules/is-decimal.d.ts +5 -1
  14. package/rules/format-rules/is-ean.d.ts +5 -1
  15. package/rules/format-rules/is-email.d.ts +59 -57
  16. package/rules/format-rules/is-eth-address.d.ts +6 -2
  17. package/rules/format-rules/is-eth-address.js +1 -1
  18. package/rules/format-rules/is-fqdn.d.ts +10 -8
  19. package/rules/format-rules/is-hash.d.ts +4 -2
  20. package/rules/format-rules/is-hex-color.d.ts +5 -1
  21. package/rules/format-rules/is-hex.d.ts +5 -1
  22. package/rules/format-rules/is-iban.d.ts +5 -6
  23. package/rules/format-rules/is-iban.js +0 -11
  24. package/rules/format-rules/is-ip.d.ts +9 -2
  25. package/rules/format-rules/is-issn.d.ts +11 -9
  26. package/rules/format-rules/is-jwt.d.ts +5 -1
  27. package/rules/format-rules/is-lowercase.d.ts +5 -6
  28. package/rules/format-rules/is-lowercase.js +0 -12
  29. package/rules/format-rules/is-mac-address.d.ts +18 -16
  30. package/rules/format-rules/is-mobile-phone.d.ts +16 -14
  31. package/rules/format-rules/is-object-id.d.ts +7 -5
  32. package/rules/format-rules/is-passport-number.d.ts +5 -1
  33. package/rules/format-rules/is-port.d.ts +5 -1
  34. package/rules/format-rules/is-swift.d.ts +10 -0
  35. package/rules/format-rules/is-swift.js +13 -0
  36. package/rules/format-rules/is-time.d.ts +5 -3
  37. package/rules/format-rules/is-uppercase.d.ts +10 -0
  38. package/rules/format-rules/is-uppercase.js +14 -0
  39. package/rules/format-rules/is-url.d.ts +5 -3
  40. package/rules/format-rules/is-uuid.d.ts +6 -2
  41. package/rules/format-rules/is-vat-number.d.ts +6 -2
  42. package/rules/format-rules/matches.d.ts +6 -4
  43. package/rules/index.d.ts +9 -0
  44. package/rules/index.js +9 -0
  45. package/rules/logical-rules/is-defined.d.ts +5 -1
  46. package/rules/logical-rules/is-empty.d.ts +12 -4
  47. package/rules/logical-rules/is-empty.js +2 -2
  48. package/rules/logical-rules/is-equal.d.ts +10 -2
  49. package/rules/logical-rules/is-gt.d.ts +12 -0
  50. package/rules/logical-rules/is-gt.js +27 -0
  51. package/rules/logical-rules/is-gte.d.ts +12 -0
  52. package/rules/logical-rules/is-gte.js +27 -0
  53. package/rules/logical-rules/is-lt.d.ts +12 -0
  54. package/rules/logical-rules/is-lt.js +27 -0
  55. package/rules/logical-rules/is-lte.d.ts +12 -0
  56. package/rules/logical-rules/is-lte.js +27 -0
  57. package/rules/logical-rules/length.d.ts +10 -0
  58. package/rules/logical-rules/length.js +29 -0
  59. package/rules/logical-rules/range.d.ts +6 -42
  60. package/rules/logical-rules/range.js +0 -134
  61. package/rules/type-rules/is-any.d.ts +1 -1
  62. package/rules/type-rules/is-any.js +1 -1
  63. package/rules/type-rules/is-array.d.ts +7 -3
  64. package/rules/type-rules/is-array.js +2 -2
  65. package/rules/type-rules/is-bigint.d.ts +6 -2
  66. package/rules/type-rules/is-bigint.js +1 -1
  67. package/rules/type-rules/is-boolean.d.ts +6 -2
  68. package/rules/type-rules/is-boolean.js +1 -1
  69. package/rules/type-rules/is-date.d.ts +17 -12
  70. package/rules/type-rules/is-date.js +1 -1
  71. package/rules/type-rules/is-enum.d.ts +8 -5
  72. package/rules/type-rules/is-enum.js +1 -1
  73. package/rules/type-rules/is-integer.d.ts +7 -3
  74. package/rules/type-rules/is-integer.js +2 -2
  75. package/rules/type-rules/is-null.d.ts +24 -8
  76. package/rules/type-rules/is-null.js +4 -4
  77. package/rules/type-rules/is-number.d.ts +7 -3
  78. package/rules/type-rules/is-number.js +2 -2
  79. package/rules/type-rules/is-object.d.ts +7 -7
  80. package/rules/type-rules/is-object.js +2 -2
  81. package/rules/type-rules/is-record.d.ts +7 -3
  82. package/rules/type-rules/is-record.js +2 -2
  83. package/rules/type-rules/is-string.d.ts +7 -38
  84. package/rules/type-rules/is-string.js +2 -49
  85. package/rules/type-rules/is-tuple.d.ts +13 -9
  86. package/rules/type-rules/is-undefined.d.ts +6 -2
  87. package/rules/type-rules/is-undefined.js +1 -1
  88. package/rules/utility-rules/all-of.d.ts +6 -2
  89. package/rules/utility-rules/all-of.js +3 -3
  90. package/rules/utility-rules/exists.d.ts +5 -1
  91. package/rules/utility-rules/one-of.d.ts +6 -2
  92. package/rules/utility-rules/one-of.js +4 -4
  93. package/rules/utility-rules/optional.d.ts +6 -2
  94. package/rules/utility-rules/optional.js +1 -1
  95. package/rules/utility-rules/pipe.d.ts +6 -4
  96. package/rules/utility-rules/string-utils.d.ts +35 -0
  97. package/rules/utility-rules/string-utils.js +48 -0
@@ -1,31 +1,31 @@
1
1
  import { type ValidationOptions, type Validator } from '../../core/index.js';
2
2
  /**
3
- * Validates if value is "tuple" and applies validation for each item.
4
- * Converts input value to tuple if coerce option is set to 'true'.
3
+ * Validates if the value is "tuple" and applies validation for each item.
4
+ * Converts input value to tuple if the coerce option is set to 'true'.
5
5
  * @validator isTuple
6
6
  */
7
- export declare function isTuple<T1, I1>(items: [Validator<T1, I1>], options?: ValidationOptions): Validator<[T1], [I1]>;
8
- export declare function isTuple<T1, I1, T2, I2>(items: [Validator<T1, I1>, Validator<T2, I2>], options?: ValidationOptions): Validator<[T1, T2], [I1, I2]>;
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]>;
7
+ export declare function isTuple<T1, I1>(items: [Validator<T1, I1>], options?: isTuple.Options): Validator<[T1], [I1]>;
8
+ export declare function isTuple<T1, I1, T2, I2>(items: [Validator<T1, I1>, Validator<T2, I2>], options?: isTuple.Options): Validator<[T1, T2], [I1, I2]>;
9
+ export declare function isTuple<T1, I1, T2, I2, T3, I3>(items: [Validator<T1, I1>, Validator<T2, I2>, Validator<T3, I3>], options?: isTuple.Options): Validator<[T1, T2, T3], [I1, I2, I3]>;
10
10
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [
11
11
  Validator<T1, I1>,
12
12
  Validator<T2, I2>,
13
13
  Validator<T3, I3>,
14
14
  Validator<T4, I4>
15
- ], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
15
+ ], options?: isTuple.Options): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
16
16
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4>(items: [
17
17
  Validator<T1, I1>,
18
18
  Validator<T2, I2>,
19
19
  Validator<T3, I3>,
20
20
  Validator<T4, I4>
21
- ], options?: ValidationOptions): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
21
+ ], options?: isTuple.Options): Validator<[T1, T2, T3, T4], [I1, I2, I3, I4]>;
22
22
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5>(items: [
23
23
  Validator<T1, I1>,
24
24
  Validator<T2, I2>,
25
25
  Validator<T3, I3>,
26
26
  Validator<T4, I4>,
27
27
  Validator<T5, I5>
28
- ], options?: ValidationOptions): Validator<[T1, T2, T3, T4, T5], [I1, I2, I3, I4, I5]>;
28
+ ], options?: isTuple.Options): Validator<[T1, T2, T3, T4, T5], [I1, I2, I3, I4, I5]>;
29
29
  export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(items: [
30
30
  Validator<T1, I1>,
31
31
  Validator<T2, I2>,
@@ -34,7 +34,7 @@ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(
34
34
  Validator<T5, I5>,
35
35
  Validator<T6, I6>,
36
36
  ...Validator[]
37
- ], options?: ValidationOptions): Validator<[
37
+ ], options?: isTuple.Options): Validator<[
38
38
  T1,
39
39
  T2,
40
40
  T3,
@@ -51,3 +51,7 @@ export declare function isTuple<T1, I1, T2, I2, T3, I3, T4, I4, T5, I5, T6, I6>(
51
51
  I5,
52
52
  ...any[]
53
53
  ]>;
54
+ export declare namespace isTuple {
55
+ interface Options extends ValidationOptions {
56
+ }
57
+ }
@@ -1,6 +1,10 @@
1
1
  import { type ValidationOptions } from '../../core/index.js';
2
2
  /**
3
- * Validates if value is "undefined"
3
+ * Validates if the value is undefined
4
4
  * @validator isUndefined
5
5
  */
6
- export declare function isUndefined(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
6
+ export declare function isUndefined(options?: isUndefined.Options): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
7
+ export declare namespace isUndefined {
8
+ interface Options extends ValidationOptions {
9
+ }
10
+ }
@@ -1,6 +1,6 @@
1
1
  import { validator, } from '../../core/index.js';
2
2
  /**
3
- * Validates if value is "undefined"
3
+ * Validates if the value is undefined
4
4
  * @validator isUndefined
5
5
  */
6
6
  export function isUndefined(options) {
@@ -1,6 +1,10 @@
1
- import { type Validator } from '../../core/index.js';
1
+ import { ValidationOptions, type Validator } from '../../core/index.js';
2
2
  /**
3
3
  * Test given value against to all codecs and returns original input
4
4
  * @validator allOf
5
5
  */
6
- export declare function allOf<T = any>(rules: Validator[]): Validator<T>;
6
+ export declare function allOf<T = any>(rules: Validator[], options?: allOf.Options): Validator<T>;
7
+ export declare namespace allOf {
8
+ interface Options extends ValidationOptions {
9
+ }
10
+ }
@@ -1,16 +1,16 @@
1
- import { validator } from '../../core/index.js';
1
+ import { validator, } from '../../core/index.js';
2
2
  /**
3
3
  * Test given value against to all codecs and returns original input
4
4
  * @validator allOf
5
5
  */
6
- export function allOf(rules) {
6
+ export function allOf(rules, options) {
7
7
  return validator('allOf', (input, context) => {
8
8
  let i;
9
9
  let c;
10
10
  const l = rules.length;
11
11
  for (i = 0; i < l; i++) {
12
12
  c = rules[i];
13
- c(input, context);
13
+ c(input, context || options);
14
14
  }
15
15
  return input;
16
16
  });
@@ -3,4 +3,8 @@ import { type ValidationOptions } from '../../core/index.js';
3
3
  * Validates if property exists
4
4
  * @validator exists
5
5
  */
6
- export declare function exists(options?: ValidationOptions): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
6
+ export declare function exists(options?: exists.Options): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
7
+ export declare namespace exists {
8
+ interface Options extends ValidationOptions {
9
+ }
10
+ }
@@ -1,7 +1,11 @@
1
- import { type Validator } from '../../core/index.js';
1
+ import { ValidationOptions, type Validator } from '../../core/index.js';
2
2
  type DiscriminatorRecord = Record<string, Validator>;
3
3
  /**
4
4
  *
5
5
  */
6
- export declare function oneOf(rules: (Validator | [Validator, DiscriminatorRecord])[]): Validator<any, any, import("../../core/types.js").ExecutionOptions>;
6
+ export declare function oneOf(rules: (Validator | [Validator, DiscriminatorRecord])[], options?: oneOf.Options): Validator<any, any, import("../../core/types.js").ExecutionOptions>;
7
+ export declare namespace oneOf {
8
+ interface Options extends ValidationOptions {
9
+ }
10
+ }
7
11
  export {};
@@ -1,8 +1,8 @@
1
- import { validator } from '../../core/index.js';
1
+ import { validator, } from '../../core/index.js';
2
2
  /**
3
3
  *
4
4
  */
5
- export function oneOf(rules) {
5
+ export function oneOf(rules, options) {
6
6
  const l = rules.length;
7
7
  return validator('union', (input, context, _this) => {
8
8
  let i;
@@ -24,7 +24,7 @@ export function oneOf(rules) {
24
24
  }
25
25
  try {
26
26
  for (const k of Object.keys(discriminator)) {
27
- discriminator[k](input[k], context);
27
+ discriminator[k](input[k], context || options);
28
28
  if (!passed)
29
29
  break;
30
30
  }
@@ -39,7 +39,7 @@ export function oneOf(rules) {
39
39
  c = rules[i];
40
40
  if (passed)
41
41
  try {
42
- v = c(input, context);
42
+ v = c(input, context || options);
43
43
  if (passed)
44
44
  break;
45
45
  }
@@ -1,7 +1,11 @@
1
1
  import type { Nullish } from 'ts-gems';
2
2
  import { type ValidationOptions, type Validator } from '../../core/index.js';
3
3
  /**
4
- * Makes sub-rule optional
4
+ * Makes the sub-rule optional
5
5
  * @validator optional
6
6
  */
7
- export declare function optional<T, I>(nested: Validator<T, I>, options?: ValidationOptions): Validator<Nullish<T>, Nullish<I>, import("../../core/types.js").ExecutionOptions>;
7
+ export declare function optional<T, I>(nested: Validator<T, I>, options?: optional.Options): Validator<Nullish<T>, Nullish<I>, import("../../core/types.js").ExecutionOptions>;
8
+ export declare namespace optional {
9
+ interface Options extends ValidationOptions {
10
+ }
11
+ }
@@ -1,6 +1,6 @@
1
1
  import { validator, } from '../../core/index.js';
2
2
  /**
3
- * Makes sub-rule optional
3
+ * Makes the sub-rule optional
4
4
  * @validator optional
5
5
  */
6
6
  export function optional(nested, options) {
@@ -1,9 +1,11 @@
1
1
  import { type ValidationOptions, type Validator } from '../../core/index.js';
2
- export interface PipeOptions extends ValidationOptions {
3
- returnIndex?: number;
4
- }
5
2
  /**
6
3
  *
7
4
  * @validator pipe
8
5
  */
9
- export declare function pipe<T>(rules: Validator[], options?: PipeOptions): Validator<T>;
6
+ export declare function pipe<T>(rules: Validator[], options?: pipe.Options): Validator<T>;
7
+ export declare namespace pipe {
8
+ interface Options extends ValidationOptions {
9
+ returnIndex?: number;
10
+ }
11
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Applies "String.replace" method
3
+ * @validator stringReplace
4
+ */
5
+ export declare function stringReplace(searchValue: string | RegExp, replaceValue: string): any;
6
+ export declare function stringReplace(searchValue: string | RegExp, replacer: (subsring: string, ...args: any[]) => string): any;
7
+ export declare function stringReplace(searchValue: {
8
+ [Symbol.replace](string: string, replaceValue: string): string;
9
+ }, replaceValue: string): any;
10
+ export declare function stringReplace(searchValue: {
11
+ [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
12
+ }, replacer: (substring: string, ...args: any[]) => string): any;
13
+ /**
14
+ * Applies "String.split" method
15
+ * @validator split
16
+ */
17
+ export declare function stringSplit(separator: string | RegExp, limit?: number): any;
18
+ export declare function stringSplit(splitter: {
19
+ [Symbol.split](string: string, limit?: number): string[];
20
+ }, limit?: number): any;
21
+ /**
22
+ * Removes whitespace from both ends of a string
23
+ * @validator trim
24
+ */
25
+ export declare function trim(): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
26
+ /**
27
+ * Removes whitespace from the end of a string
28
+ * @validator trimEnd
29
+ */
30
+ export declare const trimEnd: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
31
+ /**
32
+ * Removes whitespace from the beginning of a string
33
+ * @validator trimStart
34
+ */
35
+ export declare const trimStart: () => import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
@@ -0,0 +1,48 @@
1
+ import { validator } from '../../core/index.js';
2
+ export function stringReplace(searchValue, replacer) {
3
+ return validator('stringReplace', (input) => {
4
+ if (input == null)
5
+ return input;
6
+ return String(input).replace(searchValue, replacer);
7
+ });
8
+ }
9
+ export function stringSplit(splitter, limit) {
10
+ return validator('stringSplit', (input) => {
11
+ if (input == null)
12
+ return input;
13
+ return String(input).split(splitter, limit);
14
+ });
15
+ }
16
+ /**
17
+ * Removes whitespace from both ends of a string
18
+ * @validator trim
19
+ */
20
+ export function trim() {
21
+ return validator('trim', (input) => {
22
+ if (input == null)
23
+ return input;
24
+ return String(input).trim();
25
+ });
26
+ }
27
+ // *************************************************************
28
+ /**
29
+ * Removes whitespace from the end of a string
30
+ * @validator trimEnd
31
+ */
32
+ export const trimEnd = () => trimEndRule;
33
+ const trimEndRule = validator('trimEnd', (input) => {
34
+ if (input == null)
35
+ return input;
36
+ return String(input).trimEnd();
37
+ });
38
+ // *************************************************************
39
+ /**
40
+ * Removes whitespace from the beginning of a string
41
+ * @validator trimStart
42
+ */
43
+ export const trimStart = () => trimStartRule;
44
+ const trimStartRule = validator('trimStart', (input) => {
45
+ if (input == null)
46
+ return input;
47
+ return String(input).trimStart();
48
+ });