Optionaloptions: deepEqual.Optionsimport { JsonSchema } from '@traversable/json-schema'
const deepEqual = JsonSchema.deepEqual.writeable({
type: 'object',
required: ['street1', 'city'],
properties: {
street1: { type: 'string' },
street2: { type: 'string' },
city: { type: 'string' },
}
}, { typeName: 'Address' })
console.log(deepEqual)
// =>
// type Address = { street1: string; street2?: string; city: string; }
// function deepEqual(x: Address, y: Address) {
// if (x === y) return true;
// if (x.street1 !== y.street1) return false;
// if (x.street2 !== y.street2) return false;
// if (x.city !== y.city) return false;
// return true;
// }
JsonSchema.deepEqual.writeableDerive a "writeable" (stringified) "deep equal" function from a Json Schema spec.
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 function generated by
JsonSchema.deepEqualassumes that both values have already been validated. Passing unvalidated values to the function might result in undefined behavior.JsonSchema.deepEqual.writeableaccepts an optional configuration object as its second argument; documentation for those options are available via hover on autocompletion.See also:
JsonSchema.deepEqual