{"id":18931501,"url":"https://github.com/filibit/must-be-valid","last_synced_at":"2025-04-15T16:33:02.259Z","repository":{"id":59117303,"uuid":"535467017","full_name":"filiBit/must-be-valid","owner":"filiBit","description":"A Javascript library for type validation with Typescript support","archived":false,"fork":false,"pushed_at":"2022-10-03T01:23:15.000Z","size":140,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T20:18:46.801Z","etag":null,"topics":["data","javascript","typescript","validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/filiBit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-12T00:56:02.000Z","updated_at":"2024-09-27T21:45:34.000Z","dependencies_parsed_at":"2022-09-12T15:10:59.375Z","dependency_job_id":null,"html_url":"https://github.com/filiBit/must-be-valid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filiBit%2Fmust-be-valid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filiBit%2Fmust-be-valid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filiBit%2Fmust-be-valid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filiBit%2Fmust-be-valid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filiBit","download_url":"https://codeload.github.com/filiBit/must-be-valid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249108414,"owners_count":21214001,"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":["data","javascript","typescript","validation"],"created_at":"2024-11-08T11:42:24.707Z","updated_at":"2025-04-15T16:33:01.953Z","avatar_url":"https://github.com/filiBit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# must-be-valid\n\nA Javascript library for data \u0026 type validation with Typescript support\n\n## Install\n\n```sh\nnpm install must-be-valid\n```\n\n## Use\n\n```ts\nimport { mustBeArray, mustBeNumber, mustBeObject, mustBeString } from 'must-be-valid'\n\nfunction makeUser(userDto: unknown) {\n  const userInfo = mustBeObject(userDto) // throws if not valid\n\n  return {\n    username: mustBeString(userInfo.username), // throws if not valid\n    password: mustBeString(userInfo.password), // throws if not valid\n    age: mustBeNumber(userInfo.age), // throws if `age` is not a number\n    friendIds: mustBeArray(userInfo.friendIds).map((f) =\u003e mustBeString(f)), // throws if not valid\n  }\n}\n```\n\n### Awesome type inferencing\n\nThanks to extensive Typescript support by the library, including the use of generics, Typescript infers the following return type of `makeUser` function:\n\n```ts\nfunction makeUser(userDto: unknown): {\n  username: string\n  password: string\n  age: number\n  friendIds: string[]\n}\n```\n\n### Chaining\n\n```js\nconst password = mustBe.string(userInfo.password).min(7).max(50).value // throws if not valid\nconst age = mustBe.number(userInfo.age).min(13).value // throws if not valid\n```\n\n## Documentation\n\n- [API documentation](https://github.com/filiBit/must-be-valid/blob/main/API.md)\n- [Changelog](https://github.com/filiBit/must-be-valid/blob/main/CHANGELOG.md)\n- [Playground](https://codesandbox.io/s/must-be-valid-example-hykjgh)\n\n## Contribute\n\n1. open an Issue on GitHub, describe the changes you want to introduce and check the feedback from community\n1. from branch `develop` create a feature branch with descriptive name\n1. make changes\n1. check for code style inconsistencies with `npm run lint`\n1. ensure all tests pass: `npm run test`\n1. submit a Pull request with description\n\nThank you \u003c3\n\n## Contact author\n\n`filip.biterski@gmail.com`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilibit%2Fmust-be-valid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilibit%2Fmust-be-valid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilibit%2Fmust-be-valid/lists"}