@validup/validator-js 1.0.0 → 2.0.1
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 +2 -2
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @validup/validator-js validator validup --save
|
|
|
14
14
|
|
|
15
15
|
| Peer dependency | Supported versions |
|
|
16
16
|
|-----------------|--------------------|
|
|
17
|
-
| `validup` | `^
|
|
17
|
+
| `validup` | `^2.0.0` |
|
|
18
18
|
| `validator` | `^13.0.0` |
|
|
19
19
|
|
|
20
20
|
## Quick Start
|
|
@@ -130,7 +130,7 @@ container.mount('phone', createValidator(
|
|
|
130
130
|
- `fn` — any function with the signature `(value: string, ...args: any[]) => boolean`. validator.js's predicates all fit.
|
|
131
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
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 (`{
|
|
133
|
+
- `data` — structured payload surfaced on `IssueItem.data`. Optional; templates that reference placeholders (`{locale}`, `{min}`, …) resolve against this.
|
|
134
134
|
- `sideEffect` — optional flag for the rare case where the wrapped predicate captures external state. Default is cache-eligible.
|
|
135
135
|
|
|
136
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.
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getPathValue } from "pathtrace";
|
|
2
2
|
import validator from "validator";
|
|
3
|
-
import { IssueCode
|
|
3
|
+
import { IssueCode } from "@ebec/core";
|
|
4
|
+
import { createValidupError, defineValidator } from "validup";
|
|
4
5
|
//#region src/module.ts
|
|
5
6
|
/**
|
|
6
7
|
* Build a string representation suitable for validator.js. validator.js
|
package/dist/index.mjs.map
CHANGED
|
@@ -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 {\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 * 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":";;;;;;;;;;AAyDA,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,SACs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,MAAM,UAAU,OAAO,CAAC;EAQxB,IAAI,CAAC,OAAO,MAAM,OAAO,GACrB,mBAAmB,IAAI,OAAO,SAAS,OAAO;EAElD,IAAI,CAAC,UAAU,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\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;C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AO,gBAAmB,EACtB,MAAM,QAAQ;EACV,MAAM,IAAI,kBAAkB,IAAI,KAAK;EAIrC,IAAI,CAAC,UAAU,QAAQ,GAAG,EAAE,QAAQ,QAAQ,OAAO,CAAC,GAChD,MAAM,mBACF,IAAI,OACJ,UAAU,SACV,QAAQ,WAAW,oCACvB;EAEJ,MAAM,UAAU,OAAO,CAAC;EAQxB,IAAI,CAAC,OAAO,MAAM,OAAO,GACrB,mBAAmB,IAAI,OAAO,SAAS,OAAO;EAElD,IAAI,CAAC,UAAU,QAAQ,GAAG,OAAO,GAC7B,MAAM,mBACF,IAAI,OACJ,UAAU,SACV,QAAQ,WAAW,oCACvB;EAEJ,OAAO,IAAI;CACf,EACJ,CAAC;AACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@validup/validator-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
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": {
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
],
|
|
45
45
|
"license": "Apache-2.0",
|
|
46
46
|
"dependencies": {
|
|
47
|
+
"@ebec/core": "^1.3.1",
|
|
47
48
|
"pathtrace": "^2.2.3"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
@@ -51,8 +52,8 @@
|
|
|
51
52
|
"validator": "^13.12.0"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
55
|
+
"validator": "^13.0.0",
|
|
56
|
+
"validup": "^2.0.1"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|