# @alifd/validate

> Validation to be used with @alifd/field

Latest version **1.4.0** (published 2021-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alifd/validate
pnpm add @alifd/validate
yarn add @alifd/validate
bun add @alifd/validate
```

## 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.4.0 |
| Published | 2021-12-22 |
| First published | 2019-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 95.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | mark-ck, lakerswgq, no-repeat, wwsun, aboutblank, bindoon, tao1991123, vicerwang, myronliu347, jdkahn, fusion-bot, sobear, lianmin, clarkxia, quanyin, jerryyxu, yellow2dong, alvinhui, andevery, luhengchang228, yuysmile, fd.xy, rax-publisher |
| Keywords | ice, react, component |

## Links

- npm: https://www.npmjs.com/package/@alifd/validate
- Repository: https://github.com/alibaba-fusion/validate
- Homepage: https://unpkg.com/@alifd/validate@1.4.0/build/index.html
- Issues: https://github.com/alibaba-fusion/validate/issues
- npm.io page: https://npm.io/package/@alifd/validate

## 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.4.0 (latest) — 2021-12-22
- 2.0.3 (next) — 2024-02-21
- 2.0.2 — 2024-02-21
- 2.0.1 — 2024-02-19
- 2.0.0 — 2024-01-31
- 1.3.4 — 2021-12-22
- 1.3.3 — 2021-12-15
- 1.3.2 — 2021-12-02
- 1.3.1 — 2021-07-19
- 1.3.0 — 2021-07-16
- 1.2.3 — 2021-04-23
- 1.2.2 — 2021-04-19
- 1.2.1 — 2021-02-18
- 1.2.0 — 2020-02-21
- 1.1.5 — 2019-12-03
- … 6 more at https://npm.io/package/@alifd/validate/versions

## README

# Validate

<p align="center">
  <a href="https://www.npmjs.org/package/@alifd/validate"><img src="https://img.shields.io/npm/v/@alifd/validate.svg"></a>
  <a href="https://www.npmjs.org/package/@alifd/validate"><img src="https://img.shields.io/npm/dm/@alifd/validate.svg"></a>
  <a href="https://codecov.io/gh/alibaba-fusion/validate"><img src="https://codecov.io/gh/alibaba-fusion/validate/branch/master/graph/badge.svg"></a>
  <a href="https://travis-ci.com/alibaba-fusion/validate"><img src="https://travis-ci.com/alibaba-fusion/validate.svg?branch=master"></a>
  <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a>
  <a href="https://github.com/alibaba-fusion/validate/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg"></a>
  <a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg"></a>
</p>


Validation to be used with @alifd/field
Install with `npm install @alifd/validate`

### Basic Usage

#### Callback
```
const rules = {
  myInput: function (rule, value, cb, options) {
    if (value <= 100) {
      cb('Value must be more than 100');
    } else {
      cb();
    }
  }
}
const validator = new Validator(rules);
validator.validate({ myInput: 90 }, (err) => { console.log(err)});
```

#### Promise
```
const rules = {
  myInput: function (rule, value, cb, options) {
    if (value <= 100) {
      cb('Value must be more than 100');
    } else {
      cb();
    }
  }
}
const validator = new Validator(rules);
validator.validatePromise({ myInput: 90 })
  .then((err) => { console.log(err)})
```

## API
### Initialization
```
let validator = new Validator(rules [, options]);
```

|Parameter | Description | Type | Optional |Default |
|-----------|------------------------------------------|------------|-------|--------|
| rules | Map of rule names to validation functions | { [ruleName] : Array of validation functions } | yes | undefined
| options | validation options | Object | yes | {} |

`options` configuration item

| Parameters | Description | Type |Default |
|-----------|------------------------------------------|-----------|--------|
| first | should only return the first error found amongst rules | Boolean | undefined
| messages | map to override default messages | Object | (see ./src/messages)



## Development

### Testing
`npm run test` - triggers a one-time full run of all unit tests
`npm run test-watch` - triggers a run of all unit tests, but watches for any changes to code or tests and reruns all tests.


### Making commits
Commits must be in the following format `TYPE(SCOPE): MESSAGE`, where `SCOPE` is optional.
e.g. `fix: validatePromise return value`
Review the `commitlint.config.js` file to see allowed types.

### Release
There are 2 main branches: Master and Develop. Master holds the latest code that is contained in the npm package. Develop is the development branch used for queueing package changes and any final validation. All development should occur on another branch and then be merged into Develop. 

Travis CI will run tests on each pull request and push. If the push is to master then an additional release step runs. The release step uses `semantic-release` to determine the correct version, tag the master branch, and release the new package to npm. 

NOTE: the package.json file needs to be updated manually after the release.

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