joi
joi copied to clipboard
Comparing arrays of objects by key or predicate
Support plan
- which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): yes
Context
- node version: 13.6.0
- module version: 16.1.5
- environment (e.g. node, browser, native): browser
- used with (e.g. hapi application, another framework, standalone, ...): standalone
- any other relevant information: Webpack and Babel
How can we help?
I would like to validate the following object such that the names in xs and the names inys are the same list when ordered.
const inputData = {
xs: [
{ id: 'x1', name: 'A' },
{ id: 'x2', name: 'B' },
{ id: 'x3', name: 'C' },
{ id: 'x4', name: 'D' }, // Invalid: No match in ys
],
ys: [
{ id: 'y1', name: 'A' },
{ id: 'y2', name: 'B' },
{ id: 'y3', name: 'C' },
{ id: 'x4', name: 'E' }, // Invalid: No match in xs
],
Is there a built-in to validate this?
Nope.