valgen 7.0.1 → 7.0.3

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 (143) hide show
  1. package/README.md +1 -1
  2. package/constants.js +1 -1
  3. package/core/constants.d.ts +11 -0
  4. package/core/constants.js +11 -0
  5. package/core/context.d.ts +57 -0
  6. package/core/context.js +57 -0
  7. package/core/types.d.ts +40 -0
  8. package/core/utilities.d.ts +42 -2
  9. package/core/utilities.js +21 -1
  10. package/core/validation-error.d.ts +13 -0
  11. package/core/validation-error.js +13 -0
  12. package/core/validator.d.ts +100 -0
  13. package/core/validator.js +6 -0
  14. package/package.json +1 -1
  15. package/rules/format-rules/is-alpha.d.ts +10 -1
  16. package/rules/format-rules/is-alpha.js +10 -1
  17. package/rules/format-rules/is-alphanumeric.d.ts +10 -1
  18. package/rules/format-rules/is-alphanumeric.js +10 -1
  19. package/rules/format-rules/is-ascii.d.ts +10 -1
  20. package/rules/format-rules/is-ascii.js +10 -1
  21. package/rules/format-rules/is-base64.d.ts +20 -1
  22. package/rules/format-rules/is-base64.js +10 -1
  23. package/rules/format-rules/is-btc-address.d.ts +10 -1
  24. package/rules/format-rules/is-btc-address.js +10 -1
  25. package/rules/format-rules/is-credit-card.d.ts +16 -1
  26. package/rules/format-rules/is-credit-card.js +11 -1
  27. package/rules/format-rules/is-decimal.d.ts +12 -2
  28. package/rules/format-rules/is-decimal.js +12 -2
  29. package/rules/format-rules/is-ean.d.ts +11 -1
  30. package/rules/format-rules/is-ean.js +11 -1
  31. package/rules/format-rules/is-email.d.ts +19 -7
  32. package/rules/format-rules/is-email.js +13 -1
  33. package/rules/format-rules/is-eth-address.d.ts +10 -1
  34. package/rules/format-rules/is-eth-address.js +10 -1
  35. package/rules/format-rules/is-fqdn.d.ts +13 -2
  36. package/rules/format-rules/is-fqdn.js +12 -1
  37. package/rules/format-rules/is-hash.d.ts +17 -1
  38. package/rules/format-rules/is-hash.js +16 -1
  39. package/rules/format-rules/is-hex-color.d.ts +13 -1
  40. package/rules/format-rules/is-hex-color.js +13 -1
  41. package/rules/format-rules/is-hex.d.ts +13 -1
  42. package/rules/format-rules/is-hex.js +13 -1
  43. package/rules/format-rules/is-iban.d.ts +33 -2
  44. package/rules/format-rules/is-iban.js +19 -1
  45. package/rules/format-rules/is-ip.d.ts +44 -2
  46. package/rules/format-rules/is-ip.js +42 -2
  47. package/rules/format-rules/is-issn.d.ts +19 -2
  48. package/rules/format-rules/is-issn.js +18 -1
  49. package/rules/format-rules/is-jwt.d.ts +16 -1
  50. package/rules/format-rules/is-jwt.js +16 -1
  51. package/rules/format-rules/is-lowercase.d.ts +13 -1
  52. package/rules/format-rules/is-lowercase.js +13 -1
  53. package/rules/format-rules/is-mac-address.d.ts +19 -2
  54. package/rules/format-rules/is-mac-address.js +16 -1
  55. package/rules/format-rules/is-mobile-phone.d.ts +19 -3
  56. package/rules/format-rules/is-mobile-phone.js +17 -1
  57. package/rules/format-rules/is-object-id.d.ts +20 -1
  58. package/rules/format-rules/is-object-id.js +19 -1
  59. package/rules/format-rules/is-passport-number.d.ts +17 -1
  60. package/rules/format-rules/is-passport-number.js +17 -1
  61. package/rules/format-rules/is-port.d.ts +16 -1
  62. package/rules/format-rules/is-port.js +16 -1
  63. package/rules/format-rules/is-swift.d.ts +15 -1
  64. package/rules/format-rules/is-swift.js +15 -1
  65. package/rules/format-rules/is-time.d.ts +22 -1
  66. package/rules/format-rules/is-time.js +22 -1
  67. package/rules/format-rules/is-uppercase.d.ts +15 -1
  68. package/rules/format-rules/is-uppercase.js +15 -1
  69. package/rules/format-rules/is-url.d.ts +99 -1
  70. package/rules/format-rules/is-url.js +19 -1
  71. package/rules/format-rules/is-uuid.d.ts +23 -1
  72. package/rules/format-rules/is-uuid.js +23 -1
  73. package/rules/format-rules/is-vat-number.d.ts +19 -2
  74. package/rules/format-rules/is-vat-number.js +19 -2
  75. package/rules/format-rules/matches.d.ts +27 -1
  76. package/rules/format-rules/matches.js +23 -1
  77. package/rules/logical-rules/is-defined.d.ts +14 -2
  78. package/rules/logical-rules/is-defined.js +13 -2
  79. package/rules/logical-rules/is-empty.d.ts +40 -2
  80. package/rules/logical-rules/is-empty.js +38 -2
  81. package/rules/logical-rules/is-equal.d.ts +31 -4
  82. package/rules/logical-rules/is-equal.js +29 -4
  83. package/rules/logical-rules/is-gt.d.ts +26 -1
  84. package/rules/logical-rules/is-gt.js +20 -1
  85. package/rules/logical-rules/is-gte.d.ts +25 -1
  86. package/rules/logical-rules/is-gte.js +20 -1
  87. package/rules/logical-rules/is-lt.d.ts +24 -1
  88. package/rules/logical-rules/is-lt.js +19 -1
  89. package/rules/logical-rules/is-lte.d.ts +25 -1
  90. package/rules/logical-rules/is-lte.js +20 -1
  91. package/rules/logical-rules/length.d.ts +38 -2
  92. package/rules/logical-rules/length.js +38 -2
  93. package/rules/logical-rules/range.d.ts +25 -1
  94. package/rules/logical-rules/range.js +23 -1
  95. package/rules/type-rules/is-any.d.ts +12 -1
  96. package/rules/type-rules/is-any.js +12 -1
  97. package/rules/type-rules/is-array.d.ts +23 -2
  98. package/rules/type-rules/is-array.js +23 -2
  99. package/rules/type-rules/is-bigint.d.ts +14 -2
  100. package/rules/type-rules/is-bigint.js +14 -2
  101. package/rules/type-rules/is-boolean.d.ts +17 -2
  102. package/rules/type-rules/is-boolean.js +17 -2
  103. package/rules/type-rules/is-date.d.ts +47 -5
  104. package/rules/type-rules/is-date.js +42 -5
  105. package/rules/type-rules/is-enum.d.ts +23 -1
  106. package/rules/type-rules/is-enum.js +21 -1
  107. package/rules/type-rules/is-instanceof.d.ts +21 -1
  108. package/rules/type-rules/is-instanceof.js +21 -1
  109. package/rules/type-rules/is-integer.d.ts +17 -2
  110. package/rules/type-rules/is-integer.js +17 -2
  111. package/rules/type-rules/is-null.d.ts +51 -4
  112. package/rules/type-rules/is-null.js +51 -4
  113. package/rules/type-rules/is-number.d.ts +17 -2
  114. package/rules/type-rules/is-number.js +17 -2
  115. package/rules/type-rules/is-object.d.ts +45 -7
  116. package/rules/type-rules/is-object.js +40 -7
  117. package/rules/type-rules/is-record.d.ts +21 -2
  118. package/rules/type-rules/is-record.js +21 -2
  119. package/rules/type-rules/is-string.d.ts +16 -2
  120. package/rules/type-rules/is-string.js +16 -2
  121. package/rules/type-rules/is-tuple.d.ts +21 -2
  122. package/rules/type-rules/is-undefined.d.ts +16 -4
  123. package/rules/type-rules/is-undefined.js +16 -4
  124. package/rules/utility-rules/all-of.d.ts +28 -1
  125. package/rules/utility-rules/all-of.js +27 -1
  126. package/rules/utility-rules/exists.d.ts +30 -1
  127. package/rules/utility-rules/exists.js +29 -1
  128. package/rules/utility-rules/fixed.d.ts +19 -1
  129. package/rules/utility-rules/fixed.js +19 -1
  130. package/rules/utility-rules/get-length.d.ts +25 -2
  131. package/rules/utility-rules/get-length.js +25 -2
  132. package/rules/utility-rules/nullable.d.ts +28 -1
  133. package/rules/utility-rules/nullable.js +27 -1
  134. package/rules/utility-rules/one-of.d.ts +52 -3
  135. package/rules/utility-rules/one-of.js +51 -3
  136. package/rules/utility-rules/optional.d.ts +29 -1
  137. package/rules/utility-rules/optional.js +28 -1
  138. package/rules/utility-rules/pipe.d.ts +38 -1
  139. package/rules/utility-rules/pipe.js +30 -1
  140. package/rules/utility-rules/required.d.ts +39 -1
  141. package/rules/utility-rules/required.js +32 -1
  142. package/rules/utility-rules/string-utils.d.ts +99 -5
  143. package/rules/utility-rules/string-utils.js +53 -3
