{"id":13484955,"url":"https://github.com/mizchi/lizod","last_synced_at":"2025-04-09T21:20:13.591Z","repository":{"id":168303841,"uuid":"643993109","full_name":"mizchi/lizod","owner":"mizchi","description":"lightweight zod-like validator","archived":false,"fork":false,"pushed_at":"2024-01-18T23:48:52.000Z","size":44,"stargazers_count":210,"open_issues_count":5,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T19:06:10.568Z","etag":null,"topics":["lizod","typescript","validation","validator","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mizchi.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":"2023-05-22T15:23:05.000Z","updated_at":"2024-12-30T14:44:32.000Z","dependencies_parsed_at":"2024-01-13T19:19:41.270Z","dependency_job_id":"b8d1b473-3405-4203-856c-40647b407959","html_url":"https://github.com/mizchi/lizod","commit_stats":null,"previous_names":["mizchi/lizod"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Flizod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Flizod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Flizod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Flizod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mizchi","download_url":"https://codeload.github.com/mizchi/lizod/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248112225,"owners_count":21049619,"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":["lizod","typescript","validation","validator","zod"],"created_at":"2024-07-31T17:01:40.190Z","updated_at":"2025-04-09T21:20:13.542Z","avatar_url":"https://github.com/mizchi.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","typescript"],"sub_categories":[],"readme":"# lizod\n\nLightweight zod-like validator (about 600bytes with full features)\n\n```bash\n$ npm install lizod -S\n```\n\ntypescript \u003e=5 required.\n\n## Concepts\n\n- Spiritual successor of zod but for bundle size.\n  - No method-chaining\n  - No string utils like `.email()`\n  - Very simple error reporter\n- Bare TypeScript's type expression helpers\n\n## How to use\n\n```ts\n// Pick validators for treeshake\nimport {\n  $any,\n  $array,\n  $boolean,\n  $const,\n  $enum,\n  $intersection,\n  $null,\n  $number,\n  $object,\n  $opt,\n  $regexp,\n  $string,\n  $symbol,\n  $undefined,\n  $union,\n  $void,\n  $record,\n  type Infer,\n  type Validator,\n} from \"lizod\";\n\nconst validate = $object({\n  name: $string,\n  age: $number,\n  familyName: $opt($string),\n  abc: $enum([\"a\", \"b\", \"c\"]),\n  nested: $object({\n    age: $number,\n  }),\n  static: $const(\"static\"),\n  items: $array($object({\n    a: $string,\n    b: $boolean,\n  })),\n  complex: $array($union([\n    $object({ a: $string }),\n    $object({ b: $number }),\n  ])),\n  sec: $intersection([$string, $const(\"x\")]),\n  record: $record($string, $number)\n});\n\nconst v: Infer\u003ctypeof validate\u003e = {\n  name: \"aaa\",\n  age: 1,\n  familyName: null,\n  abc: \"b\",\n  nested: {\n    age: 1,\n  },\n  static: \"static\",\n  items: [\n    {\n      a: \"\",\n      b: true,\n    },\n    {\n      a: \"\",\n      b: false,\n    },\n  ],\n  complex: [\n    { a: \"\" },\n    { b: 1 },\n  ],\n  sec: \"x\",\n  record: {\n    \"a\": 1,\n    \"b\": 2\n  }\n};\n\nif (validate(v)) {\n  const _1: string = v.name;\n  const _2: number = v.age;\n  const _3: string | void = v.familyName;\n  const _4: \"a\" | \"b\" | \"c\" = v.abc;\n  const _5: { age: number } = v.nested;\n  const _6: \"static\" = v.static;\n  const _7: Array\u003c{\n    a: string;\n    b: boolean;\n  }\u003e = v.items;\n}\n```\n\n## exact | loose object\n\nAllow unchecked params on object\n\n```ts\nimport {$object, $string} from \"lizod\";\n\n// default exact\nconst ret1 = $object({a: $string}, /* default */ true)({a: \"\", b: \"\"}); // =\u003e false\n// loose\nconst ret2 = $object({a: $string}, false)({a: \"\", b: \"\"}) // =\u003e true;\n```\n\ndefault mode is exact.\n\n## Error Reporter\n\n```ts\nimport { $object, $string, access } from \"lizod\";\n\n// your validator\nconst validate = $object({ a: $string });\n\nconst input = { a: 1 };\n\n// check with context mutation\nconst ctx = { errors: [] };\nconst ret = validate(input, ctx);\n\n// report errors\nfor (const errorPath of ctx.errors) {\n  console.log(\"error at\", errorPath, access(input, errorPath));\n}\n```\n\nDo not reuse `ctx`.\n\n## With custom validator\n\n```ts\nimport type { Validator, ValidatorContext } from \"lizod\";\n\n// simple validator\nconst isA: Validator\u003c\"A\"\u003e = (input: any): input is \"A\" =\u003e input === \"A\";\nconst myValidator = $object({\n  a: isA,\n});\n\n// create wrapper validator\n// you should pass context args to next validator for error reporter\nconst wrap: (child: Validator\u003cstring\u003e) =\u003e Validator\u003cstring\u003e =\n  (input: any, ctx: ValidatorContext, path = []): input is string =\u003e child(input, ctx, path);\n```\n\n## Relations\n\n- https://github.com/colinhacks/zod\n\n## ChangeLog\n\n### v0.2.6\n\n- added: `$record`\n- added: `$numberString`\n\n### v0.2.5\n\n- fix: `$intersection` return type https://github.com/mizchi/lizod/pull/13\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizchi%2Flizod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmizchi%2Flizod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizchi%2Flizod/lists"}