ember-changeset-hofs
Higher-order validation functions for
ember-changeset-validations.
For background info, please see the thread here.
This addon provides and
and or
higher-order functions, that allow you to
compose together validations. It is useful if you want the short-circuit
behavior of &&
and ||
. For example:
import and from 'ember-changeset-hofs/utils/and'
import or from 'ember-changeset-hofs/utils/or'
export const {
email: and(
validateFormat({ type: 'email' }),
askServerIfExists(),
),
anotherEmail: or(
isUndefinedOrNull(),
askServerIfExists(),
),
}
Note that the and
and or
utils work with both synchronous and asynchronous
validators. You can nest and
and or
expressions arbitrarily, and you can
mix sync and async validators however you want:
const validationFn = and(
and(
and(...someValidators),
or(...someMoreValidators),
or(
or(...someValidators),
and(...someMoreValidators),
)
),
or(...evenMoreValidators)
)
Install
$ ember install ember-changeset-hofs
License
MIT