# 快速开始

## 安装

npm

```
$ npm install acr
```

yarn

```
$ yarn add acr
```

## 配置

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

```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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seek.gitbook.io/acr/quick-start.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
