import * as v from 'valibot'
import { vx } from '@traversable/valibot'
const deepEqual = vx.deepEqual(
v.object({
street1: v.string(),
street2: v.optional(v.string()),
city: v.string()
})
)
deepEqual(
{ street1: '221B Baker St', city: 'London' },
{ street1: '221B Baker St', city: 'London' }
) // => true
deepEqual(
{ street1: '221B Baker St', city: 'London' },
{ street1: '4 Privet Dr', city: 'Little Whinging' }
) // => false
vx.deepEqual
Derive a "deep equal" function from a valibot schema.
A "deep equal" function" (see also,
Equal
) is similar to lodash'sisEqual
function, except more performant, because when the shape of the values being compared is known ahead of time, we can optimize ahead of time, and only check what's necessary.Note that the deep equal generated by
vx.deepEqual
assumes that both values have already been validated. Passing unvalidated values to the function might result in undefined behavior.See also:
vx.deepEqual.writeable