{"id":17242798,"url":"https://github.com/imcuttle/walli","last_synced_at":"2025-04-14T03:25:57.048Z","repository":{"id":31796983,"uuid":"128787673","full_name":"imcuttle/walli","owner":"imcuttle","description":"🚨A manageable validation library.","archived":false,"fork":false,"pushed_at":"2023-03-02T05:58:49.000Z","size":584,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T02:34:06.751Z","etag":null,"topics":["prop-types","typescript","validation","validator"],"latest_commit_sha":null,"homepage":"https://imcuttle.github.io/walli/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imcuttle.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"License","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-04-09T14:48:45.000Z","updated_at":"2023-03-01T09:18:27.000Z","dependencies_parsed_at":"2024-06-20T00:08:27.381Z","dependency_job_id":"ce971e6c-2b36-4001-9965-7142db18c3a6","html_url":"https://github.com/imcuttle/walli","commit_stats":{"total_commits":80,"total_committers":2,"mean_commits":40.0,"dds":0.07499999999999996,"last_synced_commit":"715d42103e8afb05e5aea5a859ce3a844b9d6430"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fwalli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fwalli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fwalli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcuttle%2Fwalli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcuttle","download_url":"https://codeload.github.com/imcuttle/walli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248814746,"owners_count":21165819,"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":["prop-types","typescript","validation","validator"],"created_at":"2024-10-15T06:14:05.720Z","updated_at":"2025-04-14T03:25:57.029Z","avatar_url":"https://github.com/imcuttle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Walli\n\n[![build status](https://img.shields.io/travis/imcuttle/walli/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/walli)\n[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/walli.svg?style=flat-square)](https://codecov.io/github/imcuttle/walli?branch=master)\n[![NPM version](https://img.shields.io/npm/v/walli.svg?style=flat-square)](https://www.npmjs.com/package/walli)\n[![NPM Downloads](https://img.shields.io/npm/dm/walli.svg?style=flat-square\u0026maxAge=43200)](https://www.npmjs.com/package/walli)\n\nA manageable and immutable validation library.\n\n[Chinese](https://imcuttle.github.io/walli-born)\n\n[REPL](https://npm.runkit.com/walli)\n\n## Installation\n\n```bash\nnpm install walli --save\n```\n\n## Usage\n\n* `ok`\n\n```javascript\nimport { string, arrayOf } from 'walli'\n\nstring.ok('1') === true\nstring.ok(1) === false\narrayOf(string).ok(['a']) === true\narrayOf(string).ok(['a', 1]) === false\n```\n\n* `toUnlawfulString`\n\n```javascript\nstring.toUnlawfulString('1') === ''\nstring.toUnlawfulString(1) === 'expected type: string, actual type: number.'\nstringMatching('any').toUnlawfulString('axaxnyx', { delimiter: '\\n' }) ===\n  \"expected: stringMatching(/any/), actual: 'axaxnyx'.\"\n```\n\n* `check`\n\n```javascript\nstring.check('1').ok === true\nstring.check('1').toString({ delimiter: '\\n' }) ===\n  'expected type: string, actual type: number.'\n```\n\n* `message`\n\n```javascript\n// :actual: and :expected: are special placeholders.\nstring.message('error! :expected:  :actual:').toUnlawfulString(1) ===\n  'error! string  number'\n\nconst foo = eq({\n  name: string.message('name error!'),\n  age: number\n}).message('error happened')\n\nfoo.toUnlawfulString({\n  name: '',\n  age: 'er'\n}) === 'age: error happened'\n\nfoo.toUnlawfulString({\n  name: 222,\n  age: 19\n}) === 'name: name error!'\n```\n\n## [Custom Type](./src/__tests__/examples.spec.ts)\n\n* Expected Struction\n\n```typescript\n// typescript\ntype Person = {\n  name: string\n  age: string\n  gender: 'F' | 'M'\n  father?: Person\n  mother?: Person\n  children?: Person[]\n}\n```\n\n* Walli Type's Definition\n\n```javascript\nimport { string, eq, oneOf, arrayOf, array, integer, Verifiable } from 'walli'\nimport { util } from 'walli'\nconst { funcify, createVerifiableClass, createFinalVerifiable } = util\n\nconst person = createVerifiableClass({\n  getDisplayName() {\n    return 'person'\n  },\n  _check(req) {\n    return eq({\n      name: string,\n      age: integer,\n      gender: oneOf(['F', 'M']),\n      father: person().optional,\n      mother: person().optional,\n      children: arrayOf(person()).optional\n    }).check(req)\n  }\n})\n\nperson().ok({\n  name: 'cy',\n  age: 22,\n  gender: 'F'\n}) === true\nperson().toUnlawfulString({\n  // ...\n})\n// creates final verifiable instance like string / null_\nconst fperson = createFinalVerifiable(person)\nfperson.ok({\n  // ...\n})\n\n// Or using es6 syntax\nclass Person extends Verifiable {\n  static displayName = 'person'\n  _check(req) {\n    // same code here\n  }\n}\nconst es6Person = funcify(Person)\n```\n\nAnd the document named [How to write a customized type](./docs/How-To-Write-Customized-Type.md) would give you more help.\n\n## Related\n\n* [json-schema-walli](https://github.com/imcuttle/transform-json-schema) - Transform json schema to walli definition.\n\n## [Exported API](./src/walli.ts)\n\n[More Detail](https://imcuttle.github.io/walli)\n\n## Verifiable List\n\n### function\\_\n\n### null\\_\n\n### undefined\\_\n\n### primitive\n\n### object\n\n### array\n\n### any\n\n### nil\n\n* null or undefined\n\n### string\n\n### number\n\n### strictNumber\n\n### integer\n\n### any\n\n### objectOf(...)\n\n#### objectOf()\n\n#### objectOf(value)\n\n#### objectOf([value, key])\n\n### arrayOf(value)\n\n### be(value)\n\n### oneOf([a, b, c])\n\n### equal(value)\n\n* Alias `eq`\n\n### looseEqual(value)\n\n* Alias `leq`\n\n### not(value)\n\n### every([a, b, c])\n\n### some([a, b, c])\n\n### custom((...requests) =\u003e string | null)\n\n### instanceOf(Type)\n\n### stringMatching(string | regexp)\n\n## Class List\n\n### Verifiable\n\n### UnlawfulnessList\n\n### Unlawfulness\n\n### Reason\n\n### TypeReason\n\n### TypeItem\n\n### ToEqualReason\n\n## Utilities\n\n### checkEqual(request: any, expected, fallbackVerifiable)\n\n### single(str)\n\n### double(str)\n\n### inherits(Child, Parent)\n\n### getDisplayName(Type)\n\n### isRequired(req)\n\n### toString(instance)\n\n### funcify(Class)\n\n### constructify(Class)\n\n### getTypeName(Type)\n\n### createVerifiableClass(entities, options)\n\n### createFinalVerifiable(Verifiable, [rule, options])\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fwalli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcuttle%2Fwalli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcuttle%2Fwalli/lists"}