@validup/validator-js 2.0.0 → 2.0.2

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.
package/README.md CHANGED
@@ -1,6 +1,12 @@
1
- # @validup/validator-js 🛡️
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/tada5hi/validup/HEAD/packages/validator-js/assets/logo.svg" alt="@validup/validator-js" width="128" height="128" />
3
+ </p>
2
4
 
3
- A [validup](https://www.npmjs.com/package/validup) integration for [validator.js](https://github.com/validatorjs/validator.js) — pre-baked factories for the common string validators (`isEmail`, `isLength`, `isInt`, …) plus a generic `createValidator(fn, …)` for the long tail.
5
+ <h1 align="center">@validup/validator-js</h1>
6
+
7
+ <p align="center">
8
+ <b>A <a href="https://www.npmjs.com/package/validup">validup</a> integration for <a href="https://github.com/validatorjs/validator.js">validator.js</a>: pre-baked factories for the common string rules, plus a generic wrap for the long tail.</b>
9
+ </p>
4
10
 
5
11
  Each factory stamps the right validup [`IssueCode`](https://www.npmjs.com/package/validup#issue-codes) on failure, with structured `data` matching the i18n catalog's placeholders. Drop into `@ilingo/validup` for free per-rule translations.
6
12
 
@@ -61,24 +67,24 @@ const valid = await container.run({
61
67
 
62
68
  ## Factories
63
69
 
64
- Every factory takes a **flat options object** — the validup-side `message` override sits alongside the validator.js options for that rule (`BaseFactoryOptions & validator.Is*Options`). No nesting; one shape per call site.
70
+ Every factory takes a **flat options object**: the validup-side `message` override sits alongside the validator.js options for that rule (`BaseFactoryOptions & validator.Is*Options`). No nesting; one shape per call site.
65
71
 
66
72
  | Factory | Options type | Emits | `data` payload |
67
73
  |---------|--------------|-------|------------------|
68
- | `isEmail(opts?)` | `BaseFactoryOptions & validator.IsEmailOptions` | `EMAIL` | — |
69
- | `isURL(opts?)` | `BaseFactoryOptions & validator.IsURLOptions` | `URL` | — |
70
- | `isUUID(opts?)` | `BaseFactoryOptions & { version? }` | `UUID` | — |
71
- | `isIP(opts?)` | `BaseFactoryOptions & { version? }` | `IP_ADDRESS` | — |
72
- | `isMACAddress(opts?)` | `BaseFactoryOptions & validator.IsMACAddressOptions` | `MAC_ADDRESS` | — |
73
- | `isDate(opts?)` | `BaseFactoryOptions & validator.IsDateOptions` | `DATE` | — |
74
- | `isISO8601(opts?)` | `BaseFactoryOptions & validator.IsISO8601Options` | `DATE` | — |
75
- | `isJSON(opts?)` | `BaseFactoryOptions & validator.IsJSONOptions` | `JSON` | — |
76
- | `isBase64(opts?)` | `BaseFactoryOptions & validator.IsBase64Options` | `BASE64` | — |
74
+ | `isEmail(opts?)` | `BaseFactoryOptions & validator.IsEmailOptions` | `EMAIL` | - |
75
+ | `isURL(opts?)` | `BaseFactoryOptions & validator.IsURLOptions` | `URL` | - |
76
+ | `isUUID(opts?)` | `BaseFactoryOptions & { version? }` | `UUID` | - |
77
+ | `isIP(opts?)` | `BaseFactoryOptions & { version? }` | `IP_ADDRESS` | - |
78
+ | `isMACAddress(opts?)` | `BaseFactoryOptions & validator.IsMACAddressOptions` | `MAC_ADDRESS` | - |
79
+ | `isDate(opts?)` | `BaseFactoryOptions & validator.IsDateOptions` | `DATE` | - |
80
+ | `isISO8601(opts?)` | `BaseFactoryOptions & validator.IsISO8601Options` | `DATE` | - |
81
+ | `isJSON(opts?)` | `BaseFactoryOptions & validator.IsJSONOptions` | `JSON` | - |
82
+ | `isBase64(opts?)` | `BaseFactoryOptions & validator.IsBase64Options` | `BASE64` | - |
77
83
  | `isStrongPassword(opts?)` | `BaseFactoryOptions & validator.StrongPasswordOptions` | `STRONG_PASSWORD` | `{ minLength?, minLowercase?, minUppercase?, minNumbers?, minSymbols? }` |
78
- | `isAlpha(opts?)` | `BaseFactoryOptions & validator.IsAlphaOptions & { locale? }` | `ALPHA` | — |
79
- | `isAlphanumeric(opts?)` | `BaseFactoryOptions & validator.IsAlphanumericOptions & { locale? }` | `ALPHA_NUM` | — |
80
- | `isNumeric(opts?)` | `BaseFactoryOptions & validator.IsNumericOptions` | `NUMERIC` | — |
81
- | `isDecimal(opts?)` | `BaseFactoryOptions & validator.IsDecimalOptions` | `DECIMAL` | — |
84
+ | `isAlpha(opts?)` | `BaseFactoryOptions & validator.IsAlphaOptions & { locale? }` | `ALPHA` | - |
85
+ | `isAlphanumeric(opts?)` | `BaseFactoryOptions & validator.IsAlphanumericOptions & { locale? }` | `ALPHA_NUM` | - |
86
+ | `isNumeric(opts?)` | `BaseFactoryOptions & validator.IsNumericOptions` | `NUMERIC` | - |
87
+ | `isDecimal(opts?)` | `BaseFactoryOptions & validator.IsDecimalOptions` | `DECIMAL` | - |
82
88
  | `isInt(opts?)` | `BaseFactoryOptions & validator.IsIntOptions` | `INTEGER` *or* `MIN_VALUE` / `MAX_VALUE` | `{ min }` / `{ max }` on range failure |
83
89
  | `isFloat(opts?)` | `BaseFactoryOptions & validator.IsFloatOptions` | `DECIMAL` *or* `MIN_VALUE` / `MAX_VALUE` | `{ min }` / `{ max }` on range failure |
84
90
  | `isLength(opts?)` | `BaseFactoryOptions & validator.IsLengthOptions` | `MIN_LENGTH` *or* `MAX_LENGTH` | `{ min }` / `{ max }` |
@@ -96,13 +102,13 @@ isAlpha({ locale: 'de-DE', ignore: '-' });
96
102
  isStrongPassword({ minLength: 12, minNumbers: 2 });
97
103
  ```
98
104
 
99
- **`isInt` / `isFloat` / `isLength` are intentionally split.** A failure can be either a type mismatch (`'abc'` for an integer) or a range mismatch (`5` when min is `18`). Validator.js collapses both into a single boolean, so the factory checks them in order and emits the most specific code for each case — that's what makes the i18n story useful ("must be between 18 and 120" vs. "must be an integer" are different messages).
105
+ **`isInt` / `isFloat` / `isLength` are intentionally split.** A failure can be either a type mismatch (`'abc'` for an integer) or a range mismatch (`5` when min is `18`). Validator.js collapses both into a single boolean, so the factory checks them in order and emits the most specific code for each case; that's what makes the i18n story useful ("must be between 18 and 120" vs. "must be an integer" are different messages).
100
106
 
101
- **`equals` resolves its comparison target from `ctx.data`.** When `expectedValue` is omitted, `key` is used as a pathtrace path into the current container's input — so `equals('password')` mounted on `confirm` compares against `ctx.data.password` (the password-confirmation pattern). Pass `expectedValue` for a fixed literal target; `key` always supplies the `{ other }` label for i18n templates.
107
+ **`equals` resolves its comparison target from `ctx.data`.** When `expectedValue` is omitted, `key` is used as a pathtrace path into the current container's input, so `equals('password')` mounted on `confirm` compares against `ctx.data.password` (the password-confirmation pattern). Pass `expectedValue` for a fixed literal target; `key` always supplies the `{ other }` label for i18n templates.
102
108
 
103
- **Result caching.** Every factory returns a `ValidatorDescriptor` that participates in validup's [result cache](https://validup.tada5hi.net/guide/caching) by default — every shipped factory is a deterministic function of `ctx.value`, so cached `(value, context, group)` snapshots replay without re-running validator.js. The one exception is `equals(key)` **without** `expectedValue`, which stamps `sideEffect: true` automatically because the comparison target comes from `ctx.data[key]` (a sibling field the snapshot doesn't capture). When `expectedValue` is provided, `equals` is pure and participates in the cache like the rest.
109
+ **Result caching.** Every factory returns a `ValidatorDescriptor` that participates in validup's [result cache](https://validup.tada5hi.net/guide/caching) by default: every shipped factory is a deterministic function of `ctx.value`, so cached `(value, context, group)` snapshots replay without re-running validator.js. The one exception is `equals(key)` **without** `expectedValue`, which stamps `sideEffect: true` automatically because the comparison target comes from `ctx.data[key]` (a sibling field the snapshot doesn't capture). When `expectedValue` is provided, `equals` is pure and participates in the cache like the rest.
104
110
 
105
- ## Generic wrap — `createValidator`
111
+ ## Generic wrap: `createValidator`
106
112
 
107
113
  For validators not pre-baked (`isCreditCard`, `isJWT`, `isMobilePhone`, `isPostalCode`, …):
108
114
 
@@ -127,13 +133,13 @@ container.mount('phone', createValidator(
127
133
 
128
134
  `createValidator(fn, { code, message, data?, sideEffect? })`:
129
135
 
130
- - `fn` — any function with the signature `(value: string, ...args: any[]) => boolean`. validator.js's predicates all fit.
131
- - `code` — the validup `IssueCode` (or any project-specific string) attached to the resulting `IssueItem`. `IssueItem.code` widens to `IssueCode | (string & {})`, so ad-hoc strings are accepted.
132
- - `message` — fallback English message on `IssueItem.message`. Always set this — i18n catalogs key off `code`, but consumers without an i18n setup see the message directly.
133
- - `data` — structured payload surfaced on `IssueItem.data`. Optional; templates that reference placeholders (`{locale}`, `{min}`, …) resolve against this.
134
- - `sideEffect` — optional flag for the rare case where the wrapped predicate captures external state. Default is cache-eligible.
136
+ - `fn`: any function with the signature `(value: string, ...args: any[]) => boolean`. validator.js's predicates all fit.
137
+ - `code`: the validup `IssueCode` (or any project-specific string) attached to the resulting `IssueItem`. `IssueItem.code` widens to `IssueCode | (string & {})`, so ad-hoc strings are accepted.
138
+ - `message`: fallback English message on `IssueItem.message`. Always set this; i18n catalogs key off `code`, but consumers without an i18n setup see the message directly.
139
+ - `data`: structured payload surfaced on `IssueItem.data`. Optional; templates that reference placeholders (`{locale}`, `{min}`, …) resolve against this.
140
+ - `sideEffect`: optional flag for the rare case where the wrapped predicate captures external state. Default is cache-eligible.
135
141
 
136
- The wrap stringifies `ctx.value` via `toValidatorString` before calling `fn` — same as the factories — so consumers can mount on `number`-shaped fields without manual coercion.
142
+ The wrap stringifies `ctx.value` via `toValidatorString` before calling `fn` (same as the factories) so consumers can mount on `number`-shaped fields without manual coercion.
137
143
 
138
144
  ## Per-call message override
139
145
 
@@ -148,7 +154,7 @@ Defaults match `@ilingo/validup`'s `en` catalog wording, so consumers without i1
148
154
 
149
155
  ## Why not express-validator?
150
156
 
151
- express-validator wraps validator.js in a chain API meant for Express middleware. validup doesn't use Express's `req` / `body` / `query` routing — it has its own `Container.mount` for path traversal. The chain abstraction added complexity (no machine-readable validator identity through `ValidationError`, so codes had to come from `.withMessage({ code, message })` opt-ins) without payoff.
157
+ express-validator wraps validator.js in a chain API meant for Express middleware. validup doesn't use Express's `req` / `body` / `query` routing; it has its own `Container.mount` for path traversal. The chain abstraction added complexity (no machine-readable validator identity through `ValidationError`, so codes had to come from `.withMessage({ code, message })` opt-ins) without payoff.
152
158
 
153
159
  `@validup/validator-js` replaces `@validup/express-validator` outright. Migration is mechanical:
154
160
 
@@ -0,0 +1,22 @@
1
+ <svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="vjs-title">
2
+ <title id="vjs-title">@validup/validator-js logo: a shield holding a rule checklist, the last rule highlighted</title>
3
+
4
+ <defs>
5
+ <linearGradient id="vjs-shield" x1="32" y1="16" x2="224" y2="240" gradientUnits="userSpaceOnUse">
6
+ <stop stop-color="#FBBF24" />
7
+ <stop offset="1" stop-color="#EA580C" />
8
+ </linearGradient>
9
+ </defs>
10
+
11
+ <path fill="url(#vjs-shield)" d="M128 16 L32 56 V128 C32 181.6 69.6 229.6 128 240 C186.4 229.6 224 181.6 224 128 V56 Z" />
12
+
13
+ <!-- one pre-baked rule per line -->
14
+ <path stroke="#FFFFFF" stroke-width="13" stroke-linecap="round" stroke-linejoin="round" d="M70 90 L80 100 L100 78" />
15
+ <rect x="116" y="82" width="72" height="16" rx="8" fill="#FFFFFF" />
16
+
17
+ <path stroke="#FFFFFF" stroke-width="13" stroke-linecap="round" stroke-linejoin="round" stroke-opacity="0.8" d="M70 126 L80 136 L100 114" />
18
+ <rect x="116" y="118" width="56" height="16" rx="8" fill="#FFFFFF" fill-opacity="0.8" />
19
+
20
+ <path stroke="#3B0764" stroke-width="13" stroke-linecap="round" stroke-linejoin="round" d="M70 162 L80 172 L100 150" />
21
+ <rect x="116" y="154" width="64" height="16" rx="8" fill="#3B0764" />
22
+ </svg>
package/dist/index.d.mts CHANGED
@@ -1,14 +1,5 @@
1
1
  import { ValidatorDescriptor } from "validup";
2
- //#region src/module.d.ts
3
- /**
4
- * Shape of a validator.js boolean predicate. The first argument is always
5
- * the string to test; subsequent arguments are validator-specific options.
6
- */
7
2
  type ValidatorJsFn = (value: string, ...args: any[]) => boolean;
8
- /**
9
- * Options accepted by every factory (and {@link createValidator}). The
10
- * factory layers vocabulary-specific fields on top of this shape.
11
- */
12
3
  interface BaseFactoryOptions {
13
4
  /**
14
5
  * Override the default English message produced by the factory. The
@@ -17,11 +8,6 @@ interface BaseFactoryOptions {
17
8
  */
18
9
  message?: string;
19
10
  }
20
- /**
21
- * Options accepted by {@link createValidator}. The vocabulary code is
22
- * required — that's the entire point of the generic wrap; if you just
23
- * want `VALUE_INVALID`, hand-roll a `Validator` instead.
24
- */
25
11
  interface CreateValidatorOptions extends BaseFactoryOptions {
26
12
  /**
27
13
  * `IssueCode` value (or any project-specific string) attached to the
@@ -34,13 +20,26 @@ interface CreateValidatorOptions extends BaseFactoryOptions {
34
20
  */
35
21
  data?: Record<string, unknown>;
36
22
  }
23
+ /**
24
+ * Shape of a validator.js boolean predicate. The first argument is always
25
+ * the string to test; subsequent arguments are validator-specific options.
26
+ */
27
+ /**
28
+ * Options accepted by every factory (and {@link createValidator}). The
29
+ * factory layers vocabulary-specific fields on top of this shape.
30
+ */
31
+ /**
32
+ * Options accepted by {@link createValidator}. The vocabulary code is
33
+ * required — that's the entire point of the generic wrap; if you just
34
+ * want `VALUE_INVALID`, hand-roll a `Validator` instead.
35
+ */
37
36
  /**
38
37
  * Build a string representation suitable for validator.js. validator.js
39
38
  * functions expect strings; for numbers and booleans we use `String(...)`
40
39
  * so consumers can mount `isInt()` on a `number`-shaped field without
41
40
  * pre-stringifying.
42
41
  */
43
- declare function toValidatorString(value: unknown): string;
42
+ export declare function toValidatorString(value: unknown): string;
44
43
  /**
45
44
  * Generic wrap for any validator.js function we don't ship a pre-baked
46
45
  * factory for. The wrapped validator stringifies `ctx.value`, calls the
@@ -67,17 +66,15 @@ declare function toValidatorString(value: unknown): string;
67
66
  * predicate captures external state and the caller knowingly opts
68
67
  * into that, pass `sideEffect: true` to bypass the cache.
69
68
  */
70
- declare function createValidator<C = unknown>(fn: ValidatorJsFn, options: CreateValidatorOptions & {
69
+ export declare function createValidator<C = unknown>(fn: ValidatorJsFn, options: CreateValidatorOptions & {
71
70
  sideEffect?: boolean;
72
71
  }): ValidatorDescriptor<C>;
73
- //#endregion
74
- //#region src/factories/comparison.d.ts
75
72
  /**
76
73
  * Factory: validator.js `matches`. Emits `IssueCode.PATTERN` on failure
77
74
  * with `data: { pattern: string }` (the regex source, no flags) so
78
75
  * i18n templates can quote it.
79
76
  */
80
- declare function matches<C = unknown>(pattern: RegExp | string, options?: BaseFactoryOptions & {
77
+ export declare function matches<C = unknown>(pattern: RegExp | string, options?: BaseFactoryOptions & {
81
78
  modifiers?: string;
82
79
  }): ValidatorDescriptor<C>;
83
80
  /**
@@ -101,11 +98,9 @@ declare function matches<C = unknown>(pattern: RegExp | string, options?: BaseFa
101
98
  * branch so the framework re-runs it on every invocation; otherwise a
102
99
  * `passwordConfirm` check would stay stale after `password` changes.
103
100
  */
104
- declare function equals<C = unknown>(key: string, options?: BaseFactoryOptions & {
101
+ export declare function equals<C = unknown>(key: string, options?: BaseFactoryOptions & {
105
102
  expectedValue?: string;
106
103
  }): ValidatorDescriptor<C>;
107
- //#endregion
108
- //#region src/factories/length.d.ts
109
104
  /**
110
105
  * Factory: validator.js `isLength`. Detects which bound failed at
111
106
  * validation time so the resulting issue carries a useful vocabulary
@@ -118,9 +113,7 @@ declare function equals<C = unknown>(key: string, options?: BaseFactoryOptions &
118
113
  * passes. `message` overrides the default English string for both bound
119
114
  * failures.
120
115
  */
121
- declare function isLength<C = unknown>(options?: BaseFactoryOptions & validator.IsLengthOptions): ValidatorDescriptor<C>;
122
- //#endregion
123
- //#region src/factories/string-format.d.ts
116
+ export declare function isLength<C = unknown>(options?: BaseFactoryOptions & validator.IsLengthOptions): ValidatorDescriptor<C>;
124
117
  /**
125
118
  * Factory: validator.js `isEmail`. Emits `IssueCode.EMAIL` on failure.
126
119
  *
@@ -128,11 +121,11 @@ declare function isLength<C = unknown>(options?: BaseFactoryOptions & validator.
128
121
  * (`require_display_name`, `allow_utf8_local_part`, …) directly alongside
129
122
  * the validup-side `message` override.
130
123
  */
131
- declare function isEmail<C = unknown>(options?: BaseFactoryOptions & validator.IsEmailOptions): ValidatorDescriptor<C>;
124
+ export declare function isEmail<C = unknown>(options?: BaseFactoryOptions & validator.IsEmailOptions): ValidatorDescriptor<C>;
132
125
  /**
133
126
  * Factory: validator.js `isURL`. Emits `IssueCode.URL` on failure.
134
127
  */
135
- declare function isURL<C = unknown>(options?: BaseFactoryOptions & validator.IsURLOptions): ValidatorDescriptor<C>;
128
+ export declare function isURL<C = unknown>(options?: BaseFactoryOptions & validator.IsURLOptions): ValidatorDescriptor<C>;
136
129
  /**
137
130
  * Factory: validator.js `isUUID`. Emits `IssueCode.UUID` on failure.
138
131
  *
@@ -140,7 +133,7 @@ declare function isURL<C = unknown>(options?: BaseFactoryOptions & validator.IsU
140
133
  * (`'1' | '2' | '3' | '4' | '5' | 'all' | 1 | …`). Promoted into the
141
134
  * options object so the call site is consistent with the other factories.
142
135
  */
143
- declare function isUUID<C = unknown>(options?: BaseFactoryOptions & {
136
+ export declare function isUUID<C = unknown>(options?: BaseFactoryOptions & {
144
137
  version?: validator.UUIDVersion;
145
138
  }): ValidatorDescriptor<C>;
146
139
  /**
@@ -148,31 +141,31 @@ declare function isUUID<C = unknown>(options?: BaseFactoryOptions & {
148
141
  *
149
142
  * `version` mirrors validator.js's positional second argument.
150
143
  */
151
- declare function isIP<C = unknown>(options?: BaseFactoryOptions & {
144
+ export declare function isIP<C = unknown>(options?: BaseFactoryOptions & {
152
145
  version?: '4' | '6' | 4 | 6;
153
146
  }): ValidatorDescriptor<C>;
154
147
  /**
155
148
  * Factory: validator.js `isMACAddress`. Emits `IssueCode.MAC_ADDRESS` on failure.
156
149
  */
157
- declare function isMACAddress<C = unknown>(options?: BaseFactoryOptions & validator.IsMACAddressOptions): ValidatorDescriptor<C>;
150
+ export declare function isMACAddress<C = unknown>(options?: BaseFactoryOptions & validator.IsMACAddressOptions): ValidatorDescriptor<C>;
158
151
  /**
159
152
  * Factory: validator.js `isDate`. Emits `IssueCode.DATE` on failure.
160
153
  */
161
- declare function isDate<C = unknown>(options?: BaseFactoryOptions & validator.IsDateOptions): ValidatorDescriptor<C>;
154
+ export declare function isDate<C = unknown>(options?: BaseFactoryOptions & validator.IsDateOptions): ValidatorDescriptor<C>;
162
155
  /**
163
156
  * Factory: validator.js `isISO8601`. Emits `IssueCode.DATE` on failure
164
157
  * (same code as `isDate` — both produce the "is this a parseable date"
165
158
  * outcome from the consumer's perspective).
166
159
  */
167
- declare function isISO8601<C = unknown>(options?: BaseFactoryOptions & validator.IsISO8601Options): ValidatorDescriptor<C>;
160
+ export declare function isISO8601<C = unknown>(options?: BaseFactoryOptions & validator.IsISO8601Options): ValidatorDescriptor<C>;
168
161
  /**
169
162
  * Factory: validator.js `isJSON`. Emits `IssueCode.JSON` on failure.
170
163
  */
171
- declare function isJSON<C = unknown>(options?: BaseFactoryOptions & validator.IsJSONOptions): ValidatorDescriptor<C>;
164
+ export declare function isJSON<C = unknown>(options?: BaseFactoryOptions & validator.IsJSONOptions): ValidatorDescriptor<C>;
172
165
  /**
173
166
  * Factory: validator.js `isBase64`. Emits `IssueCode.BASE64` on failure.
174
167
  */
175
- declare function isBase64<C = unknown>(options?: BaseFactoryOptions & validator.IsBase64Options): ValidatorDescriptor<C>;
168
+ export declare function isBase64<C = unknown>(options?: BaseFactoryOptions & validator.IsBase64Options): ValidatorDescriptor<C>;
176
169
  /**
177
170
  * Factory: validator.js `isStrongPassword`. Emits
178
171
  * `IssueCode.STRONG_PASSWORD` on failure. `data` carries only the
@@ -191,32 +184,30 @@ declare function isBase64<C = unknown>(options?: BaseFactoryOptions & validator.
191
184
  * do NOT appear in `data` — i18n templates would never want to render
192
185
  * "must score at least N points per unique character" to the user.
193
186
  */
194
- declare function isStrongPassword<C = unknown>(options?: BaseFactoryOptions & validator.StrongPasswordOptions): ValidatorDescriptor<C>;
195
- //#endregion
196
- //#region src/factories/type-assertions.d.ts
187
+ export declare function isStrongPassword<C = unknown>(options?: BaseFactoryOptions & validator.StrongPasswordOptions): ValidatorDescriptor<C>;
197
188
  /**
198
189
  * Factory: validator.js `isAlpha`. Emits `IssueCode.ALPHA` on failure.
199
190
  *
200
191
  * `locale` (validator.js's positional second arg) is promoted into the
201
192
  * flat options object; everything else passes through as `IsAlphaOptions`.
202
193
  */
203
- declare function isAlpha<C = unknown>(options?: BaseFactoryOptions & validator.IsAlphaOptions & {
194
+ export declare function isAlpha<C = unknown>(options?: BaseFactoryOptions & validator.IsAlphaOptions & {
204
195
  locale?: validator.AlphaLocale;
205
196
  }): ValidatorDescriptor<C>;
206
197
  /**
207
198
  * Factory: validator.js `isAlphanumeric`. Emits `IssueCode.ALPHA_NUM` on failure.
208
199
  */
209
- declare function isAlphanumeric<C = unknown>(options?: BaseFactoryOptions & validator.IsAlphanumericOptions & {
200
+ export declare function isAlphanumeric<C = unknown>(options?: BaseFactoryOptions & validator.IsAlphanumericOptions & {
210
201
  locale?: validator.AlphanumericLocale;
211
202
  }): ValidatorDescriptor<C>;
212
203
  /**
213
204
  * Factory: validator.js `isNumeric`. Emits `IssueCode.NUMERIC` on failure.
214
205
  */
215
- declare function isNumeric<C = unknown>(options?: BaseFactoryOptions & validator.IsNumericOptions): ValidatorDescriptor<C>;
206
+ export declare function isNumeric<C = unknown>(options?: BaseFactoryOptions & validator.IsNumericOptions): ValidatorDescriptor<C>;
216
207
  /**
217
208
  * Factory: validator.js `isDecimal`. Emits `IssueCode.DECIMAL` on failure.
218
209
  */
219
- declare function isDecimal<C = unknown>(options?: BaseFactoryOptions & validator.IsDecimalOptions): ValidatorDescriptor<C>;
210
+ export declare function isDecimal<C = unknown>(options?: BaseFactoryOptions & validator.IsDecimalOptions): ValidatorDescriptor<C>;
220
211
  /**
221
212
  * Factory: validator.js `isInt`. Resolves the right vocabulary code
222
213
  * based on what failed:
@@ -229,7 +220,7 @@ declare function isDecimal<C = unknown>(options?: BaseFactoryOptions & validator
229
220
  * - Value above `max` (inclusive) or `lt` (exclusive) → `IssueCode.MAX_VALUE`
230
221
  * (data: `{ max }`). Same treatment as `gt` → `data.max` is `options.lt`.
231
222
  */
232
- declare function isInt<C = unknown>(options?: BaseFactoryOptions & validator.IsIntOptions): ValidatorDescriptor<C>;
223
+ export declare function isInt<C = unknown>(options?: BaseFactoryOptions & validator.IsIntOptions): ValidatorDescriptor<C>;
233
224
  /**
234
225
  * Factory: validator.js `isFloat`. Like {@link isInt} but for decimal
235
226
  * numbers — type failure emits `IssueCode.DECIMAL`; range bounds emit
@@ -247,7 +238,5 @@ declare function isInt<C = unknown>(options?: BaseFactoryOptions & validator.IsI
247
238
  * instead of `MIN_VALUE` / `MAX_VALUE`. Use the default locale (or
248
239
  * normalize the input upstream) when precise range codes matter for i18n.
249
240
  */
250
- declare function isFloat<C = unknown>(options?: BaseFactoryOptions & validator.IsFloatOptions): ValidatorDescriptor<C>;
251
- //#endregion
252
- export { BaseFactoryOptions, CreateValidatorOptions, ValidatorJsFn, createValidator, equals, isAlpha, isAlphanumeric, isBase64, isDate, isDecimal, isEmail, isFloat, isIP, isISO8601, isInt, isJSON, isLength, isMACAddress, isNumeric, isStrongPassword, isURL, isUUID, matches, toValidatorString };
253
- //# sourceMappingURL=index.d.mts.map
241
+ export declare function isFloat<C = unknown>(options?: BaseFactoryOptions & validator.IsFloatOptions): ValidatorDescriptor<C>;
242
+ export type { BaseFactoryOptions, CreateValidatorOptions, ValidatorJsFn };
package/dist/index.mjs CHANGED
@@ -2,7 +2,20 @@ import { getPathValue } from "pathtrace";
2
2
  import validator from "validator";
3
3
  import { IssueCode } from "@ebec/core";
4
4
  import { createValidupError, defineValidator } from "validup";
5
- //#region src/module.ts
5
+ // src/module.ts
6
+ /**
7
+ * Shape of a validator.js boolean predicate. The first argument is always
8
+ * the string to test; subsequent arguments are validator-specific options.
9
+ */
10
+ /**
11
+ * Options accepted by every factory (and {@link createValidator}). The
12
+ * factory layers vocabulary-specific fields on top of this shape.
13
+ */
14
+ /**
15
+ * Options accepted by {@link createValidator}. The vocabulary code is
16
+ * required — that's the entire point of the generic wrap; if you just
17
+ * want `VALUE_INVALID`, hand-roll a `Validator` instead.
18
+ */
6
19
  /**
7
20
  * Build a string representation suitable for validator.js. validator.js
8
21
  * functions expect strings; for numbers and booleans we use `String(...)`
@@ -52,8 +65,7 @@ function createValidator(fn, options) {
52
65
  }
53
66
  });
54
67
  }
55
- //#endregion
56
- //#region src/factories/comparison.ts
68
+ // src/factories/comparison.ts
57
69
  /**
58
70
  * Factory: validator.js `matches`. Emits `IssueCode.PATTERN` on failure
59
71
  * with `data: { pattern: string }` (the regex source, no flags) so
@@ -99,8 +111,7 @@ function equals(key, options = {}) {
99
111
  }
100
112
  });
101
113
  }
102
- //#endregion
103
- //#region src/factories/length.ts
114
+ // src/factories/length.ts
104
115
  /**
105
116
  * Factory: validator.js `isLength`. Detects which bound failed at
106
117
  * validation time so the resulting issue carries a useful vocabulary
@@ -124,8 +135,7 @@ function isLength(options = {}) {
124
135
  throw createValidupError(ctx.value, IssueCode.VALUE_INVALID, options.message ?? "The value has an invalid length");
125
136
  } });
126
137
  }
127
- //#endregion
128
- //#region src/factories/string-format.ts
138
+ // src/factories/string-format.ts
129
139
  /**
130
140
  * Factory: validator.js `isEmail`. Emits `IssueCode.EMAIL` on failure.
131
141
  *
@@ -282,8 +292,7 @@ function isStrongPassword(options = {}) {
282
292
  throw createValidupError(ctx.value, IssueCode.STRONG_PASSWORD, message, { ...paramsTemplate });
283
293
  } });
284
294
  }
285
- //#endregion
286
- //#region src/factories/type-assertions.ts
295
+ // src/factories/type-assertions.ts
287
296
  /**
288
297
  * Factory: validator.js `isAlpha`. Emits `IssueCode.ALPHA` on failure.
289
298
  *
@@ -408,7 +417,6 @@ function isFloat(options = {}) {
408
417
  return ctx.value;
409
418
  } });
410
419
  }
411
- //#endregion
412
420
  export { createValidator, equals, isAlpha, isAlphanumeric, isBase64, isDate, isDecimal, isEmail, isFloat, isIP, isISO8601, isInt, isJSON, isLength, isMACAddress, isNumeric, isStrongPassword, isURL, isUUID, matches, toValidatorString };
413
421
 
414
422
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/module.ts","../src/factories/comparison.ts","../src/factories/length.ts","../src/factories/string-format.ts","../src/factories/type-assertions.ts"],"sourcesContent":["/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\n\n/**\n * Shape of a validator.js boolean predicate. The first argument is always\n * the string to test; subsequent arguments are validator-specific options.\n */\nexport type ValidatorJsFn = (value: string, ...args: any[]) => boolean;\n\n/**\n * Options accepted by every factory (and {@link createValidator}). The\n * factory layers vocabulary-specific fields on top of this shape.\n */\nexport interface BaseFactoryOptions {\n /**\n * Override the default English message produced by the factory. The\n * default tracks `@ilingo/validup`'s `en` catalog so the same wording\n * surfaces with and without i18n.\n */\n message?: string;\n}\n\n/**\n * Options accepted by {@link createValidator}. The vocabulary code is\n * required — that's the entire point of the generic wrap; if you just\n * want `VALUE_INVALID`, hand-roll a `Validator` instead.\n */\nexport interface CreateValidatorOptions extends BaseFactoryOptions {\n /**\n * `IssueCode` value (or any project-specific string) attached to the\n * `IssueItem` on failure.\n */\n code: string;\n /**\n * Optional structured payload surfaced on `IssueItem.data` — what\n * the i18n template's `{{placeholders}}` resolve against.\n */\n data?: Record<string, unknown>;\n}\n\n/**\n * Build a string representation suitable for validator.js. validator.js\n * functions expect strings; for numbers and booleans we use `String(...)`\n * so consumers can mount `isInt()` on a `number`-shaped field without\n * pre-stringifying.\n */\nexport function toValidatorString(value: unknown): string {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (value === null || value === undefined) return '';\n return String(value);\n}\n\n/**\n * Generic wrap for any validator.js function we don't ship a pre-baked\n * factory for. The wrapped validator stringifies `ctx.value`, calls the\n * validator.js predicate, and throws a `ValidupError` carrying the\n * supplied `code` (+ optional `data`) on failure.\n *\n * @example\n * import validator from 'validator';\n * import { createValidator } from '@validup/validator-js';\n *\n * container.mount('card', createValidator(validator.isCreditCard, {\n * code: 'credit_card',\n * message: 'Invalid credit card number',\n * }));\n *\n * For the common cases — `email()`, `isLength()`, `isInt()` etc. — reach\n * for the pre-baked factories instead; they bake the right vocabulary\n * code and `data` in for you.\n *\n * The returned descriptor participates in the validup result cache by\n * default — validator.js's `ValidatorJsFn` signature is synchronous\n * and only inspects the stringified value, so the outcome is a pure\n * function of `(ctx.value, ctx.context, ctx.group)`. If the wrapped\n * predicate captures external state and the caller knowingly opts\n * into that, pass `sideEffect: true` to bypass the cache.\n */\nexport function createValidator<C = unknown>(\n fn: ValidatorJsFn,\n options: CreateValidatorOptions & { sideEffect?: boolean },\n): ValidatorDescriptor<C> {\n const fallbackCode = options.code || IssueCode.VALUE_INVALID;\n const fallbackMessage = options.message ?? 'The value is invalid';\n\n return defineValidator<C>({\n sideEffect: options.sideEffect,\n run: (ctx) => {\n const stringified = toValidatorString(ctx.value);\n if (fn(stringified)) {\n return ctx.value;\n }\n throw createValidupError(ctx.value, fallbackCode, fallbackMessage, options.data);\n },\n });\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { getPathValue } from 'pathtrace';\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `matches`. Emits `IssueCode.PATTERN` on failure\n * with `data: { pattern: string }` (the regex source, no flags) so\n * i18n templates can quote it.\n */\nexport function matches<C = unknown>(pattern: RegExp | string, options: BaseFactoryOptions & {\n modifiers?: string,\n} = {}): ValidatorDescriptor<C> {\n const patternSource = typeof pattern === 'string' ? pattern : pattern.source;\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n const ok = typeof pattern === 'string' ?\n validator.matches(s, pattern, options.modifiers) :\n validator.matches(s, pattern);\n if (ok) return ctx.value;\n throw createValidupError(\n ctx.value,\n IssueCode.PATTERN,\n options.message ?? 'The value does not match the expected pattern',\n { pattern: patternSource },\n );\n },\n });\n}\n\n/**\n * Factory: validator.js `equals`. Emits `IssueCode.SAME_AS` on failure\n * with `data: { other: string }` so a translated message can quote the\n * key subject (e.g. \"must equal {{other}}\").\n *\n * `key` is the field-name / label the i18n template should\n * surface. When `expectedValue` is omitted, `key` is also used as a\n * pathtrace path into `ctx.data` to look up the runtime comparison\n * target — so `equals('password')` mounted on `passwordConfirm`\n * compares against `ctx.data.password`. Pass `expectedValue`\n * explicitly to compare against a fixed string instead.\n *\n * **Side-effect contract.** When `expectedValue` is provided the\n * validator is a pure function of `ctx.value` and participates in the\n * result cache like every other factory. When `expectedValue` is\n * omitted the validator reads `ctx.data[key]` — a sibling field —\n * which the cache's `(value, context, group)` snapshot does NOT\n * capture. The factory therefore stamps `sideEffect: true` in that\n * branch so the framework re-runs it on every invocation; otherwise a\n * `passwordConfirm` check would stay stale after `password` changes.\n */\nexport function equals<C = unknown>(key: string, options: BaseFactoryOptions & {\n expectedValue?: string,\n} = {}): ValidatorDescriptor<C> {\n return defineValidator<C>({\n sideEffect: typeof options.expectedValue === 'undefined',\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n const target = options.expectedValue ?? toValidatorString(getPathValue(ctx.data, key));\n if (validator.equals(s, target)) return ctx.value;\n throw createValidupError(\n ctx.value,\n IssueCode.SAME_AS,\n options.message ?? `The value must equal ${key}`,\n { other: key },\n );\n },\n });\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `isLength`. Detects which bound failed at\n * validation time so the resulting issue carries a useful vocabulary\n * code:\n *\n * - Too short → `IssueCode.MIN_LENGTH` (data: `{ min }`).\n * - Too long → `IssueCode.MAX_LENGTH` (data: `{ max }`).\n *\n * Calling without `min` / `max` is allowed but degenerate — every value\n * passes. `message` overrides the default English string for both bound\n * failures.\n */\nexport function isLength<C = unknown>(\n options: BaseFactoryOptions & validator.IsLengthOptions = {},\n): ValidatorDescriptor<C> {\n const { min, max } = options;\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isLength(s, options)) return ctx.value;\n if (typeof min === 'number' && s.length < min) {\n throw createValidupError(\n ctx.value,\n IssueCode.MIN_LENGTH,\n options.message ?? `The minimum length allowed is ${min}`,\n { min },\n );\n }\n if (typeof max === 'number' && s.length > max) {\n throw createValidupError(\n ctx.value,\n IssueCode.MAX_LENGTH,\n options.message ?? `The maximum length allowed is ${max}`,\n { max },\n );\n }\n // Fallback (shouldn't normally hit — `isLength` returned false but\n // neither bound was crossed). The MIN_LENGTH / MAX_LENGTH codes\n // both require their bound in `data`; without a bound we can't\n // honour the vocabulary contract, so emit the generic code.\n if (typeof min === 'number') {\n throw createValidupError(\n ctx.value,\n IssueCode.MIN_LENGTH,\n options.message ?? 'The value has an invalid length',\n { min },\n );\n }\n throw createValidupError(\n ctx.value,\n IssueCode.VALUE_INVALID,\n options.message ?? 'The value has an invalid length',\n );\n },\n });\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `isEmail`. Emits `IssueCode.EMAIL` on failure.\n *\n * Options are flattened — pass validator.js's `IsEmailOptions` keys\n * (`require_display_name`, `allow_utf8_local_part`, …) directly alongside\n * the validup-side `message` override.\n */\nexport function isEmail<C = unknown>(\n options: BaseFactoryOptions & validator.IsEmailOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid email address';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isEmail(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.EMAIL, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isURL`. Emits `IssueCode.URL` on failure.\n */\nexport function isURL<C = unknown>(\n options: BaseFactoryOptions & validator.IsURLOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid URL';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isURL(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.URL, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isUUID`. Emits `IssueCode.UUID` on failure.\n *\n * `version` mirrors validator.js's positional second argument\n * (`'1' | '2' | '3' | '4' | '5' | 'all' | 1 | …`). Promoted into the\n * options object so the call site is consistent with the other factories.\n */\nexport function isUUID<C = unknown>(\n options: BaseFactoryOptions & { version?: validator.UUIDVersion } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid UUID';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isUUID(s, options.version)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.UUID, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isIP`. Emits `IssueCode.IP_ADDRESS` on failure.\n *\n * `version` mirrors validator.js's positional second argument.\n */\nexport function isIP<C = unknown>(\n options: BaseFactoryOptions & { version?: '4' | '6' | 4 | 6 } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid IP address';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isIP(s, options.version)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.IP_ADDRESS, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isMACAddress`. Emits `IssueCode.MAC_ADDRESS` on failure.\n */\nexport function isMACAddress<C = unknown>(\n options: BaseFactoryOptions & validator.IsMACAddressOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid MAC address';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isMACAddress(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.MAC_ADDRESS, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isDate`. Emits `IssueCode.DATE` on failure.\n */\nexport function isDate<C = unknown>(\n options: BaseFactoryOptions & validator.IsDateOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid date';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isDate(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.DATE, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isISO8601`. Emits `IssueCode.DATE` on failure\n * (same code as `isDate` — both produce the \"is this a parseable date\"\n * outcome from the consumer's perspective).\n */\nexport function isISO8601<C = unknown>(\n options: BaseFactoryOptions & validator.IsISO8601Options = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid date';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isISO8601(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.DATE, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isJSON`. Emits `IssueCode.JSON` on failure.\n */\nexport function isJSON<C = unknown>(\n options: BaseFactoryOptions & validator.IsJSONOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not valid JSON';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isJSON(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.JSON, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isBase64`. Emits `IssueCode.BASE64` on failure.\n */\nexport function isBase64<C = unknown>(\n options: BaseFactoryOptions & validator.IsBase64Options = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not valid base64';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isBase64(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.BASE64, message);\n },\n });\n}\n\n/**\n * The subset of `validator.StrongPasswordOptions` keys that describe\n * *strength requirements* — what the consumer wants the password to look\n * like, as opposed to scoring weights (`pointsPerUnique`,\n * `pointsForContainingLower`, …) which only affect validator.js's\n * `returnScore` mode. Only these keys surface on `IssueCode.STRONG_PASSWORD`'s\n * `data` payload, matching the documented vocabulary contract.\n */\nconst STRONG_PASSWORD_REQUIREMENT_KEYS = [\n 'minLength',\n 'minLowercase',\n 'minUppercase',\n 'minNumbers',\n 'minSymbols',\n] as const;\n\ntype StrongPasswordRequirementParams = {\n minLength?: number,\n minLowercase?: number,\n minUppercase?: number,\n minNumbers?: number,\n minSymbols?: number,\n};\n\n/**\n * Factory: validator.js `isStrongPassword`. Emits\n * `IssueCode.STRONG_PASSWORD` on failure. `data` carries only the\n * documented strength-requirement keys (`minLength`, `minLowercase`,\n * `minUppercase`, `minNumbers`, `minSymbols`) so i18n templates can quote\n * them:\n *\n * ```ts\n * isStrongPassword({ minLength: 12, minNumbers: 2 });\n * // → IssueCode.STRONG_PASSWORD, data: { minLength: 12, minNumbers: 2 }\n * ```\n *\n * Scoring weights (`pointsPerUnique`, `pointsForContainingLower`, …) are\n * still forwarded to validator.js so they continue to influence the\n * pass/fail decision (and any `returnScore`-shaped diagnostics), but they\n * do NOT appear in `data` — i18n templates would never want to render\n * \"must score at least N points per unique character\" to the user.\n */\nexport function isStrongPassword<C = unknown>(\n options: BaseFactoryOptions & validator.StrongPasswordOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value does not meet the password strength requirements';\n // Strip validup-only `message` AND `returnScore` before forwarding to\n // validator.js. With `returnScore: true`, validator.js returns a numeric\n // score instead of a boolean — the truthy check below would accept any\n // non-zero score as a pass, so a weak password could squeak through.\n // Drop the flag and force boolean semantics.\n const {\n message: _ignored,\n returnScore: _alsoIgnored,\n ...rest\n } = options;\n // Project `rest` down to the documented strength-requirement subset for\n // the `data` payload. The full `rest` (including scoring weights) is\n // what validator.js sees — but consumer-facing `IssueItem.data`\n // matches the documented vocabulary contract.\n //\n // Build the template once at factory time; clone it per failure so a\n // consumer mutating `issue.data` on one IssueItem can't bleed into a\n // future failure from the same factory.\n const paramsTemplate: StrongPasswordRequirementParams = {};\n for (const key of STRONG_PASSWORD_REQUIREMENT_KEYS) {\n if (typeof rest[key] === 'number') {\n paramsTemplate[key] = rest[key];\n }\n }\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n // validator.js mutates the options argument it receives (merging\n // defaults in-place). Pass a shallow clone so consumer-side\n // `options` and our captured template stay clean.\n const probeOptions = { ...rest } as validator.StrongPasswordOptions;\n if (validator.isStrongPassword(s, probeOptions) === true) return ctx.value;\n throw createValidupError(\n ctx.value,\n IssueCode.STRONG_PASSWORD,\n message,\n { ...paramsTemplate },\n );\n },\n });\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `isAlpha`. Emits `IssueCode.ALPHA` on failure.\n *\n * `locale` (validator.js's positional second arg) is promoted into the\n * flat options object; everything else passes through as `IsAlphaOptions`.\n */\nexport function isAlpha<C = unknown>(\n options: BaseFactoryOptions & validator.IsAlphaOptions & {\n locale?: validator.AlphaLocale,\n } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not alphabetical';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isAlpha(s, options.locale, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.ALPHA, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isAlphanumeric`. Emits `IssueCode.ALPHA_NUM` on failure.\n */\nexport function isAlphanumeric<C = unknown>(\n options: BaseFactoryOptions & validator.IsAlphanumericOptions & {\n locale?: validator.AlphanumericLocale,\n } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value must be alphanumeric';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isAlphanumeric(s, options.locale, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.ALPHA_NUM, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isNumeric`. Emits `IssueCode.NUMERIC` on failure.\n */\nexport function isNumeric<C = unknown>(\n options: BaseFactoryOptions & validator.IsNumericOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value must be numeric';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isNumeric(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.NUMERIC, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isDecimal`. Emits `IssueCode.DECIMAL` on failure.\n */\nexport function isDecimal<C = unknown>(\n options: BaseFactoryOptions & validator.IsDecimalOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value must be a decimal number';\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n if (validator.isDecimal(s, options)) return ctx.value;\n throw createValidupError(ctx.value, IssueCode.DECIMAL, message);\n },\n });\n}\n\n/**\n * The min/gt/max/lt bounds shared by {@link isInt} and {@link isFloat}.\n * A subset of both `validator.IsIntOptions` and `validator.IsFloatOptions`\n * plus the `message` override from `BaseFactoryOptions`.\n */\ntype NumericRangeOptions = {\n min?: number,\n max?: number,\n lt?: number,\n gt?: number,\n message?: string,\n};\n\n/**\n * Shared range ladder for {@link isInt} / {@link isFloat}. Throws the first\n * violated bound and returns `void` when every bound holds.\n *\n * The bounds are checked first-match-wins in `min`, `gt`, `max`, `lt` order,\n * and the emitted codes are deliberately coarser than the option names:\n *\n * - `min` (inclusive) and `gt` (exclusive) both emit `IssueCode.MIN_VALUE`.\n * For `gt`, `data.min` carries `options.gt` — i18n templates can quote the\n * boundary, and the precise inclusive/exclusive wording comes from\n * `message`. Same treatment for `lt` → `IssueCode.MAX_VALUE` with\n * `data.max` carrying `options.lt`. This mapping is an i18n-facing\n * contract; don't split it without a matching catalog change.\n *\n * Type-failure codes (`INTEGER` for `isInt`, `DECIMAL` for `isFloat`) sit\n * OUTSIDE this ladder and stay with their respective factories — which is\n * why the helper needs no code-selecting parameter.\n *\n * `NaN` handling also stays with the caller: `isFloat` skips the ladder for\n * localized input that `Number()` can't parse, while `isInt` reaches it only\n * after `validator.isInt` returned true.\n */\nfunction assertNumericRange(\n received: unknown,\n numeric: number,\n options: NumericRangeOptions,\n): void {\n const {\n min,\n max,\n lt,\n gt,\n } = options;\n if (typeof min === 'number' && numeric < min) {\n throw createValidupError(\n received,\n IssueCode.MIN_VALUE,\n options.message ?? `The value must be greater than or equal to ${min}`,\n { min },\n );\n }\n if (typeof gt === 'number' && numeric <= gt) {\n throw createValidupError(\n received,\n IssueCode.MIN_VALUE,\n options.message ?? `The value must be greater than ${gt}`,\n { min: gt },\n );\n }\n if (typeof max === 'number' && numeric > max) {\n throw createValidupError(\n received,\n IssueCode.MAX_VALUE,\n options.message ?? `The value must be less than or equal to ${max}`,\n { max },\n );\n }\n if (typeof lt === 'number' && numeric >= lt) {\n throw createValidupError(\n received,\n IssueCode.MAX_VALUE,\n options.message ?? `The value must be less than ${lt}`,\n { max: lt },\n );\n }\n}\n\n/**\n * Factory: validator.js `isInt`. Resolves the right vocabulary code\n * based on what failed:\n *\n * - Value isn't an integer at all → `IssueCode.INTEGER`.\n * - Value below `min` (inclusive) or `gt` (exclusive) → `IssueCode.MIN_VALUE`\n * (data: `{ min }`). For `gt`, `data.min` is `options.gt` — i18n\n * templates can quote the boundary; the precise inclusive/exclusive\n * wording comes from `message`.\n * - Value above `max` (inclusive) or `lt` (exclusive) → `IssueCode.MAX_VALUE`\n * (data: `{ max }`). Same treatment as `gt` → `data.max` is `options.lt`.\n */\nexport function isInt<C = unknown>(\n options: BaseFactoryOptions & validator.IsIntOptions = {},\n): ValidatorDescriptor<C> {\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n // Type check first — strip range bounds so a non-integer always\n // surfaces as INTEGER instead of being swallowed by a range failure.\n const isInteger = validator.isInt(s, { allow_leading_zeroes: options.allow_leading_zeroes });\n if (!isInteger) {\n throw createValidupError(\n ctx.value,\n IssueCode.INTEGER,\n options.message ?? 'The value must be an integer',\n );\n }\n assertNumericRange(ctx.value, Number(s), options);\n // Defensive final pass — catches any remaining option we didn't\n // model explicitly (currently none beyond min/max/lt/gt and\n // allow_leading_zeroes). If this fires the failure is a true type\n // mismatch.\n if (!validator.isInt(s, options)) {\n throw createValidupError(\n ctx.value,\n IssueCode.INTEGER,\n options.message ?? 'The value must be an integer',\n );\n }\n return ctx.value;\n },\n });\n}\n\n/**\n * Factory: validator.js `isFloat`. Like {@link isInt} but for decimal\n * numbers — type failure emits `IssueCode.DECIMAL`; range bounds emit\n * `MIN_VALUE` / `MAX_VALUE`. `gt` / `lt` map to `MIN_VALUE` / `MAX_VALUE`\n * the same way `isInt` does — `gt` emits `MIN_VALUE` with `data.min` set to\n * `options.gt`, `lt` emits `MAX_VALUE` with `data.max` set to `options.lt`.\n *\n * **Locale caveat.** validator.js's locale-aware float parsing (e.g.\n * `'123,45'` under `locale: 'de-DE'`) is opaque to the factory — we use\n * `Number(s)` for the explicit range checks, which returns `NaN` for\n * localized strings. When `locale` is set and the input parses to `NaN`,\n * we skip the explicit range checks and fall through to\n * `validator.isFloat(s, options)`, which DOES handle the locale correctly\n * — but a range failure caught there surfaces as `IssueCode.DECIMAL`\n * instead of `MIN_VALUE` / `MAX_VALUE`. Use the default locale (or\n * normalize the input upstream) when precise range codes matter for i18n.\n */\nexport function isFloat<C = unknown>(\n options: BaseFactoryOptions & validator.IsFloatOptions = {},\n): ValidatorDescriptor<C> {\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n // Pre-check honours `locale` so localized floats (e.g. '123,45' for\n // 'de-DE') aren't rejected by the type gate before the range checks\n // get a chance to run.\n if (!validator.isFloat(s, { locale: options.locale })) {\n throw createValidupError(\n ctx.value,\n IssueCode.DECIMAL,\n options.message ?? 'The value must be a decimal number',\n );\n }\n const numeric = Number(s);\n // NaN from a localized input skips the explicit range checks — see\n // the JSDoc above for the resulting code-vs-message trade-off. The\n // guard stays at THIS call site rather than moving into\n // `assertNumericRange`: `isInt` reaches the ladder only after\n // `validator.isInt` returned true, so hoisting it would bake in an\n // invariant that a future locale-aware `isInt` could silently break\n // into a wrong-pass.\n if (!Number.isNaN(numeric)) {\n assertNumericRange(ctx.value, numeric, options);\n }\n if (!validator.isFloat(s, options)) {\n throw createValidupError(\n ctx.value,\n IssueCode.DECIMAL,\n options.message ?? 'The value must be a decimal number',\n );\n }\n return ctx.value;\n },\n });\n}\n"],"mappings":";;;;;;;;;;;AAsDA,SAAgB,kBAAkB,OAAwB;CACtD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,OAAO,OAAO,KAAK;CAChF,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO;CAClD,OAAO,OAAO,KAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,gBACZ,IACA,SACsB;CACtB,MAAM,eAAe,QAAQ,QAAQ,UAAU;CAC/C,MAAM,kBAAkB,QAAQ,WAAW;CAE3C,OAAO,gBAAmB;EACtB,YAAY,QAAQ;EACpB,MAA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QAAQ,GAAG,OAAO,GAC7B,MAAM,mBACF,IAAI,OACJ,UAAU,SACV,QAAQ,WAAW,oCACvB;EAEJ,OAAO,IAAI;CACf,EACJ,CAAC;AACL"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/module.ts","../src/factories/comparison.ts","../src/factories/length.ts","../src/factories/string-format.ts","../src/factories/type-assertions.ts"],"sourcesContent":["/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\n\nimport type { BaseFactoryOptions, CreateValidatorOptions, ValidatorJsFn } from './types';\n\n/**\n * Shape of a validator.js boolean predicate. The first argument is always\n * the string to test; subsequent arguments are validator-specific options.\n */\n\n/**\n * Options accepted by every factory (and {@link createValidator}). The\n * factory layers vocabulary-specific fields on top of this shape.\n */\n\n/**\n * Options accepted by {@link createValidator}. The vocabulary code is\n * required — that's the entire point of the generic wrap; if you just\n * want `VALUE_INVALID`, hand-roll a `Validator` instead.\n */\n\n/**\n * Build a string representation suitable for validator.js. validator.js\n * functions expect strings; for numbers and booleans we use `String(...)`\n * so consumers can mount `isInt()` on a `number`-shaped field without\n * pre-stringifying.\n */\nexport function toValidatorString(value: unknown): string {\n if (typeof value === 'string') {\n return value;\n }\n\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n\n if (value === null || value === undefined) {\n return '';\n }\n\n return String(value);\n}\n\n/**\n * Generic wrap for any validator.js function we don't ship a pre-baked\n * factory for. The wrapped validator stringifies `ctx.value`, calls the\n * validator.js predicate, and throws a `ValidupError` carrying the\n * supplied `code` (+ optional `data`) on failure.\n *\n * @example\n * import validator from 'validator';\n * import { createValidator } from '@validup/validator-js';\n *\n * container.mount('card', createValidator(validator.isCreditCard, {\n * code: 'credit_card',\n * message: 'Invalid credit card number',\n * }));\n *\n * For the common cases — `email()`, `isLength()`, `isInt()` etc. — reach\n * for the pre-baked factories instead; they bake the right vocabulary\n * code and `data` in for you.\n *\n * The returned descriptor participates in the validup result cache by\n * default — validator.js's `ValidatorJsFn` signature is synchronous\n * and only inspects the stringified value, so the outcome is a pure\n * function of `(ctx.value, ctx.context, ctx.group)`. If the wrapped\n * predicate captures external state and the caller knowingly opts\n * into that, pass `sideEffect: true` to bypass the cache.\n */\nexport function createValidator<C = unknown>(\n fn: ValidatorJsFn,\n options: CreateValidatorOptions & { sideEffect?: boolean },\n): ValidatorDescriptor<C> {\n const fallbackCode = options.code || IssueCode.VALUE_INVALID;\n const fallbackMessage = options.message ?? 'The value is invalid';\n\n return defineValidator<C>({\n sideEffect: options.sideEffect,\n run: (ctx) => {\n const stringified = toValidatorString(ctx.value);\n\n if (fn(stringified)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, fallbackCode, fallbackMessage, options.data);\n },\n });\n}\nexport type { ValidatorJsFn, BaseFactoryOptions, CreateValidatorOptions };\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { getPathValue } from 'pathtrace';\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `matches`. Emits `IssueCode.PATTERN` on failure\n * with `data: { pattern: string }` (the regex source, no flags) so\n * i18n templates can quote it.\n */\nexport function matches<C = unknown>(pattern: RegExp | string, options: BaseFactoryOptions & {\n modifiers?: string,\n} = {}): ValidatorDescriptor<C> {\n const patternSource = typeof pattern === 'string' ? pattern : pattern.source;\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n const ok = typeof pattern === 'string' ?\n validator.matches(s, pattern, options.modifiers) :\n validator.matches(s, pattern);\n\n if (ok) {\n return ctx.value;\n }\n\n throw createValidupError(\n ctx.value,\n IssueCode.PATTERN,\n options.message ?? 'The value does not match the expected pattern',\n { pattern: patternSource },\n );\n },\n });\n}\n\n/**\n * Factory: validator.js `equals`. Emits `IssueCode.SAME_AS` on failure\n * with `data: { other: string }` so a translated message can quote the\n * key subject (e.g. \"must equal {{other}}\").\n *\n * `key` is the field-name / label the i18n template should\n * surface. When `expectedValue` is omitted, `key` is also used as a\n * pathtrace path into `ctx.data` to look up the runtime comparison\n * target — so `equals('password')` mounted on `passwordConfirm`\n * compares against `ctx.data.password`. Pass `expectedValue`\n * explicitly to compare against a fixed string instead.\n *\n * **Side-effect contract.** When `expectedValue` is provided the\n * validator is a pure function of `ctx.value` and participates in the\n * result cache like every other factory. When `expectedValue` is\n * omitted the validator reads `ctx.data[key]` — a sibling field —\n * which the cache's `(value, context, group)` snapshot does NOT\n * capture. The factory therefore stamps `sideEffect: true` in that\n * branch so the framework re-runs it on every invocation; otherwise a\n * `passwordConfirm` check would stay stale after `password` changes.\n */\nexport function equals<C = unknown>(key: string, options: BaseFactoryOptions & {\n expectedValue?: string,\n} = {}): ValidatorDescriptor<C> {\n return defineValidator<C>({\n sideEffect: typeof options.expectedValue === 'undefined',\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n const target = options.expectedValue ?? toValidatorString(getPathValue(ctx.data, key));\n\n if (validator.equals(s, target)) {\n return ctx.value;\n }\n\n throw createValidupError(\n ctx.value,\n IssueCode.SAME_AS,\n options.message ?? `The value must equal ${key}`,\n { other: key },\n );\n },\n });\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `isLength`. Detects which bound failed at\n * validation time so the resulting issue carries a useful vocabulary\n * code:\n *\n * - Too short → `IssueCode.MIN_LENGTH` (data: `{ min }`).\n * - Too long → `IssueCode.MAX_LENGTH` (data: `{ max }`).\n *\n * Calling without `min` / `max` is allowed but degenerate — every value\n * passes. `message` overrides the default English string for both bound\n * failures.\n */\nexport function isLength<C = unknown>(\n options: BaseFactoryOptions & validator.IsLengthOptions = {},\n): ValidatorDescriptor<C> {\n const { min, max } = options;\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isLength(s, options)) {\n return ctx.value;\n }\n\n if (typeof min === 'number' && s.length < min) {\n throw createValidupError(\n ctx.value,\n IssueCode.MIN_LENGTH,\n options.message ?? `The minimum length allowed is ${min}`,\n { min },\n );\n }\n\n if (typeof max === 'number' && s.length > max) {\n throw createValidupError(\n ctx.value,\n IssueCode.MAX_LENGTH,\n options.message ?? `The maximum length allowed is ${max}`,\n { max },\n );\n }\n\n // Fallback (shouldn't normally hit — `isLength` returned false but\n // neither bound was crossed). The MIN_LENGTH / MAX_LENGTH codes\n // both require their bound in `data`; without a bound we can't\n // honour the vocabulary contract, so emit the generic code.\n if (typeof min === 'number') {\n throw createValidupError(\n ctx.value,\n IssueCode.MIN_LENGTH,\n options.message ?? 'The value has an invalid length',\n { min },\n );\n }\n\n throw createValidupError(\n ctx.value,\n IssueCode.VALUE_INVALID,\n options.message ?? 'The value has an invalid length',\n );\n },\n });\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `isEmail`. Emits `IssueCode.EMAIL` on failure.\n *\n * Options are flattened — pass validator.js's `IsEmailOptions` keys\n * (`require_display_name`, `allow_utf8_local_part`, …) directly alongside\n * the validup-side `message` override.\n */\nexport function isEmail<C = unknown>(\n options: BaseFactoryOptions & validator.IsEmailOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid email address';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isEmail(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.EMAIL, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isURL`. Emits `IssueCode.URL` on failure.\n */\nexport function isURL<C = unknown>(\n options: BaseFactoryOptions & validator.IsURLOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid URL';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isURL(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.URL, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isUUID`. Emits `IssueCode.UUID` on failure.\n *\n * `version` mirrors validator.js's positional second argument\n * (`'1' | '2' | '3' | '4' | '5' | 'all' | 1 | …`). Promoted into the\n * options object so the call site is consistent with the other factories.\n */\nexport function isUUID<C = unknown>(\n options: BaseFactoryOptions & { version?: validator.UUIDVersion } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid UUID';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isUUID(s, options.version)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.UUID, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isIP`. Emits `IssueCode.IP_ADDRESS` on failure.\n *\n * `version` mirrors validator.js's positional second argument.\n */\nexport function isIP<C = unknown>(\n options: BaseFactoryOptions & { version?: '4' | '6' | 4 | 6 } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid IP address';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isIP(s, options.version)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.IP_ADDRESS, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isMACAddress`. Emits `IssueCode.MAC_ADDRESS` on failure.\n */\nexport function isMACAddress<C = unknown>(\n options: BaseFactoryOptions & validator.IsMACAddressOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid MAC address';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isMACAddress(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.MAC_ADDRESS, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isDate`. Emits `IssueCode.DATE` on failure.\n */\nexport function isDate<C = unknown>(\n options: BaseFactoryOptions & validator.IsDateOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid date';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isDate(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.DATE, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isISO8601`. Emits `IssueCode.DATE` on failure\n * (same code as `isDate` — both produce the \"is this a parseable date\"\n * outcome from the consumer's perspective).\n */\nexport function isISO8601<C = unknown>(\n options: BaseFactoryOptions & validator.IsISO8601Options = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not a valid date';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isISO8601(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.DATE, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isJSON`. Emits `IssueCode.JSON` on failure.\n */\nexport function isJSON<C = unknown>(\n options: BaseFactoryOptions & validator.IsJSONOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not valid JSON';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isJSON(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.JSON, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isBase64`. Emits `IssueCode.BASE64` on failure.\n */\nexport function isBase64<C = unknown>(\n options: BaseFactoryOptions & validator.IsBase64Options = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not valid base64';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isBase64(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.BASE64, message);\n },\n });\n}\n\n/**\n * The subset of `validator.StrongPasswordOptions` keys that describe\n * *strength requirements* — what the consumer wants the password to look\n * like, as opposed to scoring weights (`pointsPerUnique`,\n * `pointsForContainingLower`, …) which only affect validator.js's\n * `returnScore` mode. Only these keys surface on `IssueCode.STRONG_PASSWORD`'s\n * `data` payload, matching the documented vocabulary contract.\n */\nconst STRONG_PASSWORD_REQUIREMENT_KEYS = [\n 'minLength',\n 'minLowercase',\n 'minUppercase',\n 'minNumbers',\n 'minSymbols',\n] as const;\n\ntype StrongPasswordRequirementParams = {\n minLength?: number,\n minLowercase?: number,\n minUppercase?: number,\n minNumbers?: number,\n minSymbols?: number,\n};\n\n/**\n * Factory: validator.js `isStrongPassword`. Emits\n * `IssueCode.STRONG_PASSWORD` on failure. `data` carries only the\n * documented strength-requirement keys (`minLength`, `minLowercase`,\n * `minUppercase`, `minNumbers`, `minSymbols`) so i18n templates can quote\n * them:\n *\n * ```ts\n * isStrongPassword({ minLength: 12, minNumbers: 2 });\n * // → IssueCode.STRONG_PASSWORD, data: { minLength: 12, minNumbers: 2 }\n * ```\n *\n * Scoring weights (`pointsPerUnique`, `pointsForContainingLower`, …) are\n * still forwarded to validator.js so they continue to influence the\n * pass/fail decision (and any `returnScore`-shaped diagnostics), but they\n * do NOT appear in `data` — i18n templates would never want to render\n * \"must score at least N points per unique character\" to the user.\n */\nexport function isStrongPassword<C = unknown>(\n options: BaseFactoryOptions & validator.StrongPasswordOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value does not meet the password strength requirements';\n // Strip validup-only `message` AND `returnScore` before forwarding to\n // validator.js. With `returnScore: true`, validator.js returns a numeric\n // score instead of a boolean — the truthy check below would accept any\n // non-zero score as a pass, so a weak password could squeak through.\n // Drop the flag and force boolean semantics.\n const {\n message: _ignored,\n returnScore: _alsoIgnored,\n ...rest\n } = options;\n // Project `rest` down to the documented strength-requirement subset for\n // the `data` payload. The full `rest` (including scoring weights) is\n // what validator.js sees — but consumer-facing `IssueItem.data`\n // matches the documented vocabulary contract.\n //\n // Build the template once at factory time; clone it per failure so a\n // consumer mutating `issue.data` on one IssueItem can't bleed into a\n // future failure from the same factory.\n const paramsTemplate: StrongPasswordRequirementParams = {};\n\n for (const key of STRONG_PASSWORD_REQUIREMENT_KEYS) {\n if (typeof rest[key] === 'number') {\n paramsTemplate[key] = rest[key];\n }\n }\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n // validator.js mutates the options argument it receives (merging\n // defaults in-place). Pass a shallow clone so consumer-side\n // `options` and our captured template stay clean.\n const probeOptions = { ...rest } as validator.StrongPasswordOptions;\n\n if (validator.isStrongPassword(s, probeOptions) === true) {\n return ctx.value;\n }\n\n throw createValidupError(\n ctx.value,\n IssueCode.STRONG_PASSWORD,\n message,\n { ...paramsTemplate },\n );\n },\n });\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport validator from 'validator';\nimport { IssueCode } from '@ebec/core';\nimport { createValidupError, defineValidator } from 'validup';\nimport type { ValidatorDescriptor } from 'validup';\nimport type { BaseFactoryOptions } from '../module';\nimport { toValidatorString } from '../module';\n\n/**\n * Factory: validator.js `isAlpha`. Emits `IssueCode.ALPHA` on failure.\n *\n * `locale` (validator.js's positional second arg) is promoted into the\n * flat options object; everything else passes through as `IsAlphaOptions`.\n */\nexport function isAlpha<C = unknown>(\n options: BaseFactoryOptions & validator.IsAlphaOptions & {\n locale?: validator.AlphaLocale,\n } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value is not alphabetical';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isAlpha(s, options.locale, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.ALPHA, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isAlphanumeric`. Emits `IssueCode.ALPHA_NUM` on failure.\n */\nexport function isAlphanumeric<C = unknown>(\n options: BaseFactoryOptions & validator.IsAlphanumericOptions & {\n locale?: validator.AlphanumericLocale,\n } = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value must be alphanumeric';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isAlphanumeric(s, options.locale, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.ALPHA_NUM, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isNumeric`. Emits `IssueCode.NUMERIC` on failure.\n */\nexport function isNumeric<C = unknown>(\n options: BaseFactoryOptions & validator.IsNumericOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value must be numeric';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isNumeric(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.NUMERIC, message);\n },\n });\n}\n\n/**\n * Factory: validator.js `isDecimal`. Emits `IssueCode.DECIMAL` on failure.\n */\nexport function isDecimal<C = unknown>(\n options: BaseFactoryOptions & validator.IsDecimalOptions = {},\n): ValidatorDescriptor<C> {\n const message = options.message ?? 'The value must be a decimal number';\n\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n if (validator.isDecimal(s, options)) {\n return ctx.value;\n }\n\n throw createValidupError(ctx.value, IssueCode.DECIMAL, message);\n },\n });\n}\n\n/**\n * The min/gt/max/lt bounds shared by {@link isInt} and {@link isFloat}.\n * A subset of both `validator.IsIntOptions` and `validator.IsFloatOptions`\n * plus the `message` override from `BaseFactoryOptions`.\n */\ntype NumericRangeOptions = {\n min?: number,\n max?: number,\n lt?: number,\n gt?: number,\n message?: string,\n};\n\n/**\n * Shared range ladder for {@link isInt} / {@link isFloat}. Throws the first\n * violated bound and returns `void` when every bound holds.\n *\n * The bounds are checked first-match-wins in `min`, `gt`, `max`, `lt` order,\n * and the emitted codes are deliberately coarser than the option names:\n *\n * - `min` (inclusive) and `gt` (exclusive) both emit `IssueCode.MIN_VALUE`.\n * For `gt`, `data.min` carries `options.gt` — i18n templates can quote the\n * boundary, and the precise inclusive/exclusive wording comes from\n * `message`. Same treatment for `lt` → `IssueCode.MAX_VALUE` with\n * `data.max` carrying `options.lt`. This mapping is an i18n-facing\n * contract; don't split it without a matching catalog change.\n *\n * Type-failure codes (`INTEGER` for `isInt`, `DECIMAL` for `isFloat`) sit\n * OUTSIDE this ladder and stay with their respective factories — which is\n * why the helper needs no code-selecting parameter.\n *\n * `NaN` handling also stays with the caller: `isFloat` skips the ladder for\n * localized input that `Number()` can't parse, while `isInt` reaches it only\n * after `validator.isInt` returned true.\n */\nfunction assertNumericRange(\n received: unknown,\n numeric: number,\n options: NumericRangeOptions,\n): void {\n const {\n min,\n max,\n lt,\n gt,\n } = options;\n\n if (typeof min === 'number' && numeric < min) {\n throw createValidupError(\n received,\n IssueCode.MIN_VALUE,\n options.message ?? `The value must be greater than or equal to ${min}`,\n { min },\n );\n }\n\n if (typeof gt === 'number' && numeric <= gt) {\n throw createValidupError(\n received,\n IssueCode.MIN_VALUE,\n options.message ?? `The value must be greater than ${gt}`,\n { min: gt },\n );\n }\n\n if (typeof max === 'number' && numeric > max) {\n throw createValidupError(\n received,\n IssueCode.MAX_VALUE,\n options.message ?? `The value must be less than or equal to ${max}`,\n { max },\n );\n }\n\n if (typeof lt === 'number' && numeric >= lt) {\n throw createValidupError(\n received,\n IssueCode.MAX_VALUE,\n options.message ?? `The value must be less than ${lt}`,\n { max: lt },\n );\n }\n}\n\n/**\n * Factory: validator.js `isInt`. Resolves the right vocabulary code\n * based on what failed:\n *\n * - Value isn't an integer at all → `IssueCode.INTEGER`.\n * - Value below `min` (inclusive) or `gt` (exclusive) → `IssueCode.MIN_VALUE`\n * (data: `{ min }`). For `gt`, `data.min` is `options.gt` — i18n\n * templates can quote the boundary; the precise inclusive/exclusive\n * wording comes from `message`.\n * - Value above `max` (inclusive) or `lt` (exclusive) → `IssueCode.MAX_VALUE`\n * (data: `{ max }`). Same treatment as `gt` → `data.max` is `options.lt`.\n */\nexport function isInt<C = unknown>(\n options: BaseFactoryOptions & validator.IsIntOptions = {},\n): ValidatorDescriptor<C> {\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n // Type check first — strip range bounds so a non-integer always\n // surfaces as INTEGER instead of being swallowed by a range failure.\n const isInteger = validator.isInt(s, { allow_leading_zeroes: options.allow_leading_zeroes });\n\n if (!isInteger) {\n throw createValidupError(\n ctx.value,\n IssueCode.INTEGER,\n options.message ?? 'The value must be an integer',\n );\n }\n\n assertNumericRange(ctx.value, Number(s), options);\n\n // Defensive final pass — catches any remaining option we didn't\n // model explicitly (currently none beyond min/max/lt/gt and\n // allow_leading_zeroes). If this fires the failure is a true type\n // mismatch.\n if (!validator.isInt(s, options)) {\n throw createValidupError(\n ctx.value,\n IssueCode.INTEGER,\n options.message ?? 'The value must be an integer',\n );\n }\n\n return ctx.value;\n },\n });\n}\n\n/**\n * Factory: validator.js `isFloat`. Like {@link isInt} but for decimal\n * numbers — type failure emits `IssueCode.DECIMAL`; range bounds emit\n * `MIN_VALUE` / `MAX_VALUE`. `gt` / `lt` map to `MIN_VALUE` / `MAX_VALUE`\n * the same way `isInt` does — `gt` emits `MIN_VALUE` with `data.min` set to\n * `options.gt`, `lt` emits `MAX_VALUE` with `data.max` set to `options.lt`.\n *\n * **Locale caveat.** validator.js's locale-aware float parsing (e.g.\n * `'123,45'` under `locale: 'de-DE'`) is opaque to the factory — we use\n * `Number(s)` for the explicit range checks, which returns `NaN` for\n * localized strings. When `locale` is set and the input parses to `NaN`,\n * we skip the explicit range checks and fall through to\n * `validator.isFloat(s, options)`, which DOES handle the locale correctly\n * — but a range failure caught there surfaces as `IssueCode.DECIMAL`\n * instead of `MIN_VALUE` / `MAX_VALUE`. Use the default locale (or\n * normalize the input upstream) when precise range codes matter for i18n.\n */\nexport function isFloat<C = unknown>(\n options: BaseFactoryOptions & validator.IsFloatOptions = {},\n): ValidatorDescriptor<C> {\n return defineValidator<C>({\n run: (ctx) => {\n const s = toValidatorString(ctx.value);\n\n // Pre-check honours `locale` so localized floats (e.g. '123,45' for\n // 'de-DE') aren't rejected by the type gate before the range checks\n // get a chance to run.\n if (!validator.isFloat(s, { locale: options.locale })) {\n throw createValidupError(\n ctx.value,\n IssueCode.DECIMAL,\n options.message ?? 'The value must be a decimal number',\n );\n }\n\n const numeric = Number(s);\n\n // NaN from a localized input skips the explicit range checks — see\n // the JSDoc above for the resulting code-vs-message trade-off. The\n // guard stays at THIS call site rather than moving into\n // `assertNumericRange`: `isInt` reaches the ladder only after\n // `validator.isInt` returned true, so hoisting it would bake in an\n // invariant that a future locale-aware `isInt` could silently break\n // into a wrong-pass.\n if (!Number.isNaN(numeric)) {\n assertNumericRange(ctx.value, numeric, options);\n }\n\n if (!validator.isFloat(s, options)) {\n throw createValidupError(\n ctx.value,\n IssueCode.DECIMAL,\n options.message ?? 'The value must be a decimal number',\n );\n }\n\n return ctx.value;\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,kBAAkB,OAAwB;CACtD,IAAI,OAAO,UAAU,UACjB,OAAO;CAGX,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,W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B,MAAM,QAAQ;EACV,MAAM,IAAI,kBAAkB,IAAI,KAAK;EAKrC,IAAI,CAAC,UAAU,QAAQ,GAAG,EAAE,QAAQ,QAAQ,OAAO,CAAC,GAChD,MAAM,mBACF,IAAI,OACJ,UAAU,SACV,QAAQ,WAAW,oCACvB;EAGJ,MAAM,UAAU,OAAO,CAAC;EASxB,IAAI,CAAC,OAAO,MAAM,OAAO,GACrB,mBAAmB,IAAI,OAAO,SAAS,OAAO;EAGlD,IAAI,CAAC,UAAU,QAAQ,GAAG,OAAO,GAC7B,MAAM,mBACF,IAAI,OACJ,UAAU,SACV,QAAQ,WAAW,oCACvB;EAGJ,OAAO,IAAI;CACf,EACJ,CAAC;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@validup/validator-js",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "description": "validator.js integration for validup — pre-baked factories per common rule plus a generic createValidator for the long tail.",
6
6
  "author": {
@@ -23,6 +23,7 @@
23
23
  }
24
24
  },
25
25
  "files": [
26
+ "assets",
26
27
  "dist"
27
28
  ],
28
29
  "engines": {
@@ -44,7 +45,7 @@
44
45
  ],
45
46
  "license": "Apache-2.0",
46
47
  "dependencies": {
47
- "@ebec/core": "^1.3.1",
48
+ "@ebec/core": "^1.3.2",
48
49
  "pathtrace": "^2.2.3"
49
50
  },
50
51
  "devDependencies": {
@@ -53,7 +54,7 @@
53
54
  },
54
55
  "peerDependencies": {
55
56
  "validator": "^13.0.0",
56
- "validup": "^2.0.0"
57
+ "validup": "^2.0.2"
57
58
  },
58
59
  "publishConfig": {
59
60
  "access": "public"