Published
Edited
Oct 31, 2019
Insert cell
Insert cell
schema = yup.object({
type: yup.string().required(),
target: yup.object()
.when('type', {
is: 'click',
then: yup.object({
operator: yup.string().matches(/^=$/, 'Operator must be =').required(),
field: yup.string().required(),
value: yup.string().required()
}).required()
})
.when('type', {
is: 'pageview',
then: yup.object({
operator: yup.string().matches(/^wildcard_match/, 'Operator must be =').required(),
field: yup.string().matches(/^path/, 'Field must be path').required(),
value: yup.string().required()
}).required()
})
})
Insert cell
schema.validate({
type: 'click',
target: {
operator: '=',
field: 'foo',
value: 'bar',
}
})
Insert cell
schema.validate({
type: 'pageview',
target: {
operator: 'wildcard_matches',
field: 'path',
value: 'bar',
}
})
Insert cell
schema.validate({
type: 'pageview',
target: {
operator: '=',
field: 'foo',
value: 'bar',
}
})
Insert cell
yup = require('https://bundle.run/yup@0.27')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more