Const
The schema is registered in the BupkisRegistry
with the name Primitive
and indicates that it accepts primitive values as valid input.
PrimitiveSchema.parse('hello'); // ✓ Valid (string)
PrimitiveSchema.parse(42); // ✓ Valid (number)
PrimitiveSchema.parse(true); // ✓ Valid (boolean)
PrimitiveSchema.parse(BigInt(123)); // ✓ Valid (bigint)
PrimitiveSchema.parse(Symbol('test')); // ✓ Valid (symbol)
PrimitiveSchema.parse(null); // ✓ Valid (null)
PrimitiveSchema.parse(undefined); // ✓ Valid (undefined)
PrimitiveSchema.parse({}); // ✗ Throws validation error (object)
PrimitiveSchema.parse([]); // ✗ Throws validation error (array)
PrimitiveSchema.parse(() => {}); // ✗ Throws validation error (function)
A Zod schema that validates primitive JavaScript values.
This schema validates any of the seven primitive data types in JavaScript: string, number, boolean, bigint, symbol, null, and undefined. Primitive values are immutable and are passed by value rather than by reference, distinguishing them from objects and functions which are non-primitive reference types.