{"id":21461779,"url":"https://github.com/appletjs/shiver","last_synced_at":"2025-06-22T12:07:38.188Z","repository":{"id":77981644,"uuid":"147670384","full_name":"appletjs/shiver","owner":"appletjs","description":null,"archived":false,"fork":false,"pushed_at":"2018-09-06T12:33:16.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T12:07:32.287Z","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/appletjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-06T12:30:05.000Z","updated_at":"2018-09-06T12:33:17.000Z","dependencies_parsed_at":"2023-06-26T18:15:53.609Z","dependency_job_id":null,"html_url":"https://github.com/appletjs/shiver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/appletjs/shiver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fshiver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fshiver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fshiver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fshiver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appletjs","download_url":"https://codeload.github.com/appletjs/shiver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appletjs%2Fshiver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261289419,"owners_count":23136070,"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-23T07:10:54.489Z","updated_at":"2025-06-22T12:07:33.175Z","avatar_url":"https://github.com/appletjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## create(path，validators)\n\n\n\n\u003e **create('数据路径').校验器(参考数据, 异常信息)**\n\n\n\n该方法生成一个**规则函数**用于校验数据；该规则函数包含了一系列**校验器**，\n所有的校验器返回规则函数本身，便于链式调用。\n\n\n\n参数说明：\n\n- **path** `string` 数据路径\n- **validators** `Object` 规则校验器\n\n\n\n### 数据路径\n\n数据路径指的是用于在被校验数据内寻值的键名，比如：\n\n- 要校验当前请求方法，数据路径是 'method'；\n- 要检验通过 GET 方法提交到服务器内的数据，数据路径是 'query.key'；\n\n\n\n### 使用校验器\n\n规则一旦创建，如果没有使用校验器，在验证数据的时候会忽略之。\n\n```js\nconst rule = create('method') // 创建规则\n  .inside(['POST', 'PUT', 'PATCH'], 'error message') // 使用校验器\n  .existence('error message')// 使用校验器\n  // 还可以使用其它的校验器\n\n// 使用规则\ntry {\n  return rule({method: 'DELETE'})\n} catch (err) {\n  console.log(err.name) // =\u003e maybe 'ShiverError'\n  console.log(err.path) // =\u003e 'method'\n  console.log(err.value) // =\u003e 'DELETE'\n  return false\n}\n```\n\n\n规则属性\n\n* **$path** `string`\n* $value `mixed`\n\n规则方法\n\n* **$use(name: string, validator: function): rule** \n* **$batch(validators: object): rule**\n\n内置的校验器\n\n- **accordance(data: any, message?: string)** 是否与给出的值相等\n- **difference(data: any, message?: string)** 是否与给出的值不一致\n- **existence(message?: string)** 是否存在值\n- **inside(data: array|string, message?: string)** 是不是给出的数组或字符串的一部分\n- **empty(message?: string)** 是不是为空数据\n- **falsy(message?: string)** 是不是假值\n- **truthy(message?: string)** 是不是真值\n- **match(reg: RegExp, message?: string)** 能够通过给出的正则表达式校验\n- **startsWith(str: string, message?: string)** 是否以给出的字符串开头\n- **endsWith(str: string, message?: string)** 是否以给出的字符串结尾\n- **ascii(message?: string)** 是不是全 ASCII 字符串\n- **chinese(message?: string)** 是不是全中文字符\n- **md5(message?: string)** 是不是 MD5 字符串\n- **lowercase(message?: string)** 是不是全小写\n- **uppercase(message?: string)** 是不是全大写\n- **ip(version?: 4|6|'4'|'6', message?: string)** 是不是IP地址\n- **phone(message?: string)** 是不是手机号码\n- **mail(message?: string)** 是不是邮箱\n- **dataURI(message?: string)** 是不是 data-uri 数据\n- **base64(message?: string)** 是不是使用 base64 加密的字符串\n- **numeric(message?: string)** 是不是数字\n- **int(message?: string)** 是不是整数\n- **safeInt(message?: string)** 是不是安全整数\n- **yesterday(message?: string)** 是不是昨天\n- **today(message?: string)** 是不是今天\n- **tomorrow(message?: string)** 是不是明天\n- **after(date?: string|number|Date, message?: string)** 是不是在指定时间之后\n- **before(date?: string|number|Date, message?: string)** 是不是在指定时间之前\n\n\n## custom(name[, validator])\n\n- name `string` 检验器名称\n- validator 可选\n  - 值为 null 时，删除自定义的\n  - 未指定时，返回检验器\n  - 值为函数时，设置校验器\n\n\n## execute(rules, object, detail)\n\n执行规则，根据参数 detail，做出不同的返回值。\n\n- **rules** `array` 规则列表\n- **object** `object` 被校验的数据对象\n- **detail** `boolean` 是否返回校验详情\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappletjs%2Fshiver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappletjs%2Fshiver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappletjs%2Fshiver/lists"}