{"id":16831105,"url":"https://github.com/nonameprovided/typeguard-composer","last_synced_at":"2025-03-17T22:50:32.658Z","repository":{"id":40903886,"uuid":"103158662","full_name":"NoNameProvided/typeguard-composer","owner":"NoNameProvided","description":"Performant and composable type guards for runtime data validation.","archived":false,"fork":false,"pushed_at":"2023-01-06T01:31:41.000Z","size":993,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2025-03-14T05:47:59.219Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/NoNameProvided.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-11T16:12:53.000Z","updated_at":"2025-02-25T16:59:37.000Z","dependencies_parsed_at":"2023-02-05T01:31:00.147Z","dependency_job_id":null,"html_url":"https://github.com/NoNameProvided/typeguard-composer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Ftypeguard-composer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Ftypeguard-composer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Ftypeguard-composer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NoNameProvided%2Ftypeguard-composer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NoNameProvided","download_url":"https://codeload.github.com/NoNameProvided/typeguard-composer/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244122470,"owners_count":20401431,"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-10-13T11:42:16.976Z","updated_at":"2025-03-17T22:50:32.637Z","avatar_url":"https://github.com/NoNameProvided.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typeguard-composer\n\n![CI][github-actions-badge] [![codecov][codecov-badge]][codecov-page]\n\nPerformant and composable type guards for runtime data validation.\n\n```ts\nimport { validate } from 'typeguard-composer';\nimport { isString, isNumber } from 'typeguard-composer/validators';\nimport { AddressSchema } from './my-address.schema';\n\n/**\n * Schemas are simple object where every value is an object or\n * array containing type guard functions or a single type guard function.\n */\nconst PersonSchema = {\n  name: isString,\n  age: isNumber,\n  addresses: [AddressSchema],\n};\n\nvalidate(PersonSchema, { name: 'Test Elek', age: 18, addresses: [] });\n```\n\n## Installation\n\n```bash\nnpm install typeguard-composer\n```\n\n## TODO\n\n- add two different error for schema and value errors\n- add support for logging/returning invalid values\n- add support for throwing error on extraneous values\n- return object instead of simple true/false with reasoning (eg: \"'MyValue' was expected to match isMyValidator.\")\n- create repo for complex types (dates, id formats, phone numbers, addresses, etc)\n\n## Usage\n\n_To be written... include info about defining schemas and how there validation works..._\n\n## API\n\nThe public API is extremely small, it consists only one function to validate values against schemas and a validator for every primitive types which can be used to build custom schemas.\n\n### `validate` function\n\nTries to validate the received value against the received schema. If the value is valid it returns true and false otherwise.\n\n\u003c!-- **Possible errors:** --\u003e\n\u003c!--  --\u003e\n\u003c!-- - `TypeError` when the provided value does not match the provided schema. --\u003e\n\n**Signature:**\n\n```ts\nvalidate(schema: TypeSchema, value: any, options: ValidatorOptions): boolean\n```\n\n---\n\n### Validators\n\n- validators are simple functions what implement the type guard pattern described the [Typescript documentation][ts-typeguards]\n- this library includes validators for the basic primitive types only\n- you can and should define your own validators when using this library\n- validators should be fairly simple in complexity and check a single value\n\n\u003e _Note: You can check out the [NoNameProvided/typeguard-composer-validators][tcv-repo] repository to see a list of available pre-written complex schemas and validator functions._\n\nList of included base validators:\n\n- `isBoolean`\n- `isNumber`\n- `isString`\n- `isSymbol`\n- `isNull`\n- `isUndefined`\n- `isObject`\n- `isArray`\n- `isFunction`\n- `isAny` - always returns true\n- `isValue` - return true when the provided value is not `null` or `undefined`\n\n## License\n\nMIT Licensed\n\n[codecov-badge]: https://codecov.io/gh/NoNameProvided/typeguard-composer/branch/master/graph/badge.svg\n[codecov-page]: https://codecov.io/gh/NoNameProvided/typeguard-composer\n[github-actions-badge]: https://github.com/NoNameProvided/typeguard-composer/workflows/Continuous%20Integration/badge.svg?branch=master\u0026event=push\n[tcv-repo]: https://github.com/NoNameProvided/typeguard-composer-validators\n[ts-typeguards]: https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonameprovided%2Ftypeguard-composer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnonameprovided%2Ftypeguard-composer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonameprovided%2Ftypeguard-composer/lists"}