@@ -1,7 +1,28 @@
1
1
  import { validator, } from '../../core/index.js';
2
2
  const TIME_PATTERN = /^(\d{2}):?(\d{2})(?::?(\d{2}))?(?:\.(\d{1,3}))?$/;
3
3
  /**
4
- * Validates if value is a time formatted string
4
+ * Validates (and optionally coerces) a time-of-day value in `HH:mm`,
5
+ * `HH:mm:ss`, or `HH:mm:ss.SSS` format, with or without separators. Not a
6
+ * wrapper around `@browsery/validator` - it uses its own regex and checks
7
+ * hour ≤ 23, minutes/seconds ≤ 59.
8
+ *
9
+ * @param options - Validation options. When `coerce` is `true`, a `Date`
10
+ * input is converted to a `HH:mm:ss[.SSS]` string, and a compact form
11
+ * without separators (e.g. `'1230'`) is normalized to colon-separated form;
12
+ * without `coerce`, the input string is returned unchanged.
13
+ * @returns The validated (and possibly coerced) time string.
14
+ * @throws `Value must be a valid Time` when the input isn't a recognized
15
+ * time-of-day value.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { isTime } from 'valgen';
20
+ *
21
+ * isTime('12:30', { coerce: true }); // => '12:30'
22
+ * isTime('1230', { coerce: true }); // => '12:30'
23
+ * isTime(new Date('2025-01-10T08:30:15'), { coerce: true }); // => '08:30:15'
24
+ * isTime('25:00'); // throws ValidationError: "Value must be a valid Time"
25
+ * ```
5
26
  * @validator isTime
6
27
  */
