import { JsonSchema } from '@traversable/json-schema'
const deepEqual = JsonSchema.deepEqual({
type: 'object',
required: ['street1', 'city'],
properties: {
street1: { type: 'string' },
street2: { type: 'string' },
city: { type: 'string' },
}
})
deepEqual(
{ street1: '221 Baker St', street2: '#B', city: 'London' },
{ street1: '221 Baker St', street2: '#B', city: 'London' }
) // => true
deepEqual(
{ street1: '221 Baker St', street2: '#B', city: 'London' },
{ street1: '4 Privet Dr', city: 'Little Whinging' }
) // => false
JsonSchema.deepEqual
Derive an "deep equal" function from a Json Schema spec.
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 function generated by
JsonSchema.deepEqual
assumes that both values have already been validated. Passing unvalidated values to the function might result in undefined behavior.See also:
JsonSchema.deepEqual.writeable