Skip to content
This repository has been archived by the owner on May 24, 2019. It is now read-only.

(unmaintained, don't use) Higher-order validation functions for ember-changeset

License

Notifications You must be signed in to change notification settings

nucleartide/ember-changeset-hofs

Repository files navigation



ember-changeset-hofs


ember-changeset-hofs provides higher-order validation functions for ember-changeset-validations.

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:

// app/validations/user.js
import and from 'ember-changeset-hofs/utils/and'
import or from 'ember-changeset-hofs/utils/or'

export const {
  email: and(
    validateFormat({ type: 'email' }),
    askServerIfExists(), // will not get called if validateFormat fails
  ),

  anotherEmail: or(
    isUndefinedOrNull(),
    askServerIfExists(), // will not get called if isUndefinedOrNull succeeds
  ),
}

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

About

(unmaintained, don't use) Higher-order validation functions for ember-changeset

Resources

License

Stars

Watchers

Forks

Packages

No packages published