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.deepEqualDerive a "deep equal" function from a valibot schema.
A "deep equal" function" (see also,
Equal) is similar to lodash'sisEqualfunction, 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.deepEqualassumes that both values have already been validated. Passing unvalidated values to the function might result in undefined behavior.See also:
vx.deepEqual.writeable