@validup/validator-js 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # @validup/validator-js 🛡️
2
+
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.
4
+
5
+ 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
+
7
+ **Replaces** `@validup/express-validator`. validator.js is the underlying library express-validator wraps; using it directly removes the Express-chain abstraction we don't need and gives the adapter structural knowledge of which validator fired (so no `.withMessage({code, message})` dance).
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @validup/validator-js validator validup --save
13
+ ```
14
+
15
+ | Peer dependency | Supported versions |
16
+ |-----------------|--------------------|
17
+ | `validup` | `^1.0.0` |
18
+ | `validator` | `^13.0.0` |
19
+
20
+ ## Quick Start
21
+
22
+ ```typescript
23
+ import { Container } from 'validup';
24
+ import {
25
+ isEmail,
26
+ isLength,
27
+ isInt,
28
+ isURL,
29
+ matches,
30
+ equals,
31
+ } from '@validup/validator-js';
32
+
33
+ const container = new Container<{
34
+ email: string;
35
+ name: string;
36
+ age: number;
37
+ site: string;
38
+ zip: string;
39
+ password: string;
40
+ confirm: string;
41
+ }>();
42
+
43
+ container.mount('email', isEmail());
44
+ container.mount('name', isLength({ min: 3, max: 50 }));
45
+ container.mount('age', isInt({ min: 18, max: 120 }));
46
+ container.mount('site', isURL({ require_protocol: true }));
47
+ container.mount('zip', matches(/^\d{5}$/));
48
+ container.mount('password', isStrongPassword());
49
+ container.mount('confirm', equals('password')); // compares ctx.value against ctx.data.password
50
+
51
+ const valid = await container.run({
52
+ email: 'peter@example.com',
53
+ name: 'Peter',
54
+ age: 28,
55
+ site: 'https://example.com',
56
+ zip: '12345',
57
+ password: 'Hunter2!sup3r',
58
+ confirm: 'Hunter2!sup3r',
59
+ });
60
+ ```
61
+
62
+ ## Factories
63
+
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.
65
+
66
+ | Factory | Options type | Emits | `data` payload |
67
+ |---------|--------------|-------|------------------|
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` | — |
77
+ | `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` | — |
82
+ | `isInt(opts?)` | `BaseFactoryOptions & validator.IsIntOptions` | `INTEGER` *or* `MIN_VALUE` / `MAX_VALUE` | `{ min }` / `{ max }` on range failure |
83
+ | `isFloat(opts?)` | `BaseFactoryOptions & validator.IsFloatOptions` | `DECIMAL` *or* `MIN_VALUE` / `MAX_VALUE` | `{ min }` / `{ max }` on range failure |
84
+ | `isLength(opts?)` | `BaseFactoryOptions & validator.IsLengthOptions` | `MIN_LENGTH` *or* `MAX_LENGTH` | `{ min }` / `{ max }` |
85
+ | `matches(pattern, opts?)` | `BaseFactoryOptions & { modifiers? }` | `PATTERN` | `{ pattern: string }` |
86
+ | `equals(key, opts?)` | `BaseFactoryOptions & { expectedValue? }` | `SAME_AS` | `{ other: string }` |
87
+
88
+ Examples:
89
+
90
+ ```ts
91
+ isEmail({ require_display_name: true, message: 'Must include name' });
92
+ isInt({ min: 18, max: 120, message: 'Must be 18–120' });
93
+ isLength({ min: 3, max: 50 });
94
+ isURL({ require_protocol: true, protocols: ['https'] });
95
+ isAlpha({ locale: 'de-DE', ignore: '-' });
96
+ isStrongPassword({ minLength: 12, minNumbers: 2 });
97
+ ```
98
+
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).
100
+
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.
102
+
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.
104
+
105
+ ## Generic wrap — `createValidator`
106
+
107
+ For validators not pre-baked (`isCreditCard`, `isJWT`, `isMobilePhone`, `isPostalCode`, …):
108
+
109
+ ```typescript
110
+ import validator from 'validator';
111
+ import { createValidator } from '@validup/validator-js';
112
+
113
+ container.mount('card', createValidator(validator.isCreditCard, {
114
+ code: 'credit_card',
115
+ message: 'Invalid credit card number',
116
+ }));
117
+
118
+ container.mount('phone', createValidator(
119
+ (v) => validator.isMobilePhone(v, 'de-DE'),
120
+ {
121
+ code: 'mobile_phone',
122
+ data: { locale: 'de-DE' },
123
+ message: 'Invalid German mobile number',
124
+ },
125
+ ));
126
+ ```
127
+
128
+ `createValidator(fn, { code, message, data?, sideEffect? })`:
129
+
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.
135
+
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.
137
+
138
+ ## Per-call message override
139
+
140
+ Every factory accepts `{ message }` to override the default:
141
+
142
+ ```typescript
143
+ container.mount('email', isEmail({ message: 'Bad email' }));
144
+ container.mount('name', isLength({ min: 3, message: 'Name too short' }));
145
+ ```
146
+
147
+ Defaults match `@ilingo/validup`'s `en` catalog wording, so consumers without i18n see consistent strings.
148
+
149
+ ## Why not express-validator?
150
+
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.
152
+
153
+ `@validup/validator-js` replaces `@validup/express-validator` outright. Migration is mechanical:
154
+
155
+ ```diff
156
+ - container.mount('email', createValidator(() => body().isEmail()));
157
+ + container.mount('email', isEmail());
158
+
159
+ - container.mount('name', createValidator(() => body()
160
+ - .isLength({ min: 3 })
161
+ - .withMessage({ code: IssueCode.MIN_LENGTH, message: 'Too short' })));
162
+ + container.mount('name', isLength({ min: 3, message: 'Too short' }));
163
+ ```
164
+
165
+ ## License
166
+
167
+ Apache-2.0 © Peter Placzek
@@ -0,0 +1,253 @@
1
+ import { ValidatorDescriptor } from "validup";
2
+
3
+ //#region src/module.d.ts
4
+ /**
5
+ * Shape of a validator.js boolean predicate. The first argument is always
6
+ * the string to test; subsequent arguments are validator-specific options.
7
+ */
8
+ type ValidatorJsFn = (value: string, ...args: any[]) => boolean;
9
+ /**
10
+ * Options accepted by every factory (and {@link createValidator}). The
11
+ * factory layers vocabulary-specific fields on top of this shape.
12
+ */
13
+ interface BaseFactoryOptions {
14
+ /**
15
+ * Override the default English message produced by the factory. The
16
+ * default tracks `@ilingo/validup`'s `en` catalog so the same wording
17
+ * surfaces with and without i18n.
18
+ */
19
+ message?: string;
20
+ }
21
+ /**
22
+ * Options accepted by {@link createValidator}. The vocabulary code is
23
+ * required — that's the entire point of the generic wrap; if you just
24
+ * want `VALUE_INVALID`, hand-roll a `Validator` instead.
25
+ */
26
+ interface CreateValidatorOptions extends BaseFactoryOptions {
27
+ /**
28
+ * `IssueCode` value (or any project-specific string) attached to the
29
+ * `IssueItem` on failure.
30
+ */
31
+ code: string;
32
+ /**
33
+ * Optional structured payload surfaced on `IssueItem.data` — what
34
+ * the i18n template's `{{placeholders}}` resolve against.
35
+ */
36
+ data?: Record<string, unknown>;
37
+ }
38
+ /**
39
+ * Build a string representation suitable for validator.js. validator.js
40
+ * functions expect strings; for numbers and booleans we use `String(...)`
41
+ * so consumers can mount `isInt()` on a `number`-shaped field without
42
+ * pre-stringifying.
43
+ */
44
+ declare function toValidatorString(value: unknown): string;
45
+ /**
46
+ * Generic wrap for any validator.js function we don't ship a pre-baked
47
+ * factory for. The wrapped validator stringifies `ctx.value`, calls the
48
+ * validator.js predicate, and throws a `ValidupError` carrying the
49
+ * supplied `code` (+ optional `data`) on failure.
50
+ *
51
+ * @example
52
+ * import validator from 'validator';
53
+ * import { createValidator } from '@validup/validator-js';
54
+ *
55
+ * container.mount('card', createValidator(validator.isCreditCard, {
56
+ * code: 'credit_card',
57
+ * message: 'Invalid credit card number',
58
+ * }));
59
+ *
60
+ * For the common cases — `email()`, `isLength()`, `isInt()` etc. — reach
61
+ * for the pre-baked factories instead; they bake the right vocabulary
62
+ * code and `data` in for you.
63
+ *
64
+ * The returned descriptor participates in the validup result cache by
65
+ * default — validator.js's `ValidatorJsFn` signature is synchronous
66
+ * and only inspects the stringified value, so the outcome is a pure
67
+ * function of `(ctx.value, ctx.context, ctx.group)`. If the wrapped
68
+ * predicate captures external state and the caller knowingly opts
69
+ * into that, pass `sideEffect: true` to bypass the cache.
70
+ */
71
+ declare function createValidator<C = unknown>(fn: ValidatorJsFn, options: CreateValidatorOptions & {
72
+ sideEffect?: boolean;
73
+ }): ValidatorDescriptor<C>;
74
+ //#endregion
75
+ //#region src/factories/comparison.d.ts
76
+ /**
77
+ * Factory: validator.js `matches`. Emits `IssueCode.PATTERN` on failure
78
+ * with `data: { pattern: string }` (the regex source, no flags) so
79
+ * i18n templates can quote it.
80
+ */
81
+ declare function matches<C = unknown>(pattern: RegExp | string, options?: BaseFactoryOptions & {
82
+ modifiers?: string;
83
+ }): ValidatorDescriptor<C>;
84
+ /**
85
+ * Factory: validator.js `equals`. Emits `IssueCode.SAME_AS` on failure
86
+ * with `data: { other: string }` so a translated message can quote the
87
+ * key subject (e.g. "must equal {{other}}").
88
+ *
89
+ * `key` is the field-name / label the i18n template should
90
+ * surface. When `expectedValue` is omitted, `key` is also used as a
91
+ * pathtrace path into `ctx.data` to look up the runtime comparison
92
+ * target — so `equals('password')` mounted on `passwordConfirm`
93
+ * compares against `ctx.data.password`. Pass `expectedValue`
94
+ * explicitly to compare against a fixed string instead.
95
+ *
96
+ * **Side-effect contract.** When `expectedValue` is provided the
97
+ * validator is a pure function of `ctx.value` and participates in the
98
+ * result cache like every other factory. When `expectedValue` is
99
+ * omitted the validator reads `ctx.data[key]` — a sibling field —
100
+ * which the cache's `(value, context, group)` snapshot does NOT
101
+ * capture. The factory therefore stamps `sideEffect: true` in that
102
+ * branch so the framework re-runs it on every invocation; otherwise a
103
+ * `passwordConfirm` check would stay stale after `password` changes.
104
+ */
105
+ declare function equals<C = unknown>(key: string, options?: BaseFactoryOptions & {
106
+ expectedValue?: string;
107
+ }): ValidatorDescriptor<C>;
108
+ //#endregion
109
+ //#region src/factories/length.d.ts
110
+ /**
111
+ * Factory: validator.js `isLength`. Detects which bound failed at
112
+ * validation time so the resulting issue carries a useful vocabulary
113
+ * code:
114
+ *
115
+ * - Too short → `IssueCode.MIN_LENGTH` (data: `{ min }`).
116
+ * - Too long → `IssueCode.MAX_LENGTH` (data: `{ max }`).
117
+ *
118
+ * Calling without `min` / `max` is allowed but degenerate — every value
119
+ * passes. `message` overrides the default English string for both bound
120
+ * failures.
121
+ */
122
+ declare function isLength<C = unknown>(options?: BaseFactoryOptions & validator.IsLengthOptions): ValidatorDescriptor<C>;
123
+ //#endregion
124
+ //#region src/factories/string-format.d.ts
125
+ /**
126
+ * Factory: validator.js `isEmail`. Emits `IssueCode.EMAIL` on failure.
127
+ *
128
+ * Options are flattened — pass validator.js's `IsEmailOptions` keys
129
+ * (`require_display_name`, `allow_utf8_local_part`, …) directly alongside
130
+ * the validup-side `message` override.
131
+ */
132
+ declare function isEmail<C = unknown>(options?: BaseFactoryOptions & validator.IsEmailOptions): ValidatorDescriptor<C>;
133
+ /**
134
+ * Factory: validator.js `isURL`. Emits `IssueCode.URL` on failure.
135
+ */
136
+ declare function isURL<C = unknown>(options?: BaseFactoryOptions & validator.IsURLOptions): ValidatorDescriptor<C>;
137
+ /**
138
+ * Factory: validator.js `isUUID`. Emits `IssueCode.UUID` on failure.
139
+ *
140
+ * `version` mirrors validator.js's positional second argument
141
+ * (`'1' | '2' | '3' | '4' | '5' | 'all' | 1 | …`). Promoted into the
142
+ * options object so the call site is consistent with the other factories.
143
+ */
144
+ declare function isUUID<C = unknown>(options?: BaseFactoryOptions & {
145
+ version?: validator.UUIDVersion;
146
+ }): ValidatorDescriptor<C>;
147
+ /**
148
+ * Factory: validator.js `isIP`. Emits `IssueCode.IP_ADDRESS` on failure.
149
+ *
150
+ * `version` mirrors validator.js's positional second argument.
151
+ */
152
+ declare function isIP<C = unknown>(options?: BaseFactoryOptions & {
153
+ version?: '4' | '6' | 4 | 6;
154
+ }): ValidatorDescriptor<C>;
155
+ /**
156
+ * Factory: validator.js `isMACAddress`. Emits `IssueCode.MAC_ADDRESS` on failure.
157
+ */
158
+ declare function isMACAddress<C = unknown>(options?: BaseFactoryOptions & validator.IsMACAddressOptions): ValidatorDescriptor<C>;
159
+ /**
160
+ * Factory: validator.js `isDate`. Emits `IssueCode.DATE` on failure.
161
+ */
162
+ declare function isDate<C = unknown>(options?: BaseFactoryOptions & validator.IsDateOptions): ValidatorDescriptor<C>;
163
+ /**
164
+ * Factory: validator.js `isISO8601`. Emits `IssueCode.DATE` on failure
165
+ * (same code as `isDate` — both produce the "is this a parseable date"
166
+ * outcome from the consumer's perspective).
167
+ */
168
+ declare function isISO8601<C = unknown>(options?: BaseFactoryOptions & validator.IsISO8601Options): ValidatorDescriptor<C>;
169
+ /**
170
+ * Factory: validator.js `isJSON`. Emits `IssueCode.JSON` on failure.
171
+ */
172
+ declare function isJSON<C = unknown>(options?: BaseFactoryOptions & validator.IsJSONOptions): ValidatorDescriptor<C>;
173
+ /**
174
+ * Factory: validator.js `isBase64`. Emits `IssueCode.BASE64` on failure.
175
+ */
176
+ declare function isBase64<C = unknown>(options?: BaseFactoryOptions & validator.IsBase64Options): ValidatorDescriptor<C>;
177
+ /**
178
+ * Factory: validator.js `isStrongPassword`. Emits
179
+ * `IssueCode.STRONG_PASSWORD` on failure. `data` carries only the
180
+ * documented strength-requirement keys (`minLength`, `minLowercase`,
181
+ * `minUppercase`, `minNumbers`, `minSymbols`) so i18n templates can quote
182
+ * them:
183
+ *
184
+ * ```ts
185
+ * isStrongPassword({ minLength: 12, minNumbers: 2 });
186
+ * // → IssueCode.STRONG_PASSWORD, data: { minLength: 12, minNumbers: 2 }
187
+ * ```
188
+ *
189
+ * Scoring weights (`pointsPerUnique`, `pointsForContainingLower`, …) are
190
+ * still forwarded to validator.js so they continue to influence the
191
+ * pass/fail decision (and any `returnScore`-shaped diagnostics), but they
192
+ * do NOT appear in `data` — i18n templates would never want to render
193
+ * "must score at least N points per unique character" to the user.
194
+ */
195
+ declare function isStrongPassword<C = unknown>(options?: BaseFactoryOptions & validator.StrongPasswordOptions): ValidatorDescriptor<C>;
196
+ //#endregion
197
+ //#region src/factories/type-assertions.d.ts
198
+ /**
199
+ * Factory: validator.js `isAlpha`. Emits `IssueCode.ALPHA` on failure.
200
+ *
201
+ * `locale` (validator.js's positional second arg) is promoted into the
202
+ * flat options object; everything else passes through as `IsAlphaOptions`.
203
+ */
204
+ declare function isAlpha<C = unknown>(options?: BaseFactoryOptions & validator.IsAlphaOptions & {
205
+ locale?: validator.AlphaLocale;
206
+ }): ValidatorDescriptor<C>;
207
+ /**
208
+ * Factory: validator.js `isAlphanumeric`. Emits `IssueCode.ALPHA_NUM` on failure.
209
+ */
210
+ declare function isAlphanumeric<C = unknown>(options?: BaseFactoryOptions & validator.IsAlphanumericOptions & {
211
+ locale?: validator.AlphanumericLocale;
212
+ }): ValidatorDescriptor<C>;
213
+ /**
214
+ * Factory: validator.js `isNumeric`. Emits `IssueCode.NUMERIC` on failure.
215
+ */
216
+ declare function isNumeric<C = unknown>(options?: BaseFactoryOptions & validator.IsNumericOptions): ValidatorDescriptor<C>;
217
+ /**
218
+ * Factory: validator.js `isDecimal`. Emits `IssueCode.DECIMAL` on failure.
219
+ */
220
+ declare function isDecimal<C = unknown>(options?: BaseFactoryOptions & validator.IsDecimalOptions): ValidatorDescriptor<C>;
221
+ /**
222
+ * Factory: validator.js `isInt`. Resolves the right vocabulary code
223
+ * based on what failed:
224
+ *
225
+ * - Value isn't an integer at all → `IssueCode.INTEGER`.
226
+ * - Value below `min` (inclusive) or `gt` (exclusive) → `IssueCode.MIN_VALUE`
227
+ * (data: `{ min }`). For `gt`, `data.min` is `options.gt` — i18n
228
+ * templates can quote the boundary; the precise inclusive/exclusive
229
+ * wording comes from `message`.
230
+ * - Value above `max` (inclusive) or `lt` (exclusive) → `IssueCode.MAX_VALUE`
231
+ * (data: `{ max }`). Same treatment as `gt` → `data.max` is `options.lt`.
232
+ */
233
+ declare function isInt<C = unknown>(options?: BaseFactoryOptions & validator.IsIntOptions): ValidatorDescriptor<C>;
234
+ /**
235
+ * Factory: validator.js `isFloat`. Like {@link isInt} but for decimal
236
+ * numbers — type failure emits `IssueCode.DECIMAL`; range bounds emit
237
+ * `MIN_VALUE` / `MAX_VALUE`. `lt` / `gt` map to `MIN_VALUE` / `MAX_VALUE`
238
+ * the same way `isInt` does.
239
+ *
240
+ * **Locale caveat.** validator.js's locale-aware float parsing (e.g.
241
+ * `'123,45'` under `locale: 'de-DE'`) is opaque to the factory — we use
242
+ * `Number(s)` for the explicit range checks, which returns `NaN` for
243
+ * localized strings. When `locale` is set and the input parses to `NaN`,
244
+ * we skip the explicit range checks and fall through to
245
+ * `validator.isFloat(s, options)`, which DOES handle the locale correctly
246
+ * — but a range failure caught there surfaces as `IssueCode.DECIMAL`
247
+ * instead of `MIN_VALUE` / `MAX_VALUE`. Use the default locale (or
248
+ * normalize the input upstream) when precise range codes matter for i18n.
249
+ */
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
package/dist/index.mjs ADDED
@@ -0,0 +1,441 @@
1
+ import validator from "validator";
2
+ import { IssueCode, createValidupError, defineValidator } from "validup";
3
+ //#region ../../node_modules/pathtrace/dist/index.mjs
4
+ const UNSAFE_KEYS = new Set([
5
+ "__proto__",
6
+ "constructor",
7
+ "prototype"
8
+ ]);
9
+ function isUnsafeKey(key) {
10
+ return UNSAFE_KEYS.has(key);
11
+ }
12
+ const BRACKET_NUMBER_REGEX = /(?<!\\)\[(\d+)]$/;
13
+ /**
14
+ * Convert string to property path array.
15
+ *
16
+ * @see https://github.com/lodash/lodash/blob/main/src/.internal/stringToPath.ts
17
+ * @see https://github.com/chaijs/pathval
18
+ *
19
+ * @param segment
20
+ */
21
+ function pathToArray(segment) {
22
+ if (typeof segment === "number") return [segment];
23
+ if (typeof segment === "symbol") return [];
24
+ const parts = segment.replace(/([^\\])\[/g, "$1.[").match(/(\\\.|[^.]+?)+/g);
25
+ if (!parts) return [];
26
+ const result = [];
27
+ for (const part of parts) {
28
+ if (isUnsafeKey(part)) continue;
29
+ const regex = BRACKET_NUMBER_REGEX.exec(part);
30
+ if (regex) result.push(Number(regex[1]));
31
+ else result.push(part.replace(/\\([.[\]])/g, "$1"));
32
+ }
33
+ return result;
34
+ }
35
+ function getPathValue(data, path) {
36
+ const parts = Array.isArray(path) ? path : pathToArray(path);
37
+ let res;
38
+ let temp = data;
39
+ let index = 0;
40
+ while (index < parts.length) {
41
+ if (temp === null || typeof temp === "undefined") break;
42
+ if (isUnsafeKey(parts[index])) break;
43
+ if (parts[index] in Object(temp)) temp = temp[parts[index]];
44
+ else break;
45
+ if (index === parts.length - 1) res = temp;
46
+ index++;
47
+ }
48
+ return res;
49
+ }
50
+ //#endregion
51
+ //#region src/module.ts
52
+ /**
53
+ * Build a string representation suitable for validator.js. validator.js
54
+ * functions expect strings; for numbers and booleans we use `String(...)`
55
+ * so consumers can mount `isInt()` on a `number`-shaped field without
56
+ * pre-stringifying.
57
+ */
58
+ function toValidatorString(value) {
59
+ if (typeof value === "string") return value;
60
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
61
+ if (value === null || value === void 0) return "";
62
+ return String(value);
63
+ }
64
+ /**
65
+ * Generic wrap for any validator.js function we don't ship a pre-baked
66
+ * factory for. The wrapped validator stringifies `ctx.value`, calls the
67
+ * validator.js predicate, and throws a `ValidupError` carrying the
68
+ * supplied `code` (+ optional `data`) on failure.
69
+ *
70
+ * @example
71
+ * import validator from 'validator';
72
+ * import { createValidator } from '@validup/validator-js';
73
+ *
74
+ * container.mount('card', createValidator(validator.isCreditCard, {
75
+ * code: 'credit_card',
76
+ * message: 'Invalid credit card number',
77
+ * }));
78
+ *
79
+ * For the common cases — `email()`, `isLength()`, `isInt()` etc. — reach
80
+ * for the pre-baked factories instead; they bake the right vocabulary
81
+ * code and `data` in for you.
82
+ *
83
+ * The returned descriptor participates in the validup result cache by
84
+ * default — validator.js's `ValidatorJsFn` signature is synchronous
85
+ * and only inspects the stringified value, so the outcome is a pure
86
+ * function of `(ctx.value, ctx.context, ctx.group)`. If the wrapped
87
+ * predicate captures external state and the caller knowingly opts
88
+ * into that, pass `sideEffect: true` to bypass the cache.
89
+ */
90
+ function createValidator(fn, options) {
91
+ const fallbackCode = options.code || IssueCode.VALUE_INVALID;
92
+ const fallbackMessage = options.message ?? "The value is invalid";
93
+ return defineValidator({
94
+ sideEffect: options.sideEffect,
95
+ run: (ctx) => {
96
+ if (fn(toValidatorString(ctx.value))) return ctx.value;
97
+ throw createValidupError(ctx.value, fallbackCode, fallbackMessage, options.data);
98
+ }
99
+ });
100
+ }
101
+ //#endregion
102
+ //#region src/factories/comparison.ts
103
+ /**
104
+ * Factory: validator.js `matches`. Emits `IssueCode.PATTERN` on failure
105
+ * with `data: { pattern: string }` (the regex source, no flags) so
106
+ * i18n templates can quote it.
107
+ */
108
+ function matches(pattern, options = {}) {
109
+ const patternSource = typeof pattern === "string" ? pattern : pattern.source;
110
+ return defineValidator({ run: (ctx) => {
111
+ const s = toValidatorString(ctx.value);
112
+ if (typeof pattern === "string" ? validator.matches(s, pattern, options.modifiers) : validator.matches(s, pattern)) return ctx.value;
113
+ throw createValidupError(ctx.value, IssueCode.PATTERN, options.message ?? "The value does not match the expected pattern", { pattern: patternSource });
114
+ } });
115
+ }
116
+ /**
117
+ * Factory: validator.js `equals`. Emits `IssueCode.SAME_AS` on failure
118
+ * with `data: { other: string }` so a translated message can quote the
119
+ * key subject (e.g. "must equal {{other}}").
120
+ *
121
+ * `key` is the field-name / label the i18n template should
122
+ * surface. When `expectedValue` is omitted, `key` is also used as a
123
+ * pathtrace path into `ctx.data` to look up the runtime comparison
124
+ * target — so `equals('password')` mounted on `passwordConfirm`
125
+ * compares against `ctx.data.password`. Pass `expectedValue`
126
+ * explicitly to compare against a fixed string instead.
127
+ *
128
+ * **Side-effect contract.** When `expectedValue` is provided the
129
+ * validator is a pure function of `ctx.value` and participates in the
130
+ * result cache like every other factory. When `expectedValue` is
131
+ * omitted the validator reads `ctx.data[key]` — a sibling field —
132
+ * which the cache's `(value, context, group)` snapshot does NOT
133
+ * capture. The factory therefore stamps `sideEffect: true` in that
134
+ * branch so the framework re-runs it on every invocation; otherwise a
135
+ * `passwordConfirm` check would stay stale after `password` changes.
136
+ */
137
+ function equals(key, options = {}) {
138
+ return defineValidator({
139
+ sideEffect: typeof options.expectedValue === "undefined",
140
+ run: (ctx) => {
141
+ const s = toValidatorString(ctx.value);
142
+ const target = options.expectedValue ?? toValidatorString(getPathValue(ctx.data, key));
143
+ if (validator.equals(s, target)) return ctx.value;
144
+ throw createValidupError(ctx.value, IssueCode.SAME_AS, options.message ?? `The value must equal ${key}`, { other: key });
145
+ }
146
+ });
147
+ }
148
+ //#endregion
149
+ //#region src/factories/length.ts
150
+ /**
151
+ * Factory: validator.js `isLength`. Detects which bound failed at
152
+ * validation time so the resulting issue carries a useful vocabulary
153
+ * code:
154
+ *
155
+ * - Too short → `IssueCode.MIN_LENGTH` (data: `{ min }`).
156
+ * - Too long → `IssueCode.MAX_LENGTH` (data: `{ max }`).
157
+ *
158
+ * Calling without `min` / `max` is allowed but degenerate — every value
159
+ * passes. `message` overrides the default English string for both bound
160
+ * failures.
161
+ */
162
+ function isLength(options = {}) {
163
+ const { min, max } = options;
164
+ return defineValidator({ run: (ctx) => {
165
+ const s = toValidatorString(ctx.value);
166
+ if (validator.isLength(s, options)) return ctx.value;
167
+ if (typeof min === "number" && s.length < min) throw createValidupError(ctx.value, IssueCode.MIN_LENGTH, options.message ?? `The minimum length allowed is ${min}`, { min });
168
+ if (typeof max === "number" && s.length > max) throw createValidupError(ctx.value, IssueCode.MAX_LENGTH, options.message ?? `The maximum length allowed is ${max}`, { max });
169
+ if (typeof min === "number") throw createValidupError(ctx.value, IssueCode.MIN_LENGTH, options.message ?? "The value has an invalid length", { min });
170
+ throw createValidupError(ctx.value, IssueCode.VALUE_INVALID, options.message ?? "The value has an invalid length");
171
+ } });
172
+ }
173
+ //#endregion
174
+ //#region src/factories/string-format.ts
175
+ /**
176
+ * Factory: validator.js `isEmail`. Emits `IssueCode.EMAIL` on failure.
177
+ *
178
+ * Options are flattened — pass validator.js's `IsEmailOptions` keys
179
+ * (`require_display_name`, `allow_utf8_local_part`, …) directly alongside
180
+ * the validup-side `message` override.
181
+ */
182
+ function isEmail(options = {}) {
183
+ const message = options.message ?? "The value is not a valid email address";
184
+ return defineValidator({ run: (ctx) => {
185
+ const s = toValidatorString(ctx.value);
186
+ if (validator.isEmail(s, options)) return ctx.value;
187
+ throw createValidupError(ctx.value, IssueCode.EMAIL, message);
188
+ } });
189
+ }
190
+ /**
191
+ * Factory: validator.js `isURL`. Emits `IssueCode.URL` on failure.
192
+ */
193
+ function isURL(options = {}) {
194
+ const message = options.message ?? "The value is not a valid URL";
195
+ return defineValidator({ run: (ctx) => {
196
+ const s = toValidatorString(ctx.value);
197
+ if (validator.isURL(s, options)) return ctx.value;
198
+ throw createValidupError(ctx.value, IssueCode.URL, message);
199
+ } });
200
+ }
201
+ /**
202
+ * Factory: validator.js `isUUID`. Emits `IssueCode.UUID` on failure.
203
+ *
204
+ * `version` mirrors validator.js's positional second argument
205
+ * (`'1' | '2' | '3' | '4' | '5' | 'all' | 1 | …`). Promoted into the
206
+ * options object so the call site is consistent with the other factories.
207
+ */
208
+ function isUUID(options = {}) {
209
+ const message = options.message ?? "The value is not a valid UUID";
210
+ return defineValidator({ run: (ctx) => {
211
+ const s = toValidatorString(ctx.value);
212
+ if (validator.isUUID(s, options.version)) return ctx.value;
213
+ throw createValidupError(ctx.value, IssueCode.UUID, message);
214
+ } });
215
+ }
216
+ /**
217
+ * Factory: validator.js `isIP`. Emits `IssueCode.IP_ADDRESS` on failure.
218
+ *
219
+ * `version` mirrors validator.js's positional second argument.
220
+ */
221
+ function isIP(options = {}) {
222
+ const message = options.message ?? "The value is not a valid IP address";
223
+ return defineValidator({ run: (ctx) => {
224
+ const s = toValidatorString(ctx.value);
225
+ if (validator.isIP(s, options.version)) return ctx.value;
226
+ throw createValidupError(ctx.value, IssueCode.IP_ADDRESS, message);
227
+ } });
228
+ }
229
+ /**
230
+ * Factory: validator.js `isMACAddress`. Emits `IssueCode.MAC_ADDRESS` on failure.
231
+ */
232
+ function isMACAddress(options = {}) {
233
+ const message = options.message ?? "The value is not a valid MAC address";
234
+ return defineValidator({ run: (ctx) => {
235
+ const s = toValidatorString(ctx.value);
236
+ if (validator.isMACAddress(s, options)) return ctx.value;
237
+ throw createValidupError(ctx.value, IssueCode.MAC_ADDRESS, message);
238
+ } });
239
+ }
240
+ /**
241
+ * Factory: validator.js `isDate`. Emits `IssueCode.DATE` on failure.
242
+ */
243
+ function isDate(options = {}) {
244
+ const message = options.message ?? "The value is not a valid date";
245
+ return defineValidator({ run: (ctx) => {
246
+ const s = toValidatorString(ctx.value);
247
+ if (validator.isDate(s, options)) return ctx.value;
248
+ throw createValidupError(ctx.value, IssueCode.DATE, message);
249
+ } });
250
+ }
251
+ /**
252
+ * Factory: validator.js `isISO8601`. Emits `IssueCode.DATE` on failure
253
+ * (same code as `isDate` — both produce the "is this a parseable date"
254
+ * outcome from the consumer's perspective).
255
+ */
256
+ function isISO8601(options = {}) {
257
+ const message = options.message ?? "The value is not a valid date";
258
+ return defineValidator({ run: (ctx) => {
259
+ const s = toValidatorString(ctx.value);
260
+ if (validator.isISO8601(s, options)) return ctx.value;
261
+ throw createValidupError(ctx.value, IssueCode.DATE, message);
262
+ } });
263
+ }
264
+ /**
265
+ * Factory: validator.js `isJSON`. Emits `IssueCode.JSON` on failure.
266
+ */
267
+ function isJSON(options = {}) {
268
+ const message = options.message ?? "The value is not valid JSON";
269
+ return defineValidator({ run: (ctx) => {
270
+ const s = toValidatorString(ctx.value);
271
+ if (validator.isJSON(s, options)) return ctx.value;
272
+ throw createValidupError(ctx.value, IssueCode.JSON, message);
273
+ } });
274
+ }
275
+ /**
276
+ * Factory: validator.js `isBase64`. Emits `IssueCode.BASE64` on failure.
277
+ */
278
+ function isBase64(options = {}) {
279
+ const message = options.message ?? "The value is not valid base64";
280
+ return defineValidator({ run: (ctx) => {
281
+ const s = toValidatorString(ctx.value);
282
+ if (validator.isBase64(s, options)) return ctx.value;
283
+ throw createValidupError(ctx.value, IssueCode.BASE64, message);
284
+ } });
285
+ }
286
+ /**
287
+ * The subset of `validator.StrongPasswordOptions` keys that describe
288
+ * *strength requirements* — what the consumer wants the password to look
289
+ * like, as opposed to scoring weights (`pointsPerUnique`,
290
+ * `pointsForContainingLower`, …) which only affect validator.js's
291
+ * `returnScore` mode. Only these keys surface on `IssueCode.STRONG_PASSWORD`'s
292
+ * `data` payload, matching the documented vocabulary contract.
293
+ */
294
+ const STRONG_PASSWORD_REQUIREMENT_KEYS = [
295
+ "minLength",
296
+ "minLowercase",
297
+ "minUppercase",
298
+ "minNumbers",
299
+ "minSymbols"
300
+ ];
301
+ /**
302
+ * Factory: validator.js `isStrongPassword`. Emits
303
+ * `IssueCode.STRONG_PASSWORD` on failure. `data` carries only the
304
+ * documented strength-requirement keys (`minLength`, `minLowercase`,
305
+ * `minUppercase`, `minNumbers`, `minSymbols`) so i18n templates can quote
306
+ * them:
307
+ *
308
+ * ```ts
309
+ * isStrongPassword({ minLength: 12, minNumbers: 2 });
310
+ * // → IssueCode.STRONG_PASSWORD, data: { minLength: 12, minNumbers: 2 }
311
+ * ```
312
+ *
313
+ * Scoring weights (`pointsPerUnique`, `pointsForContainingLower`, …) are
314
+ * still forwarded to validator.js so they continue to influence the
315
+ * pass/fail decision (and any `returnScore`-shaped diagnostics), but they
316
+ * do NOT appear in `data` — i18n templates would never want to render
317
+ * "must score at least N points per unique character" to the user.
318
+ */
319
+ function isStrongPassword(options = {}) {
320
+ const message = options.message ?? "The value does not meet the password strength requirements";
321
+ const { message: _ignored, returnScore: _alsoIgnored, ...rest } = options;
322
+ const paramsTemplate = {};
323
+ for (const key of STRONG_PASSWORD_REQUIREMENT_KEYS) if (typeof rest[key] === "number") paramsTemplate[key] = rest[key];
324
+ return defineValidator({ run: (ctx) => {
325
+ const s = toValidatorString(ctx.value);
326
+ const probeOptions = { ...rest };
327
+ if (validator.isStrongPassword(s, probeOptions) === true) return ctx.value;
328
+ throw createValidupError(ctx.value, IssueCode.STRONG_PASSWORD, message, { ...paramsTemplate });
329
+ } });
330
+ }
331
+ //#endregion
332
+ //#region src/factories/type-assertions.ts
333
+ /**
334
+ * Factory: validator.js `isAlpha`. Emits `IssueCode.ALPHA` on failure.
335
+ *
336
+ * `locale` (validator.js's positional second arg) is promoted into the
337
+ * flat options object; everything else passes through as `IsAlphaOptions`.
338
+ */
339
+ function isAlpha(options = {}) {
340
+ const message = options.message ?? "The value is not alphabetical";
341
+ return defineValidator({ run: (ctx) => {
342
+ const s = toValidatorString(ctx.value);
343
+ if (validator.isAlpha(s, options.locale, options)) return ctx.value;
344
+ throw createValidupError(ctx.value, IssueCode.ALPHA, message);
345
+ } });
346
+ }
347
+ /**
348
+ * Factory: validator.js `isAlphanumeric`. Emits `IssueCode.ALPHA_NUM` on failure.
349
+ */
350
+ function isAlphanumeric(options = {}) {
351
+ const message = options.message ?? "The value must be alphanumeric";
352
+ return defineValidator({ run: (ctx) => {
353
+ const s = toValidatorString(ctx.value);
354
+ if (validator.isAlphanumeric(s, options.locale, options)) return ctx.value;
355
+ throw createValidupError(ctx.value, IssueCode.ALPHA_NUM, message);
356
+ } });
357
+ }
358
+ /**
359
+ * Factory: validator.js `isNumeric`. Emits `IssueCode.NUMERIC` on failure.
360
+ */
361
+ function isNumeric(options = {}) {
362
+ const message = options.message ?? "The value must be numeric";
363
+ return defineValidator({ run: (ctx) => {
364
+ const s = toValidatorString(ctx.value);
365
+ if (validator.isNumeric(s, options)) return ctx.value;
366
+ throw createValidupError(ctx.value, IssueCode.NUMERIC, message);
367
+ } });
368
+ }
369
+ /**
370
+ * Factory: validator.js `isDecimal`. Emits `IssueCode.DECIMAL` on failure.
371
+ */
372
+ function isDecimal(options = {}) {
373
+ const message = options.message ?? "The value must be a decimal number";
374
+ return defineValidator({ run: (ctx) => {
375
+ const s = toValidatorString(ctx.value);
376
+ if (validator.isDecimal(s, options)) return ctx.value;
377
+ throw createValidupError(ctx.value, IssueCode.DECIMAL, message);
378
+ } });
379
+ }
380
+ /**
381
+ * Factory: validator.js `isInt`. Resolves the right vocabulary code
382
+ * based on what failed:
383
+ *
384
+ * - Value isn't an integer at all → `IssueCode.INTEGER`.
385
+ * - Value below `min` (inclusive) or `gt` (exclusive) → `IssueCode.MIN_VALUE`
386
+ * (data: `{ min }`). For `gt`, `data.min` is `options.gt` — i18n
387
+ * templates can quote the boundary; the precise inclusive/exclusive
388
+ * wording comes from `message`.
389
+ * - Value above `max` (inclusive) or `lt` (exclusive) → `IssueCode.MAX_VALUE`
390
+ * (data: `{ max }`). Same treatment as `gt` → `data.max` is `options.lt`.
391
+ */
392
+ function isInt(options = {}) {
393
+ return defineValidator({ run: (ctx) => {
394
+ const s = toValidatorString(ctx.value);
395
+ if (!validator.isInt(s, { allow_leading_zeroes: options.allow_leading_zeroes })) throw createValidupError(ctx.value, IssueCode.INTEGER, options.message ?? "The value must be an integer");
396
+ const numeric = Number(s);
397
+ const { min, max, lt, gt } = options;
398
+ if (typeof min === "number" && numeric < min) throw createValidupError(ctx.value, IssueCode.MIN_VALUE, options.message ?? `The value must be greater than or equal to ${min}`, { min });
399
+ if (typeof gt === "number" && numeric <= gt) throw createValidupError(ctx.value, IssueCode.MIN_VALUE, options.message ?? `The value must be greater than ${gt}`, { min: gt });
400
+ if (typeof max === "number" && numeric > max) throw createValidupError(ctx.value, IssueCode.MAX_VALUE, options.message ?? `The value must be less than or equal to ${max}`, { max });
401
+ if (typeof lt === "number" && numeric >= lt) throw createValidupError(ctx.value, IssueCode.MAX_VALUE, options.message ?? `The value must be less than ${lt}`, { max: lt });
402
+ if (!validator.isInt(s, options)) throw createValidupError(ctx.value, IssueCode.INTEGER, options.message ?? "The value must be an integer");
403
+ return ctx.value;
404
+ } });
405
+ }
406
+ /**
407
+ * Factory: validator.js `isFloat`. Like {@link isInt} but for decimal
408
+ * numbers — type failure emits `IssueCode.DECIMAL`; range bounds emit
409
+ * `MIN_VALUE` / `MAX_VALUE`. `lt` / `gt` map to `MIN_VALUE` / `MAX_VALUE`
410
+ * the same way `isInt` does.
411
+ *
412
+ * **Locale caveat.** validator.js's locale-aware float parsing (e.g.
413
+ * `'123,45'` under `locale: 'de-DE'`) is opaque to the factory — we use
414
+ * `Number(s)` for the explicit range checks, which returns `NaN` for
415
+ * localized strings. When `locale` is set and the input parses to `NaN`,
416
+ * we skip the explicit range checks and fall through to
417
+ * `validator.isFloat(s, options)`, which DOES handle the locale correctly
418
+ * — but a range failure caught there surfaces as `IssueCode.DECIMAL`
419
+ * instead of `MIN_VALUE` / `MAX_VALUE`. Use the default locale (or
420
+ * normalize the input upstream) when precise range codes matter for i18n.
421
+ */
422
+ function isFloat(options = {}) {
423
+ return defineValidator({ run: (ctx) => {
424
+ const s = toValidatorString(ctx.value);
425
+ if (!validator.isFloat(s, { locale: options.locale })) throw createValidupError(ctx.value, IssueCode.DECIMAL, options.message ?? "The value must be a decimal number");
426
+ const numeric = Number(s);
427
+ const { min, max, lt, gt } = options;
428
+ if (!Number.isNaN(numeric)) {
429
+ if (typeof min === "number" && numeric < min) throw createValidupError(ctx.value, IssueCode.MIN_VALUE, options.message ?? `The value must be greater than or equal to ${min}`, { min });
430
+ if (typeof gt === "number" && numeric <= gt) throw createValidupError(ctx.value, IssueCode.MIN_VALUE, options.message ?? `The value must be greater than ${gt}`, { min: gt });
431
+ if (typeof max === "number" && numeric > max) throw createValidupError(ctx.value, IssueCode.MAX_VALUE, options.message ?? `The value must be less than or equal to ${max}`, { max });
432
+ if (typeof lt === "number" && numeric >= lt) throw createValidupError(ctx.value, IssueCode.MAX_VALUE, options.message ?? `The value must be less than ${lt}`, { max: lt });
433
+ }
434
+ if (!validator.isFloat(s, options)) throw createValidupError(ctx.value, IssueCode.DECIMAL, options.message ?? "The value must be a decimal number");
435
+ return ctx.value;
436
+ } });
437
+ }
438
+ //#endregion
439
+ export { createValidator, equals, isAlpha, isAlphanumeric, isBase64, isDate, isDecimal, isEmail, isFloat, isIP, isISO8601, isInt, isJSON, isLength, isMACAddress, isNumeric, isStrongPassword, isURL, isUUID, matches, toValidatorString };
440
+
441
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../node_modules/pathtrace/dist/index.mjs","../src/module.ts","../src/factories/comparison.ts","../src/factories/length.ts","../src/factories/string-format.ts","../src/factories/type-assertions.ts"],"sourcesContent":["//#region src/helpers/array-to-path.ts\n/**\n* @see https://github.com/express-validator/express-validator/blob/bec1dcbaa29002dcd21093ec84818c4671063b5d/src/field-selection.ts#L214\n* @param parts\n*/\nfunction arrayToPath(parts) {\n\tlet output = \"\";\n\tfor (let part of parts) {\n\t\tlet current = \"\";\n\t\tif (typeof part === \"string\") {\n\t\t\tpart = part.replace(/^\\[(\\d+)]$/g, \"\\\\[$1]\");\n\t\t\tpart = part.replace(/\\./g, \"\\\\.\");\n\t\t\tif (/^\\d+$/.test(part)) current = `[${part}]`;\n\t\t\telse if (output) current = `.${part}`;\n\t\t\telse current = part;\n\t\t} else if (typeof part === \"number\") current = `[${part}]`;\n\t\toutput += current;\n\t}\n\treturn output;\n}\n//#endregion\n//#region src/utils/is-object.ts\nfunction isObject(input) {\n\treturn !!input && typeof input === \"object\" && !Array.isArray(input);\n}\n//#endregion\n//#region src/utils/is-unsafe-key.ts\nconst UNSAFE_KEYS = new Set([\n\t\"__proto__\",\n\t\"constructor\",\n\t\"prototype\"\n]);\nfunction isUnsafeKey(key) {\n\treturn UNSAFE_KEYS.has(key);\n}\n//#endregion\n//#region src/helpers/path-to-array.ts\nconst BRACKET_NUMBER_REGEX = /(?<!\\\\)\\[(\\d+)]$/;\n/**\n* Convert string to property path array.\n*\n* @see https://github.com/lodash/lodash/blob/main/src/.internal/stringToPath.ts\n* @see https://github.com/chaijs/pathval\n*\n* @param segment\n*/\nfunction pathToArray(segment) {\n\tif (typeof segment === \"number\") return [segment];\n\tif (typeof segment === \"symbol\") return [];\n\tconst parts = segment.replace(/([^\\\\])\\[/g, \"$1.[\").match(/(\\\\\\.|[^.]+?)+/g);\n\tif (!parts) return [];\n\tconst result = [];\n\tfor (const part of parts) {\n\t\tif (isUnsafeKey(part)) continue;\n\t\tconst regex = BRACKET_NUMBER_REGEX.exec(part);\n\t\tif (regex) result.push(Number(regex[1]));\n\t\telse result.push(part.replace(/\\\\([.[\\]])/g, \"$1\"));\n\t}\n\treturn result;\n}\n//#endregion\n//#region src/path-expand/constants.ts\nlet Character = /* @__PURE__ */ function(Character) {\n\tCharacter[\"WILDCARD\"] = \"*\";\n\tCharacter[\"GLOBSTAR\"] = \"**\";\n\treturn Character;\n}({});\n//#endregion\n//#region src/path-expand/module.ts\nfunction expandPathVerboseInternal(data, path, currPath = [], currMatches = []) {\n\tconst segments = Array.isArray(path) ? path : pathToArray(path);\n\tif (!segments.length) return [{\n\t\tvalue: arrayToPath(currPath),\n\t\tmatches: currMatches\n\t}];\n\tconst key = segments[0];\n\tif (typeof key === \"symbol\") return [];\n\tconst rest = segments.slice(1);\n\tif (typeof data !== \"undefined\" && data !== null && !isObject(data) && !Array.isArray(data)) {\n\t\tif (key === Character.GLOBSTAR) {\n\t\t\tif (!rest.length) return [{\n\t\t\t\tvalue: arrayToPath(currPath),\n\t\t\t\tmatches: currMatches\n\t\t\t}];\n\t\t\treturn [];\n\t\t}\n\t\tif (key === Character.WILDCARD) return [];\n\t\treturn [{\n\t\t\tvalue: arrayToPath([...currPath, ...segments]),\n\t\t\tmatches: currMatches\n\t\t}];\n\t}\n\tdata = data || {};\n\tif (key === Character.WILDCARD) return Object.keys(data).flatMap((key) => expandPathVerboseInternal(data[key], arrayToPath(rest), currPath.concat(key), currMatches.concat(key)));\n\tif (key === Character.GLOBSTAR) return Object.keys(data).flatMap((key) => {\n\t\tconst nextPath = currPath.concat(key);\n\t\tconst value = data[key];\n\t\tconst children = expandPathVerboseInternal(value, arrayToPath(segments), nextPath, [key]).concat(rest[0] === key ? expandPathVerboseInternal(value, arrayToPath(rest.slice(1)), nextPath, []) : []);\n\t\tconst pathMatches = [];\n\t\tconst output = [];\n\t\tfor (const child of children) {\n\t\t\t/* istanbul ignore next */\n\t\t\tif (pathMatches.includes(child.value)) continue;\n\t\t\tpathMatches.push(child.value);\n\t\t\toutput.push({\n\t\t\t\tvalue: child.value,\n\t\t\t\tmatches: child.matches.length > 0 ? [...currMatches, child.matches.flat()] : currMatches\n\t\t\t});\n\t\t}\n\t\treturn output;\n\t});\n\treturn expandPathVerboseInternal(data[key], rest, currPath.concat(key), currMatches);\n}\n/**\n* Verbose expand wildcard and glob patterns.\n* Track wildcard/glob pattern matches.\n*\n* @param data\n* @param path\n*/\nfunction expandPathVerbose(data, path) {\n\treturn expandPathVerboseInternal(data, path);\n}\n/**\n* Expand wildcard and glob patterns to paths.\n*\n* @param data\n* @param path\n*/\nfunction expandPath(data, path) {\n\treturn expandPathVerbose(data, path).map((el) => el.value);\n}\n//#endregion\n//#region src/path-value/get.ts\nfunction getPathValue(data, path) {\n\tconst parts = Array.isArray(path) ? path : pathToArray(path);\n\tlet res;\n\tlet temp = data;\n\tlet index = 0;\n\twhile (index < parts.length) {\n\t\tif (temp === null || typeof temp === \"undefined\") break;\n\t\tif (isUnsafeKey(parts[index])) break;\n\t\tif (parts[index] in Object(temp)) temp = temp[parts[index]];\n\t\telse break;\n\t\tif (index === parts.length - 1) res = temp;\n\t\tindex++;\n\t}\n\treturn res;\n}\n//#endregion\n//#region src/path-value/set.ts\nconst NUMBER_REGEX = /^\\d+$/;\nfunction setPathValue(data, path, value) {\n\tconst parts = Array.isArray(path) ? path : pathToArray(path);\n\tlet temp = data;\n\tlet index = 0;\n\twhile (index < parts.length) {\n\t\t/* istanbul ignore next */\n\t\tif (!Array.isArray(temp) && !isObject(temp)) break;\n\t\tconst key = parts[index];\n\t\tif (isUnsafeKey(key)) break;\n\t\tif (typeof temp[key] === \"undefined\") if (NUMBER_REGEX.test(key)) temp[key] = [];\n\t\telse temp[key] = {};\n\t\tif (index === parts.length - 1) {\n\t\t\ttemp[key] = value;\n\t\t\tbreak;\n\t\t}\n\t\tindex++;\n\t\ttemp = temp[key];\n\t}\n\treturn data;\n}\n//#endregion\n//#region src/path-info/module.ts\nvar PathInfo = class PathInfo {\n\tdata;\n\tpathParts;\n\t_value;\n\t_parent;\n\t_exists;\n\tconstructor(data, path) {\n\t\tthis.data = data;\n\t\tif (Array.isArray(path)) this.pathParts = path.filter((p) => !isUnsafeKey(p));\n\t\telse this.pathParts = pathToArray(path);\n\t}\n\tget value() {\n\t\tif (typeof this._value !== \"undefined\") return this._value;\n\t\tif (this.pathParts.length > 0) this._value = getPathValue(this.data, this.pathParts);\n\t\telse this._value = this.data;\n\t\treturn this._value;\n\t}\n\tget name() {\n\t\tif (this.pathParts.length > 0) return this.pathParts[this.pathParts.length - 1];\n\t\treturn null;\n\t}\n\tget parent() {\n\t\tif (typeof this._parent !== \"undefined\") return this._parent;\n\t\tif (this.pathParts.length === 0) {\n\t\t\tthis._parent = null;\n\t\t\treturn this._parent;\n\t\t}\n\t\tif (this.pathParts.length > 1) this._parent = new PathInfo(this.data, this.pathParts.slice(0, this.pathParts.length - 1));\n\t\telse this._parent = new PathInfo(this.data, []);\n\t\treturn this._parent;\n\t}\n\tget exists() {\n\t\tif (typeof this._exists !== \"undefined\") return this._exists;\n\t\tif (!this.name || !this.parent) {\n\t\t\tthis._exists = true;\n\t\t\treturn this._exists;\n\t\t}\n\t\tif (this.parent.value !== null && typeof this.parent.value !== \"undefined\") this._exists = this.name in Object(this.parent.value);\n\t\telse this._exists = false;\n\t\treturn this._exists;\n\t}\n};\n//#endregion\n//#region src/path-info/helper.ts\nfunction getPathInfo(data, path) {\n\treturn new PathInfo(data, path);\n}\n//#endregion\n//#region src/remove.ts\nfunction removePath(data, path) {\n\tconst parts = Array.isArray(path) ? path : pathToArray(path);\n\tlet temp = data;\n\tlet index = 0;\n\twhile (index < parts.length) {\n\t\t/* istanbul ignore next */\n\t\tif (!Array.isArray(temp) && !isObject(temp)) break;\n\t\tconst key = parts[index];\n\t\tif (isUnsafeKey(key)) break;\n\t\tif (!Object.prototype.hasOwnProperty.call(temp, key)) break;\n\t\tif (index === parts.length - 1) {\n\t\t\tif (Array.isArray(temp)) {\n\t\t\t\tconst tempKey = Number(key);\n\t\t\t\tif (!Number.isNaN(tempKey)) {\n\t\t\t\t\ttemp.splice(tempKey, 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdelete temp[key];\n\t\t\tbreak;\n\t\t}\n\t\tindex++;\n\t\ttemp = temp[key];\n\t}\n}\n//#endregion\nexport { BRACKET_NUMBER_REGEX, PathInfo, arrayToPath, expandPath, expandPathVerbose, getPathInfo, getPathValue, pathToArray, removePath, setPathValue };\n\n//# sourceMappingURL=index.mjs.map","/*\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 {\n IssueCode,\n createValidupError,\n defineValidator,\n} 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, 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, 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, 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, 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 * 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 const numeric = Number(s);\n const {\n min,\n max,\n lt,\n gt,\n } = options;\n if (typeof min === 'number' && numeric < min) {\n throw createValidupError(\n ctx.value,\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 ctx.value,\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 ctx.value,\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 ctx.value,\n IssueCode.MAX_VALUE,\n options.message ?? `The value must be less than ${lt}`,\n { max: lt },\n );\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 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`. `lt` / `gt` map to `MIN_VALUE` / `MAX_VALUE`\n * the same way `isInt` does.\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 const {\n min,\n max,\n lt,\n gt,\n } = options;\n // NaN from a localized input skips the explicit range checks — see\n // the JSDoc above for the resulting code-vs-message trade-off.\n if (!Number.isNaN(numeric)) {\n if (typeof min === 'number' && numeric < min) {\n throw createValidupError(\n ctx.value,\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 ctx.value,\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 ctx.value,\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 ctx.value,\n IssueCode.MAX_VALUE,\n options.message ?? `The value must be less than ${lt}`,\n { max: lt },\n );\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 return ctx.value;\n },\n });\n}\n"],"x_google_ignoreList":[0],"mappings":";;;AA2BA,MAAM,cAAc,IAAI,IAAI;CAC3B;CACA;CACA;AACD,CAAC;AACD,SAAS,YAAY,KAAK;CACzB,OAAO,YAAY,IAAI,GAAG;AAC3B;AAGA,MAAM,uBAAuB;;;;;;;;;AAS7B,SAAS,YAAY,SAAS;CAC7B,IAAI,OAAO,YAAY,UAAU,OAAO,CAAC,OAAO;CAChD,IAAI,OAAO,YAAY,UAAU,OAAO,CAAC;CACzC,MAAM,QAAQ,QAAQ,QAAQ,cAAc,MAAM,EAAE,MAAM,iBAAiB;CAC3E,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,QAAQ,OAAO;EACzB,IAAI,YAAY,IAAI,GAAG;EACvB,MAAM,QAAQ,qBAAqB,KAAK,IAAI;EAC5C,IAAI,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE,CAAC;OAClC,OAAO,KAAK,KAAK,QAAQ,eAAe,IAAI,CAAC;CACnD;CACA,OAAO;AACR;AA2EA,SAAS,aAAa,MAAM,MAAM;CACjC,MAAM,QAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,YAAY,IAAI;CAC3D,IAAI;CACJ,IAAI,OAAO;CACX,IAAI,QAAQ;CACZ,OAAO,QAAQ,MAAM,QAAQ;EAC5B,IAAI,SAAS,QAAQ,OAAO,SAAS,a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version": "0.2.0",
4
+ "type": "module",
5
+ "description": "validator.js integration for validup — pre-baked factories per common rule plus a generic createValidator for the long tail.",
6
+ "author": {
7
+ "name": "Peter Placzek",
8
+ "email": "contact@tada5hi.net",
9
+ "url": "https://github.com/tada5hi"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/tada5hi/validup.git",
14
+ "directory": "packages/validator-js"
15
+ },
16
+ "main": "dist/index.mjs",
17
+ "types": "dist/index.d.mts",
18
+ "exports": {
19
+ "./package.json": "./package.json",
20
+ ".": {
21
+ "types": "./dist/index.d.mts",
22
+ "import": "./dist/index.mjs"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "engines": {
29
+ "node": ">=24.0.0"
30
+ },
31
+ "scripts": {
32
+ "build:types": "tsc --noEmit -p tsconfig.build.json",
33
+ "build:js": "tsdown",
34
+ "build": "npm run build:types && npm run build:js",
35
+ "test": "vitest --config test/vitest.config.ts --run",
36
+ "test:coverage": "vitest --config test/vitest.config.ts --run --coverage"
37
+ },
38
+ "keywords": [
39
+ "validup",
40
+ "validator",
41
+ "validation",
42
+ "validatorjs"
43
+ ],
44
+ "license": "Apache-2.0",
45
+ "devDependencies": {
46
+ "@types/validator": "^13.12.2",
47
+ "validator": "^13.12.0"
48
+ },
49
+ "peerDependencies": {
50
+ "validup": "^0.4.0",
51
+ "validator": "^13.0.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }