Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .eslintrc.js

This file was deleted.

15 changes: 1 addition & 14 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
# These are supported funding model platforms

github: ant-design
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
open_collective: ant-design
32 changes: 24 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: npm
directory: '/'
schedule:
interval: weekly
day: monday
time: '21:00'
timezone: Asia/Shanghai
open-pull-requests-limit: 10
groups:
npm-dependencies:
patterns:
- '*'

- package-ecosystem: github-actions
directory: '/'
schedule:
interval: "weekly"
interval: weekly
day: monday
time: '21:00'
timezone: Asia/Shanghai
open-pull-requests-limit: 10
groups:
github-actions:
patterns:
- '*'
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/react-doctor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: React Doctor

on:
pull_request:
push:
branches: [master]

permissions:
contents: read
pull-requests: write
issues: write
statuses: write

jobs:
react-doctor:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3
52 changes: 52 additions & 0 deletions .github/workflows/surge-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Surge Preview

on:
pull_request:

permissions:
contents: read
pull-requests: write
checks: write

jobs:
preview:
runs-on: ubuntu-latest
concurrency:
group: surge-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Check Surge token
id: surge-token
env:
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
run: |
if [ -n "$SURGE_TOKEN" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup utoo
if: ${{ steps.surge-token.outputs.enabled == 'true' }}
uses: utooland/setup-utoo@v1

- name: Build preview
if: ${{ steps.surge-token.outputs.enabled == 'true' }}
run: |
ut install
npm run build
- uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec
if: ${{ steps.surge-token.outputs.enabled == 'true' }}
env:
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
with:
surge_token: ${{ env.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dist: .docs-dist
failOnError: false
setCommitStatus: false
- name: Skip Surge preview
if: ${{ steps.surge-token.outputs.enabled != 'true' }}
run: echo "SURGE_TOKEN is not configured; skip Surge preview."
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: ✅ test

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
test:
uses: react-component/rc-test/.github/workflows/test-utoo.yml@main
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
133 changes: 63 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,80 @@
# @rc-component/async-validator

[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[![build status][github-actions-image]][github-actions-url]
[![Codecov][codecov-image]][codecov-url]
[![dumi][dumi-image]][dumi-url]

[npm-image]: http://img.shields.io/npm/v/@rc-component/async-validator.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@rc-component/async-validator
[travis-image]: https://img.shields.io/travis/react-component/async-validator/master?style=flat-square
[travis-url]: https://travis-ci.com/react-component/async-validator
[github-actions-image]: https://github.com/react-component/async-validator/actions/workflows/ci.yml/badge.svg
[github-actions-url]: https://github.com/react-component/async-validator/actions/workflows/ci.yml
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/async-validator/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/async-validator
[david-url]: https://david-dm.org/react-component/async-validator
[david-image]: https://david-dm.org/react-component/async-validator/status.svg?style=flat-square
[david-dev-url]: https://david-dm.org/react-component/async-validator?type=dev
[david-dev-image]: https://david-dm.org/react-component/async-validator/dev-status.svg?style=flat-square
[download-image]: https://img.shields.io/npm/dm/@rc-component/async-validator.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/async-validator
[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/async-validator
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/async-validator
[dumi-url]: https://github.com/umijs/dumi
[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square

Validate form asynchronous. A variation of https://github.com/freeformsystems/async-validate
<div align="center">
<h1>@rc-component/async-validator</h1>
<p><sub><a href="https://ant.design"><img alt="Ant Design" height="14" src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" style="vertical-align: -0.125em;" /></a> Part of the Ant Design ecosystem.</sub></p>
<p>✅ Async validation engine for schema-based form rules.</p>

<p>
<a href="https://npmjs.org/package/@rc-component/async-validator"><img alt="NPM version" src="https://img.shields.io/npm/v/@rc-component/async-validator.svg?style=flat-square"></a>
<a href="https://npmjs.org/package/@rc-component/async-validator"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@rc-component/async-validator.svg?style=flat-square"></a>
<a href="https://github.com/react-component/async-validator/actions/workflows/test.yml"><img alt="build status" src="https://github.com/react-component/async-validator/actions/workflows/test.yml/badge.svg"></a>
<a href="https://app.codecov.io/gh/react-component/async-validator"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/react-component/async-validator/master.svg?style=flat-square"></a>
<a href="https://bundlephobia.com/package/@rc-component/async-validator"><img alt="bundle size" src="https://img.shields.io/bundlephobia/minzip/@rc-component/async-validator?style=flat-square"></a>
<a href="https://github.com/umijs/dumi"><img alt="dumi" src="https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square"></a>
</p>
</div>

<p align="center">English | <a href="./README.zh-CN.md">简体中文</a></p>

## Highlights

| Area | Support |
| ------- | ---------------------------------------------------- |
| Purpose | Async validation engine for schema-based form rules. |
| Package | `@rc-component/async-validator` |
| Release | `@rc-component/np` / `rc-np` |

## Install

```bash
npm i @rc-component/async-validator
npm install @rc-component/async-validator
```

## Usage

Basic usage involves defining a descriptor, assigning it to a schema and passing the object to be validated and a callback function to the `validate` method of the schema:

```js
```tsx | pure
import Schema from '@rc-component/async-validator';
const descriptor = {
name: {
type: 'string',
required: true,
validator: (rule, value) => value === 'muji',
},
age: {
type: 'number',
asyncValidator: (rule, value) => {
return new Promise((resolve, reject) => {
if (value < 18) {
reject('too young'); // reject with error message
} else {
resolve();
}
});
},
},
};
const validator = new Schema(descriptor);
validator.validate({ name: 'muji' }, (errors, fields) => {
if (errors) {
// validation failed, errors is an array of all errors
// fields is an object keyed by field name with an array of
// errors per field
return handleErrors(errors, fields);
}
// validation passed

const validator = new Schema({
name: { type: 'string', required: true },
});

// PROMISE USAGE
validator
.validate({ name: 'muji', age: 16 })
.then(() => {
// validation passed or without error message
})
.catch(({ errors, fields }) => {
return handleErrors(errors, fields);
});
validator.validate({ name: 'Ant Design' }).then(() => {
// validation passed
});
```

## API

| API | Description |
| --------------------------------------- | ------------------------------------------ |
| `new Schema(descriptor)` | Create a validator from a rule descriptor. |
| `validate(source, options?, callback?)` | Validate source data and return a Promise. |
| `messages` | Customize validation messages. |

## Development

```bash
npm install
npm start
npm test
npm run coverage
npm run lint
npm run tsc
npm run compile
```

The dumi site runs at `http://localhost:8000`.

## Release

```bash
npm run prepublishOnly
```

The release flow is handled by `@rc-component/np` through the `rc-np` command when the package uses the shared release flow.

## Detailed API

### Validate

```js
Expand Down Expand Up @@ -478,4 +471,4 @@ Open coverage/ dir

## License

Everything is [MIT](https://en.wikipedia.org/wiki/MIT_License).
@rc-component/async-validator is released under the [MIT](./LICENSE.md) license.
78 changes: 78 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<div align="center">
<h1>@rc-component/async-validator</h1>
<p><sub><a href="https://ant.design"><img alt="Ant Design" height="14" src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" style="vertical-align: -0.125em;" /></a> Ant Design 生态的一部分。</sub></p>
<p>✅ 基于规则描述的异步表单校验引擎。</p>

<p>
<a href="https://npmjs.org/package/@rc-component/async-validator"><img alt="NPM version" src="https://img.shields.io/npm/v/@rc-component/async-validator.svg?style=flat-square"></a>
<a href="https://npmjs.org/package/@rc-component/async-validator"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@rc-component/async-validator.svg?style=flat-square"></a>
<a href="https://github.com/react-component/async-validator/actions/workflows/test.yml"><img alt="build status" src="https://github.com/react-component/async-validator/actions/workflows/test.yml/badge.svg"></a>
<a href="https://app.codecov.io/gh/react-component/async-validator"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/react-component/async-validator/master.svg?style=flat-square"></a>
<a href="https://bundlephobia.com/package/@rc-component/async-validator"><img alt="bundle size" src="https://img.shields.io/bundlephobia/minzip/@rc-component/async-validator?style=flat-square"></a>
<a href="https://github.com/umijs/dumi"><img alt="dumi" src="https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square"></a>
</p>
</div>

<p align="center"><a href="./README.md">English</a> | 简体中文</p>

## 亮点

| 方向 | 支持 |
| ---- | -------------------------------- |
| 定位 | 基于规则描述的异步表单校验引擎。 |
| 包名 | `@rc-component/async-validator` |
| 发布 | `@rc-component/np` / `rc-np` |

## 安装

```bash
npm install @rc-component/async-validator
```

## 用法

```tsx | pure
import Schema from '@rc-component/async-validator';

const validator = new Schema({
name: { type: 'string', required: true },
});

validator.validate({ name: 'Ant Design' }).then(() => {
// validation passed
});
```

## API

| 名称 | 说明 |
| --------------------------------------- | -------------------------- |
| `new Schema(descriptor)` | 根据规则描述创建校验器。 |
| `validate(source, options?, callback?)` | 校验源数据并返回 Promise。 |
| `messages` | 自定义校验提示。 |

## 本地开发

```bash
npm install
npm start
npm test
npm run coverage
npm run lint
npm run tsc
npm run compile
```

本地 dumi 站点默认运行在 `http://localhost:8000`.

## 发布

```bash
npm run prepublishOnly
```

发布流程通过 `@rc-component/np` 提供的 `rc-np` 命令处理。

## 许可证

@rc-component/async-validator 基于 [MIT](./LICENSE.md) 协议发布。
Loading
Loading