{"id":14156652,"url":"https://github.com/arcanis/typanion","last_synced_at":"2025-05-15T11:09:24.470Z","repository":{"id":42613163,"uuid":"273340795","full_name":"arcanis/typanion","owner":"arcanis","description":"Static and runtime type assertion library with no dependencies","archived":false,"fork":false,"pushed_at":"2024-03-25T17:14:02.000Z","size":3689,"stargazers_count":272,"open_issues_count":19,"forks_count":17,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-14T19:58:58.190Z","etag":null,"topics":["typescript","validation"],"latest_commit_sha":null,"homepage":"https://mael.dev/typanion/","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/arcanis.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":"2020-06-18T21:10:46.000Z","updated_at":"2025-03-26T03:33:36.000Z","dependencies_parsed_at":"2024-01-16T22:21:07.609Z","dependency_job_id":"a12b0d17-d06c-46e2-bba5-8064bfb08251","html_url":"https://github.com/arcanis/typanion","commit_stats":{"total_commits":83,"total_committers":9,"mean_commits":9.222222222222221,"dds":"0.24096385542168675","last_synced_commit":"74d562a6f4c7ccfe2af5643703f5de8902f898d7"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arcanis%2Ftypanion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arcanis%2Ftypanion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arcanis%2Ftypanion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arcanis%2Ftypanion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arcanis","download_url":"https://codeload.github.com/arcanis/typanion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328386,"owners_count":22052632,"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":["typescript","validation"],"created_at":"2024-08-17T08:07:32.502Z","updated_at":"2025-05-15T11:09:24.454Z","avatar_url":"https://github.com/arcanis.png","language":"TypeScript","funding_links":[],"categories":["typescript"],"sub_categories":[],"readme":"# Typanion\n\n\u003e Static and runtime type assertion library with no dependencies\n\n[![](https://img.shields.io/npm/v/typanion.svg)]() [![](https://img.shields.io/npm/l/typanion.svg)]() [![](https://img.shields.io/badge/developed%20with-Yarn%202-blue)](https://github.com/yarnpkg/berry)\n\n## Installation\n\n```\nyarn add typanion\n```\n\n## Why\n\n- Typanion can validate nested arbitrary data structures\n- Typanion is type-safe; it uses [type predicates](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates)\n- Typanion allows you to derive types from your schemas\n- Typanion can report detailed error reports\n\nCompared to [yup](https://github.com/jquense/yup), Typanion has a better inference support for TypeScript + supports `isOneOf`. Its functional API makes it very easy to tree shake, which is another bonus (although the library isn't very large in itself).\n\n## Documentation\n\nCheck the website for our documentation: [mael.dev/typanion](https://mael.dev/typanion/).\n\n## Usage\n\nFirst define a schema using the builtin operators:\n\n```ts\nimport * as t from 'typanion';\n\nconst isMovie = t.isObject({\n    title: t.isString(),\n    description: t.isString(),\n});\n```\n\nThen just call the schema to validate any `unknown` value:\n\n```ts\nconst userData = JSON.parse(input);\n\nif (isMovie(userData)) {\n    console.log(userData.title);\n}\n```\n\nPassing a second parameter allows you to retrieve detailed errors:\n\n```ts\nconst userData = JSON.parse(input);\nconst errors: string[] = [];\n\nif (!isMovie(userData, {errors})) {\n    console.log(errors);\n}\n```\n\nYou can also apply coercion over the user input:\n\n```ts\nconst userData = JSON.parse(input);\nconst coercions: Coercion[] = [];\n\nif (isMovie(userData, {coercions})) {\n    // Coercions aren't flushed by default\n    for (const [p, op] of coercions) op();\n\n    // All relevant fields have now been coerced\n    // ...\n}\n```\n\nYou can derive the type from the schema and use it in other functions:\n\n```ts\nimport * as t from 'typanion';\n\nconst isMovie = t.isObject({\n    title: t.isString(),\n    description: t.isString(),\n});\n\ntype Movie = t.InferType\u003ctypeof isMovie\u003e;\n\n// Then just use your alias:\nconst printMovie = (movie: Movie) =\u003e {\n    // ...\n};\n```\n\nSchemas can be stored in multiple variables if needed:\n\n```ts\nimport * as t from 'typanion';\n\nconst isActor = t.isObject({\n    name: t.isString();\n});\n\nconst isMovie = t.isObject({\n    title: t.isString(),\n    description: t.isString(),\n    actors: t.isArray(isActor),\n});\n```\n\n## License (MIT)\n\n\u003e **Copyright © 2020 Mael Nison**\n\u003e\n\u003e Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\u003e\n\u003e The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\u003e\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farcanis%2Ftypanion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farcanis%2Ftypanion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farcanis%2Ftypanion/lists"}