config
Changes the local configuration of a schema.
const Schema = v.config<TSchema>(schema, config);
Generics
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchemaconfigConfig<InferIssue<TSchema>>
Explanation
This method overwrites the selected configuration properties by merging the previous configuration of the schema with the provided config.
Returns
SchemaTSchema
Examples
The following examples show how config can be used.
Same error message
Schema that uses the same error message for the entire pipeline.
const Schema = v.object({
email: v.config(
v.pipe(v.string(), v.trim(), v.email(), v.endsWith('@example.com')),
{ message: 'The email does not conform to the required format.' }
),
// ...
});
Abort pipeline early
Schema that aborts only a specific pipeline early.
const Schema = v.object({
url: v.config(
v.pipe(v.string(), v.trim(), v.url(), v.endsWith('@example.com')),
{ abortPipeEarly: true }
),
// ...
});
Related
The following APIs can be combined with config.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Methods
assert, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, keyof, message, omit, parse, parser, partial, pick, pipe, required, safeParse, safeParser, unwrap
Actions
args, base64, bic, brand, bytes, check, checkItems, codePoints, creditCard, cuid2, decimal, description, digits, domain, email, emoji, empty, endsWith, entries, everyItem, excludes, filterItems, findItem, finite, flavor, graphemes, gtValue, guard, hash, hexadecimal, hexColor, imei, includes, integer, ip, ipv4, ipv6, isbn, isrc, isoDate, isoDateTime, isoDateTimeSecond, isoTime, isoTimeSecond, isoTimestamp, isoWeek, ksuid, length, ltValue, mac, mac48, mac64, mapItems, maxBytes, maxCodePoints, maxEntries, maxGraphemes, maxLength, maxSize, maxValue, maxWords, metadata, mimeType, minBytes, minCodePoints, minEntries, minGraphemes, minLength, minSize, minValue, minWords, multipleOf, nanoid, nonEmpty, notBytes, notCodePoints, notEntries, notGraphemes, notLength, notSize, notValue, notValues, notWords, octal, parseJson, partialCheck, rawCheck, rawTransform, readonly, reduceItems, regex, returns, rfcEmail, safeInteger, size, slug, someItem, sortItems, startsWith, stringifyJson, title, toCamelCase, toKebabCase, toLowerCase, toMaxValue, toMinValue, toPascalCase, toSnakeCase, toUpperCase, transform, trim, trimEnd, trimStart, ulid, url, uuid, value, values, words
Utils
Async
arrayAsync, customAsync, exactOptionalAsync, fallbackAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, partialAsync, pipeAsync, recordAsync, requiredAsync, setAsync, strictObjectAsync, strictTupleAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/config/