> For the complete documentation index, see [llms.txt](https://seek.gitbook.io/acr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://seek.gitbook.io/acr/quick-start.md).

# 快速开始

## 安装

npm

```
$ npm install acr
```

yarn

```
$ yarn add acr
```

## 配置

在正式使用前，我们需要对 acr 进行配置。 acr 在配置方面没有强制要求，你也可以使用默认配置。[了解详细配置](/acr/config.md)

```javascript
const Acr = require('acr');
const acr = new Acr({ lang: 'zh-cn' });
```

## 使用

在使用前，你可以通过 acr 实例来定义验证规则，但这并不是必须的，我们目前内置的一部分规则，应该可以满足日常的一些数据验证工作，但我们知道这不可能满足所有产品的变态需求。因此，鼓励大家自己创建符合自己业务的验证规则，因为它真的非常简单。

```javascript
acr.type('string')
    .define('hello', async (value) => {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve(value === 'hi');
            }, 200);
        });
    });


```

使用定义的规则进行验证：

```javascript
// 验证单个数据
await acr.string().hello().validate('hi'); // 验证通过

// 批量验证
await acr.validate({
    say: 'hi',
}, {
    say: acr.string().hello()
});
```

{% hint style="info" %}
在使用验证时，即使你的验证规则都是同步的，也一定不要忘记加 await，因为 acr 是纯异步的。
{% endhint %}
