ConstTruthySchema.parse(true); // ✓ Valid
TruthySchema.parse(1); // ✓ Valid
TruthySchema.parse('hello'); // ✓ Valid
TruthySchema.parse([]); // ✓ Valid (arrays are truthy)
TruthySchema.parse({}); // ✓ Valid (objects are truthy)
TruthySchema.parse(false); // ✗ Throws validation error
TruthySchema.parse(0); // ✗ Throws validation error
TruthySchema.parse(''); // ✗ Throws validation error
TruthySchema.parse(null); // ✗ Throws validation error
import { createAssertion, use } from 'bupkis';
import { TruthySchema } from 'bupkis/schema';
const somethingAssertion = createAssertion(
  ['to be something'],
  TruthySchema,
);
const { expect } = use([somethingAssertion]);
expect('pants', 'to be something');
A Zod schema that validates truthy JavaScript values.
This schema accepts any input value but only validates successfully if the value is truthy according to JavaScript's truthiness rules. A value is truthy if it converts to
truewhen evaluated in a boolean context - essentially any value that is not one of the eight falsy values.