7
28
  export function isTime(options) {
@@ -1,6 +1,20 @@
1
1
  import { type ValidationOptions } from '../../core/index.js';
2
2
  /**
3
- * Validates if value a Uppercase string
3
+ * Validates that a string contains only uppercase characters, by delegating
4
+ * to `validatorJS.isUppercase(input)`.
5
+ *
6
+ * @param options - Validation options.
7
+ * @returns The validated string, unchanged.
8
+ * @throws `Value must be an uppercase string` when the input contains any
9
+ * non-uppercase characters.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { isUppercase } from 'valgen';
14
+ *
15
+ * isUppercase('ABC'); // => 'ABC'
16
+ * isUppercase('abc'); // throws ValidationError: "Value must be an uppercase string"
17
+ * ```
4
18
  * @validator isUppercase
5
19
  */
6
20
  export declare function isUppercase(options?: isUppercase.Options): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
@@ -1,7 +1,21 @@
1
1
  import validatorJS from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
- * Validates if value a Uppercase string
4
+ * Validates that a string contains only uppercase characters, by delegating
5
+ * to `validatorJS.isUppercase(input)`.
6
+ *
7
+ * @param options - Validation options.
8
+ * @returns The validated string, unchanged.
9
+ * @throws `Value must be an uppercase string` when the input contains any
10
+ * non-uppercase characters.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { isUppercase } from 'valgen';
15
+ *
16
+ * isUppercase('ABC'); // => 'ABC'
17
+ * isUppercase('abc'); // throws ValidationError: "Value must be an uppercase string"
18
+ * ```
5
19
  * @validator isUppercase
6
20
  */
7
21
  export function isUppercase(options) {
@@ -1,11 +1,109 @@
1
1
  import { type IsURLOptions as _IsURLOptions } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is an URL
4
+ * Validates that a string is a valid URL, by delegating directly to
5
+ * `validatorJS.isURL(input, options)`; all `IsURLOptions` fields pass through
6
+ * unchanged.
7
+ *
8
+ * @param options - Validation options - see {@link isURL.Options} for the
9
+ * forwarded `IsURLOptions` fields.
10
+ * @returns The validated URL string, unchanged.
11
+ * @throws `Value must be a valid URL` when the input isn't a valid URL.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { isURL, vg } from 'valgen';
16
+ *
17
+ * isURL('https://example.com'); // => 'https://example.com'
18
+ * isURL('not a url'); // throws ValidationError: "Value must be a valid URL"
19
+ *
20
+ * const httpsOnly = vg.isURL({ protocols: ['https'] });
21
+ * httpsOnly('http://example.com'); // throws ValidationError: "Value must be a valid URL"
22
+ * ```
5
23
  * @validator isURL
6
24
  */
7
25
  export declare function isURL(options?: isURL.Options): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
8
26
  export declare namespace isURL {
9
27
  interface Options extends ValidationOptions, _IsURLOptions {
28
+ /**
29
+ * Allowed protocols.
30
+ * @defaultValue `['http','https','ftp']`
31
+ */
32
+ protocols?: string[];
33
+ /**
34
+ * Require a top-level domain.
35
+ * @defaultValue `true`
36
+ */
37
+ require_tld?: boolean;
38
+ /**
39
+ * Require the protocol (`scheme://`) to be present.
40
+ * @defaultValue `false`
41
+ */
42
+ require_protocol?: boolean;
43
+ /**
44
+ * Require a host part.
45
+ * @defaultValue `true`
46
+ */
47
+ require_host?: boolean;
48
+ /**
49
+ * Require an explicit port.
50
+ * @defaultValue `false`
51
+ */
52
+ require_port?: boolean;
53
+ /**
54
+ * Restrict to protocols in `protocols`.
55
+ * @defaultValue `true`
56
+ */
57
+ require_valid_protocol?: boolean;
58
+ /**
59
+ * Allow underscores in the host.
60
+ * @defaultValue `false`
61
+ */
62
+ allow_underscores?: boolean;
63
+ /**
64
+ * Only accept these hosts.
65
+ * @defaultValue `false`
66
+ */
67
+ host_whitelist?: (string | RegExp)[];
68
+ /**
69
+ * Reject these hosts.
70
+ * @defaultValue `false`
71
+ */
72
+ host_blacklist?: (string | RegExp)[];
73
+ /**
74
+ * Allow a trailing `.` after the domain.
75
+ * @defaultValue `false`
76
+ */
77
+ allow_trailing_dot?: boolean;
78
+ /**
79
+ * Allow `//example.com`-style URLs.
80
+ * @defaultValue `false`
81
+ */
82
+ allow_protocol_relative_urls?: boolean;
83
+ /**
84
+ * Reject `user:pass@host` credentials.
85
+ * @defaultValue `false`
86
+ */
87
+ disallow_auth?: boolean;
88
+ /**
89
+ * Allow a `#fragment`.
90
+ * @defaultValue `true`
91
+ */
92
+ allow_fragments?: boolean;
93
+ /**
94
+ * Allow a `?query=components` section.
95
+ * @defaultValue `true`
96
+ */
97
+ allow_query_components?: boolean;
98
+ /**
99
+ * Enforce the max length check.
100
+ * @defaultValue `true`
101
+ */
102
+ validate_length?: boolean;
103
+ /**
104
+ * Max URL length when `validate_length` is enabled.
105
+ * @defaultValue `2084`
106
+ */
107
+ max_allowed_length?: number | false;
10
108
  }
11
109
  }
@@ -1,7 +1,25 @@
1
1
  import validatorJS, {} from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is an URL
4
+ * Validates that a string is a valid URL, by delegating directly to
5
+ * `validatorJS.isURL(input, options)`; all `IsURLOptions` fields pass through
6
+ * unchanged.
7
+ *
8
+ * @param options - Validation options - see {@link isURL.Options} for the
9
+ * forwarded `IsURLOptions` fields.
10
+ * @returns The validated URL string, unchanged.
11
+ * @throws `Value must be a valid URL` when the input isn't a valid URL.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { isURL, vg } from 'valgen';
16
+ *
17
+ * isURL('https://example.com'); // => 'https://example.com'
18
+ * isURL('not a url'); // throws ValidationError: "Value must be a valid URL"
19
+ *
20
+ * const httpsOnly = vg.isURL({ protocols: ['https'] });
21
+ * httpsOnly('http://example.com'); // throws ValidationError: "Value must be a valid URL"
22
+ * ```
5
23
  * @validator isURL
6
24
  */
7
25
  export function isURL(options) {
@@ -1,7 +1,29 @@
1
1
  import { type UUIDVersion as _UUIDVersion } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is a "UUID".
4
+ * Validates that a string is a valid UUID, optionally restricted to a
5
+ * specific version, by delegating to `validatorJS.isUUID(input, version)`.
6
+ * Without a version, any UUID version passes; with a version, only a UUID of
7
+ * that version passes.
8
+ *
9
+ * @param version - The UUID version to restrict to (e.g. `1`-`8`, `'nil'`,
10
+ * `'max'`, `'loose'`, `'all'`); omit to accept any version.
11
+ * @param options - Validation options.
12
+ * @returns The validated UUID string, unchanged.
13
+ * @throws `Value must be a valid UUID` (or `Value must be a valid UUID v<version>`
14
+ * when `version` is given) when the input isn't a matching UUID.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { isUUID, isUUID4, vg } from 'valgen';
19
+ *
20
+ * const uuidV4 = '01e0fee8-60d5-42a5-997c-b55a4f3e973f';
21
+ * isUUID(uuidV4); // => uuidV4 (any version accepted)
22
+ * isUUID4(uuidV4); // => uuidV4
23
+ *
24
+ * const isUUIDv1 = vg.isUUID(1);
25
+ * isUUIDv1(uuidV4); // throws ValidationError: "Value must be a valid UUID v1"
26
+ * ```
5
27
  * @validator isUUID
6
28
  */
7
29
  export declare function isUUID(version?: isUUID.UUIDVersion, options?: isUUID.Options): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
@@ -1,7 +1,29 @@
1
1
  import validatorJS, {} from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is a "UUID".
4
+ * Validates that a string is a valid UUID, optionally restricted to a
5
+ * specific version, by delegating to `validatorJS.isUUID(input, version)`.
6
+ * Without a version, any UUID version passes; with a version, only a UUID of
7
+ * that version passes.
8
+ *
9
+ * @param version - The UUID version to restrict to (e.g. `1`-`8`, `'nil'`,
10
+ * `'max'`, `'loose'`, `'all'`); omit to accept any version.
11
+ * @param options - Validation options.
12
+ * @returns The validated UUID string, unchanged.
13
+ * @throws `Value must be a valid UUID` (or `Value must be a valid UUID v<version>`
14
+ * when `version` is given) when the input isn't a matching UUID.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { isUUID, isUUID4, vg } from 'valgen';
19
+ *
20
+ * const uuidV4 = '01e0fee8-60d5-42a5-997c-b55a4f3e973f';
21
+ * isUUID(uuidV4); // => uuidV4 (any version accepted)
22
+ * isUUID4(uuidV4); // => uuidV4
23
+ *
24
+ * const isUUIDv1 = vg.isUUID(1);
25
+ * isUUIDv1(uuidV4); // throws ValidationError: "Value must be a valid UUID v1"
26
+ * ```
5
27
  * @validator isUUID
6
28
  */
7
29
  export function isUUID(version, options) {
@@ -1,8 +1,25 @@
1
1
  import { type VATCountryCode as _VATCountryCode } from '@browsery/validator';
2
2
  import { type ValidationOptions } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is a VAT number
5
- * @validator isVAT
4
+ * Validates that a string is a valid VAT (Value Added Tax) number for the
5
+ * given EU country code, by delegating to `validatorJS.isVAT(input, countryCode)`.
6
+ *
7
+ * @param countryCode - The EU VAT country code to validate the number against
8
+ * (e.g. `'AT'`, `'BE'`, `'BG'`, ...).
9
+ * @param options - Validation options.
10
+ * @returns The validated VAT number string, unchanged.
11
+ * @throws `Value must be a valid VAT number` when the input isn't a valid VAT
12
+ * number for `countryCode`.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { vg } from 'valgen';
17
+ *
18
+ * const isATVat = vg.isVATNumber('AT');
19
+ * isATVat('ATU12345678'); // => 'ATU12345678'
20
+ * isATVat('12345'); // throws ValidationError: "Value must be a valid VAT number"
21
+ * ```
22
+ * @validator isVATNumber
6
23
  */
7
24
  export declare function isVATNumber(countryCode: isVATNumber.CountryCode, options?: isVATNumber.Options): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
8
25
  export declare namespace isVATNumber {
@@ -1,8 +1,25 @@
1
1
  import validatorJS, {} from '@browsery/validator';
2
2
  import { validator, } from '../../core/index.js';
3
3
  /**
4
- * Validates if value is a VAT number
5
- * @validator isVAT
4
+ * Validates that a string is a valid VAT (Value Added Tax) number for the
5
+ * given EU country code, by delegating to `validatorJS.isVAT(input, countryCode)`.
6
+ *
7
+ * @param countryCode - The EU VAT country code to validate the number against
8
+ * (e.g. `'AT'`, `'BE'`, `'BG'`, ...).
9
+ * @param options - Validation options.
10
+ * @returns The validated VAT number string, unchanged.
11
+ * @throws `Value must be a valid VAT number` when the input isn't a valid VAT
12
+ * number for `countryCode`.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { vg } from 'valgen';
17
+ *
18
+ * const isATVat = vg.isVATNumber('AT');
19
+ * isATVat('ATU12345678'); // => 'ATU12345678'
20
+ * isATVat('12345'); // throws ValidationError: "Value must be a valid VAT number"
21
+ * ```
22
+ * @validator isVATNumber
6
23
  */
7
24
  export function isVATNumber(countryCode, options) {
8
25
  return validator(isVATNumber.name, (input, context, _this) => {
@@ -1,11 +1,37 @@
1
1
  import { type ValidationOptions } from '../../core/index.js';
2
2
  /**
3
- * Validates if value matches the given regular expression, or returns undefined if nullish
3
+ * Validates that a string matches a given regular expression pattern.
4
+ * Returns `undefined` for nullish input instead of failing. A string pattern
5
+ * is compiled via `new RegExp(format)`.
6
+ *
7
+ * @param format - The pattern to match against - a `RegExp`, or a string
8
+ * compiled into one.
9
+ * @param options - Validation options.
10
+ * @returns The validated string, unchanged, or `undefined` when the input
11
+ * was `null`/`undefined`.
12
+ * @throws `Value must match <formatName> format` (using `'requested'` when
13
+ * `formatName` is omitted) when the input isn't a string or doesn't match.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { vg } from 'valgen';
18
+ *
19
+ * const isDigits = vg.matches(/\d+/);
20
+ * isDigits('0123'); // => '0123'
21
+ * isDigits('abc'); // throws ValidationError: "Value must match requested format"
22
+ *
23
+ * const isPositiveNumber = vg.matches(/\d+/, { formatName: 'positive number' });
24
+ * isPositiveNumber('abc'); // throws ValidationError: "Value must match positive number format"
25
+ * ```
4
26
  * @validator matches
5
27
  */
6
28
  export declare function matches(format: string | RegExp, options?: matches.Options): import("../../core/validator.js").Validator<string, string, import("../../core/types.js").ExecutionOptions>;
7
29
  export declare namespace matches {
8
30
  interface Options extends ValidationOptions {
31
+ /**
32
+ * Name used in the error message (`Value must match <formatName> format`).
33
+ * @defaultValue `'requested'`
34
+ */
9
35
  formatName?: string;
10
36
  }
11
37
  }
@@ -1,6 +1,28 @@
1
1
  import { validator, } from '../../core/index.js';
2
2
  /**
3
- * Validates if value matches the given regular expression, or returns undefined if nullish
3
+ * Validates that a string matches a given regular expression pattern.
4
+ * Returns `undefined` for nullish input instead of failing. A string pattern
5
+ * is compiled via `new RegExp(format)`.
6
+ *
7
+ * @param format - The pattern to match against - a `RegExp`, or a string
8
+ * compiled into one.
9
+ * @param options - Validation options.
10
+ * @returns The validated string, unchanged, or `undefined` when the input
11
+ * was `null`/`undefined`.
12
+ * @throws `Value must match <formatName> format` (using `'requested'` when
13
+ * `formatName` is omitted) when the input isn't a string or doesn't match.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { vg } from 'valgen';
18
+ *
19
+ * const isDigits = vg.matches(/\d+/);
20
+ * isDigits('0123'); // => '0123'
21
+ * isDigits('abc'); // throws ValidationError: "Value must match requested format"
22
+ *
23
+ * const isPositiveNumber = vg.matches(/\d+/, { formatName: 'positive number' });
24
+ * isPositiveNumber('abc'); // throws ValidationError: "Value must match positive number format"
25
+ * ```
4
26
  * @validator matches
5
27
  */
6
28
  export function matches(format, options) {
@@ -1,11 +1,23 @@
1
1
  import { type ValidationOptions } from '../../core/index.js';
2
2
  /**
3
- * Validates if value is not "undefined". Note that "null" is considered
4
- * defined; use `isNotNullish` to reject both "undefined" and "null".
3
+ * Validates that a value is not `undefined`. Note that `null` is considered
4
+ * defined - use `isNotNullish` to reject both `undefined` and `null`.
5
+ *
6
+ * @param options - Validation options (`onFail`, `coerce`, ...).
7
+ * @returns The input value unchanged as long as it is not `undefined`,
8
+ * including `0`, `''`, and `null`.
9
+ * @throws `Value must be defined` if the input is `undefined`.
10
+ * @example
11
+ * ```ts
12
+ * isDefined(0); // => 0
13
+ * isDefined(null); // => null
14
+ * isDefined(undefined); // throws ValidationError: "Value must be defined"
15
+ * ```
5
16
  * @validator isDefined
6
17
  */
7
18
  export declare function isDefined(options?: isDefined.Options): import("../../core/validator.js").Validator<any, unknown, import("../../core/types.js").ExecutionOptions>;
8
19
  export declare namespace isDefined {
20
+ /** Options for {@link isDefined} - adds no properties beyond `ValidationOptions`. */
9
21
  interface Options extends ValidationOptions {
10
22
  }
11
23
  }
@@ -1,7 +1,18 @@
1
1
  import { validator, } from '../../core/index.js';
2
2
  /**
3
- * Validates if value is not "undefined". Note that "null" is considered
4
- * defined; use `isNotNullish` to reject both "undefined" and "null".
3
+ * Validates that a value is not `undefined`. Note that `null` is considered
4
+ * defined - use `isNotNullish` to reject both `undefined` and `null`.
5
+ *
6
+ * @param options - Validation options (`onFail`, `coerce`, ...).
7
+ * @returns The input value unchanged as long as it is not `undefined`,
8
+ * including `0`, `''`, and `null`.
9
+ * @throws `Value must be defined` if the input is `undefined`.
10
+ * @example
11
+ * ```ts
12
+ * isDefined(0); // => 0
13
+ * isDefined(null); // => null
14
+ * isDefined(undefined); // throws ValidationError: "Value must be defined"
15
+ * ```
5
16
  * @validator isDefined
6
17
  */
7
18
  export function isDefined(options) {
@@ -1,19 +1,57 @@
1
1
  import { type ValidationOptions } from '../../core/index.js';
2
2
  /**
3
- * Checks if the value is empty. Value should be string, array, set, map or object
3
+ * Checks that the value is empty. The value should be a string, array, Set,
4
+ * Map, Buffer, ArrayBuffer, or plain object.
5
+ *
6
+ * `null`/`undefined` pass through unchanged (treated as empty), and `Date`
7
+ * instances always pass since a date has no "empty" concept.
8
+ *
9
+ * @param options - Validation options (`onFail`, `coerce`, ...).
10
+ * @returns The input value unchanged when it is considered empty.
11
+ * @throws `Value must be an empty string` / `Value must be an empty array` /
12
+ * `Value must be an empty Set` / `Value must be an empty Map` / `Value must
13
+ * be an empty Buffer` / `Value must be an empty ArrayBuffer` / `Value must be
14
+ * an empty Object`, depending on the input's type, or the generic `Value
15
+ * must be empty` for any other non-empty type (e.g. `NaN`).
16
+ * @example
17
+ * ```ts
18
+ * isEmpty(''); // => ''
19
+ * isEmpty([]); // => []
20
+ * isEmpty('dd'); // throws ValidationError: "Value must be an empty string"
21
+ * ```
4
22
  * @validator isEmpty
5
23
  */
6
24
  export declare function isEmpty(options?: isEmpty.Options): import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;
7
25
  export declare namespace isEmpty {
26
+ /** Options for {@link isEmpty} - adds no properties beyond `ValidationOptions`. */
8
27
  interface Options extends ValidationOptions {
9
28
  }
10
29
  }
11
30
  /**
12
- * Checks if the value is not empty. Value should be string, array, set, map or object
31
+ * Checks that the value is not empty. The value should be a string, array,
32
+ * Set, Map, Buffer, ArrayBuffer, or plain object.
33
+ *
34
+ * Unlike `isEmpty`, nullish input is rejected here rather than treated as
35
+ * passing, and `Date` instances always pass.
36
+ *
37
+ * @param options - Validation options (`onFail`, `coerce`, ...).
38
+ * @returns The input value unchanged when it is considered non-empty.
39
+ * @throws `Value must not be empty` for `null`/`undefined`/an empty string,
40
+ * `Value must not be NaN` for `NaN`, `Array must not be empty`, `Set must
41
+ * not be empty`, `Map must not be empty`, `Buffer must not be empty`,
42
+ * `ArrayBuffer must not be empty`, or `Object must not be empty`, depending
43
+ * on the input's type.
44
+ * @example
45
+ * ```ts
46
+ * isNotEmpty('abc'); // => 'abc'
47
+ * isNotEmpty(''); // throws ValidationError: "Value must not be empty"
48
+ * isNotEmpty([]); // throws ValidationError: "Array must not be empty"
49
+ * ```
13
50
  * @validator isNotEmpty
14
51
  */
15
52
  export declare function isNotEmpty(options?: isNotEmpty.Options): import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;
16
53
  export declare namespace isNotEmpty {
54
+ /** Options for {@link isNotEmpty} - adds no properties beyond `ValidationOptions`. */
17
55
  interface Options extends ValidationOptions {
18
56
  }
19
57
  }
@@ -1,6 +1,24 @@
1
1
  import { validator, } from '../../core/index.js';
2
2
  /**
3
- * Checks if the value is empty. Value should be string, array, set, map or object
3
+ * Checks that the value is empty. The value should be a string, array, Set,
4
+ * Map, Buffer, ArrayBuffer, or plain object.
5
+ *
6
+ * `null`/`undefined` pass through unchanged (treated as empty), and `Date`
7
+ * instances always pass since a date has no "empty" concept.
8
+ *
9
+ * @param options - Validation options (`onFail`, `coerce`, ...).
10
+ * @returns The input value unchanged when it is considered empty.
11
+ * @throws `Value must be an empty string` / `Value must be an empty array` /
12
+ * `Value must be an empty Set` / `Value must be an empty Map` / `Value must
13
+ * be an empty Buffer` / `Value must be an empty ArrayBuffer` / `Value must be
14
+ * an empty Object`, depending on the input's type, or the generic `Value
15
+ * must be empty` for any other non-empty type (e.g. `NaN`).
16
+ * @example
17
+ * ```ts
18
+ * isEmpty(''); // => ''
19
+ * isEmpty([]); // => []
20
+ * isEmpty('dd'); // throws ValidationError: "Value must be an empty string"
21
+ * ```
4
22
  * @validator isEmpty
5
23
  */
6
24
  export function isEmpty(options) {
@@ -48,7 +66,25 @@ export function isEmpty(options) {
48
66
  }, options);
49
67
  }
50
68
  /**
51
- * Checks if the value is not empty. Value should be string, array, set, map or object
69
+ * Checks that the value is not empty. The value should be a string, array,
70
+ * Set, Map, Buffer, ArrayBuffer, or plain object.
71
+ *
72
+ * Unlike `isEmpty`, nullish input is rejected here rather than treated as
73
+ * passing, and `Date` instances always pass.
74
+ *
75
+ * @param options - Validation options (`onFail`, `coerce`, ...).
76
+ * @returns The input value unchanged when it is considered non-empty.
77
+ * @throws `Value must not be empty` for `null`/`undefined`/an empty string,
78
+ * `Value must not be NaN` for `NaN`, `Array must not be empty`, `Set must
79
+ * not be empty`, `Map must not be empty`, `Buffer must not be empty`,
80
+ * `ArrayBuffer must not be empty`, or `Object must not be empty`, depending
81
+ * on the input's type.
82
+ * @example
83
+ * ```ts
84
+ * isNotEmpty('abc'); // => 'abc'
85
+ * isNotEmpty(''); // throws ValidationError: "Value must not be empty"
86
+ * isNotEmpty([]); // throws ValidationError: "Array must not be empty"
87
+ * ```
52
88
  * @validator isNotEmpty
53
89
  */
54
90
  export function isNotEmpty(options) {
@@ -1,21 +1,48 @@
1
1
  import { type ValidationOptions } from '../../core/index.js';
2
2
  /**
3
- * Validates if the value is strictly equal ("===") to "compare".
4
- * `null`/`undefined` input is passed through unchanged.
3
+ * Validates that the value is strictly equal (`===`) to `compare`.
4
+ * `null`/`undefined` input is always passed through unchanged, regardless of
5
+ * `compare`.
6
+ *
7
+ * @typeParam T - The type of `compare`.
8
+ * @param compare - The value the input must strictly equal.
9
+ * @param options - Validation options (`onFail`, `coerce`, ...).
10
+ * @returns The input value unchanged when it strictly equals `compare` (or
11
+ * is nullish).
12
+ * @throws `Value must be equal to "<compare>"` if `input !== compare`.
13
+ * @example
14
+ * ```ts
15
+ * vg.isEqual('a')('a'); // => 'a'
16
+ * vg.isEqual('a')('b'); // throws ValidationError: "Value must be equal to..."
17
+ * ```
5
18
  * @validator isEqual
6
19
  */
7
20
  export declare function isEqual<T>(compare: T, options?: isEqual.Options): import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;
8
21
  export declare namespace isEqual {
22
+ /** Options for {@link isEqual} - adds no properties beyond `ValidationOptions`. */
9
23
  interface Options extends ValidationOptions {
10
24
  }
11
25
  }
12
26
  /**
13
- * Validates if the value is not strictly equal ("===") to "compare".
14
- * `null`/`undefined` input is passed through unchanged.
27
+ * Validates that the value is not strictly equal (`===`) to `compare`.
28
+ * `null`/`undefined` input is always passed through unchanged, regardless of
29
+ * `compare`.
30
+ *
31
+ * @param compare - The value the input must not strictly equal.
32
+ * @param options - Validation options (`onFail`, `coerce`, ...).
33
+ * @returns The input value unchanged when it does not strictly equal
34
+ * `compare` (or is nullish).
35
+ * @throws `Value must not be equal to "<compare>"` if `input === compare`.
36
+ * @example
37
+ * ```ts
38
+ * vg.isNotEqual('a')('b'); // => 'b'
39
+ * vg.isNotEqual('a')('a'); // throws ValidationError: "Value must not be equal to..."
40
+ * ```
15
41
  * @validator isNotEqual
16
42
  */
17
43
  export declare function isNotEqual(compare: any, options?: isNotEqual.Options): import("../../core/validator.js").Validator<any, any, import("../../core/types.js").ExecutionOptions>;
18
44
  export declare namespace isNotEqual {
45
+ /** Options for {@link isNotEqual} - adds no properties beyond `ValidationOptions`. */
19
46
  interface Options extends ValidationOptions {
20
47
  }
21
48
  }