This commit is contained in:
dswbx
2025-06-21 17:05:27 +02:00
parent 42edce904f
commit 6e78a4c238
37 changed files with 215 additions and 125 deletions
+6 -2
View File
@@ -38,6 +38,7 @@ export class InvalidSchemaError extends Error {
export type ParseOptions = {
withDefaults?: boolean;
withExtendedDefaults?: boolean;
coerce?: boolean;
clone?: boolean;
skipMark?: boolean; // @todo: do something with this
@@ -57,8 +58,11 @@ export function parse<S extends s.Schema, Options extends ParseOptions = ParseOp
): Options extends { coerce: true } ? s.StaticCoerced<S> : s.Static<S> {
const schema = (opts?.clone ? cloneSchema(_schema as any) : _schema) as s.Schema;
let value = opts?.coerce !== false ? schema.coerce(v) : v;
if (opts?.withDefaults) {
value = schema.template(value, { withOptional: true });
if (opts?.withDefaults !== false) {
value = schema.template(value, {
withOptional: true,
withExtendedOptional: opts?.withExtendedDefaults ?? false,
});
}
const result = schema.validate(value, {