@lucid-softworks/schema-object
v0.1.0
Published
Typed object schemas with optional fields and explicit unknown-key policies.
Downloads
162
Maintainers
Readme
@lucid-softworks/schema-object
Typed object schemas with required and optional fields. Unknown keys can be stripped (the default), passed through, or rejected.
import {
objectSchema,
optionalSchema,
partialShape,
} from "@lucid-softworks/schema-object";
import { numberSchema, stringSchema } from "@lucid-softworks/schema-primitives";
const userShape = {
age: optionalSchema(numberSchema({ minimum: 0 })),
name: stringSchema(),
};
const user = objectSchema(userShape, { unknownKeys: "strict" });
const userUpdate = objectSchema(partialShape(userShape));pickShape and omitShape create type-preserving derived shapes. Dangerous
property names such as __proto__ are copied as ordinary own properties.
