Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/realign/data-rules
https://github.com/realign/data-rules
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/realign/data-rules
- Owner: ReAlign
- Created: 2017-12-09T15:34:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-18T02:08:06.000Z (almost 7 years ago)
- Last Synced: 2023-12-28T08:09:17.640Z (11 months ago)
- Language: JavaScript
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# data-rules
> 添加 mock 数据的类型检测,让前后端联调变得更简单
前提:前端 `mock`, 只做了 `url` & `method` 校验。
这种情况下,前端几乎不太会去关心接口 `具体参数` 的格式,所以,前端的自测,一般在 `mock` 环境下通过,就算是通过了。但是跟后端联调各种格式问题。
所以,想在前端 `mock` 环境下,搞一套类似 `静态类型检查` 的东西,初始生成 `mock` 数据的时候(一般是提交数据接口),就定好 `参数格式规则` ,省去前后端联调时再去 `订正` 数据格式的时间,提高效率。
## Usage
```javascript
const _dr = require('data-rules');const obj = {
name: 'realign',
age: 120
};const rules = {
name: {
type: 'str',
regex: { min: 1, max: 10 }
},
age: {
type: 'int',
regex: { min: 1, max: 100 }
}
};let res = _dr(obj, rules);
/**
{
"success": false,
"message": {
"name": [],
"age": [
{
"key": "min",
"msg": "length error"
}
]
}
}
* /
```todo
* [ ] caalback