# ember-yup

> Dead, simple object schema validations for Ember

Latest version **1.0.15** (published 2019-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-yup
pnpm add ember-yup
yarn add ember-yup
bun add ember-yup
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.15 |
| Published | 2019-07-27 |
| First published | 2019-04-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 8.* \|\| >= 10.* |
| Dependencies | 4 |
| Unpacked size | 8.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Edward Gaba |
| Maintainers | egaba |
| Keywords | ember-addon, validate, validation, form, forms, schema |

## Links

- npm: https://www.npmjs.com/package/ember-yup
- Repository: https://github.com/egaba/ember-yup
- Homepage: https://egaba.github.io/ember-yup/
- Issues: https://github.com/egaba/ember-yup/issues
- npm.io page: https://npm.io/package/ember-yup

## Dependencies (4)

- [yup](https://npm.io/package/yup.md) 0.27.x
- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^7.7.3
- [ember-cli-htmlbars](https://npm.io/package/ember-cli-htmlbars.md) ^3.0.1
- [ember-cli-cjs-transform](https://npm.io/package/ember-cli-cjs-transform.md) ^1.3.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.15 (latest) — 2019-07-27
- 1.0.14 — 2019-07-27
- 1.0.13 — 2019-07-27
- 1.0.11 — 2019-06-30
- 1.0.9 — 2019-06-30
- 1.0.8 — 2019-06-13
- 1.0.7 — 2019-06-09
- 1.0.6 — 2019-06-05
- 1.0.5 — 2019-06-05
- 1.0.4 — 2019-06-04
- 1.0.3 — 2019-06-04
- 1.0.2 — 2019-06-04
- 1.0.1 — 2019-06-02
- 1.0.0 — 2019-06-01
- 0.4.3 — 2019-05-01
- … 22 more at https://npm.io/package/ember-yup/versions

## README

# ember-yup

Yup is a JavaScript object schema validator and object parser. This is an Ember port of the [Yup Schema library](https://github.com/jquense/yup).

Docs: https://egaba.github.io/ember-yup/

Yup library playground: https://runkit.com/jquense/yup

## Installation

```sh
$ ember install ember-yup
```

## Usage

Here's an example of adding validation to a user model.

Demo: https://egaba.github.io/ember-yup/#/getting-started/ember-data

```js
import DS from 'ember-data';
const { Model } = DS;
import Validate from 'ember-yup/mixins/validate-model';

export default Model.extend(Validate, {
  username: DS.attr({
    validate: {
      required: true,
    },
  }),
  age: DS.attr('number', {
    validate: {
      required: true,
      min: 18,
    },
  }),
  email: DS.attr('string', {
    validate: {
      type: 'email',
      required: true,
    },
  }),
  countryCode: DS.attr({
    validate: {
      required: true,
      oneOf: ['US', 'ES', 'JP', 'SK']
    },
  }),
  zipCode: DS.attr('string', {
    validate: {
      required: true,
      when: {
        countryCode: {
          is: 'US',
          then: {
            matches: /\d{5}(-?\d{4})?/,
          }
        }
      }
    },
  }),
  gender: DS.attr(),
});
```

```js
actions: {
  validate() {
    this.get('model').validate().then(function(data) {
      console.log('validate success', data);
    }).catch((errors) => {
      console.log('validate errors', errors.get('messages'));
    });
  },
  save() {
    this.get('model').save({ validate: true }).then(function(data) {
      console.log('save success', data);
    }).catch(function(errors) {
      console.log('save errors', errors.get('messages'));
    });
  }
}
```

## Contributing

See the [Contributing](CONTRIBUTING.md) guide for details.

### Installation

* `git clone <repository-url>`
* `cd ember-yup`
* `npm install`

### Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js --fix`

### Running tests

* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions

### Running the dummy application

* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).

## License

This project is licensed under the [MIT License](LICENSE.md).

---
_Source: https://npm.io/package/ember-yup · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
