{"id":18722041,"url":"https://github.com/realign/data-rules","last_synced_at":"2025-06-20T15:07:33.594Z","repository":{"id":57358577,"uuid":"113680078","full_name":"ReAlign/data-rules","owner":"ReAlign","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-18T02:08:06.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-19T15:56:15.811Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ReAlign.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-09T15:34:09.000Z","updated_at":"2017-12-09T16:00:22.000Z","dependencies_parsed_at":"2022-09-26T16:40:48.333Z","dependency_job_id":null,"html_url":"https://github.com/ReAlign/data-rules","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ReAlign/data-rules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReAlign%2Fdata-rules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReAlign%2Fdata-rules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReAlign%2Fdata-rules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReAlign%2Fdata-rules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ReAlign","download_url":"https://codeload.github.com/ReAlign/data-rules/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReAlign%2Fdata-rules/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260967380,"owners_count":23090101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T13:39:36.804Z","updated_at":"2025-06-20T15:07:28.574Z","avatar_url":"https://github.com/ReAlign.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# data-rules\n\n\u003e 添加 mock 数据的类型检测，让前后端联调变得更简单\n\n前提：前端 `mock`， 只做了 `url` \u0026 `method` 校验。\n\n这种情况下，前端几乎不太会去关心接口 `具体参数` 的格式，所以，前端的自测，一般在 `mock` 环境下通过，就算是通过了。但是跟后端联调各种格式问题。\n\n所以，想在前端 `mock` 环境下，搞一套类似 `静态类型检查` 的东西，初始生成 `mock` 数据的时候（一般是提交数据接口），就定好 `参数格式规则` ，省去前后端联调时再去 `订正` 数据格式的时间，提高效率。\n\n## Usage\n\n```javascript\nconst _dr = require('data-rules');\n\nconst obj = {\n    name: 'realign',\n    age: 120\n};\n\nconst rules = {\n    name: {\n        type: 'str',\n        regex: { min: 1, max: 10 }\n    },\n    age: {\n        type: 'int',\n        regex: { min: 1, max: 100 }\n    }\n};\n\nlet res = _dr(obj, rules);\n\n/**\n{\n \"success\": false,\n \"message\": {\n  \"name\": [],\n  \"age\": [\n   {\n    \"key\": \"min\",\n    \"msg\": \"length error\"\n   }\n  ]\n }\n}\n * /\n```\n\ntodo\n\n* [ ] caalback\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealign%2Fdata-rules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealign%2Fdata-rules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealign%2Fdata-rules/lists"}