{"id":25306656,"url":"https://github.com/neworbit/not-valid","last_synced_at":"2025-10-28T11:31:05.565Z","repository":{"id":48030315,"uuid":"90616866","full_name":"NewOrbit/not-valid","owner":"NewOrbit","description":"Extensible and flexible TypeScript validation","archived":false,"fork":false,"pushed_at":"2023-05-23T10:18:06.000Z","size":95,"stargazers_count":3,"open_issues_count":6,"forks_count":0,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-01-30T12:42:05.858Z","etag":null,"topics":["hacktoberfest","javascript","nodejs","package","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NewOrbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-05-08T10:42:28.000Z","updated_at":"2023-05-22T10:47:12.000Z","dependencies_parsed_at":"2024-06-21T17:51:36.241Z","dependency_job_id":"63200358-a401-4eb6-8c12-9f26ae0b396e","html_url":"https://github.com/NewOrbit/not-valid","commit_stats":{"total_commits":101,"total_committers":8,"mean_commits":12.625,"dds":"0.27722772277227725","last_synced_commit":"b64c4420a1fb15172d302ecdd10090f9cfc687d9"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewOrbit%2Fnot-valid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewOrbit%2Fnot-valid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewOrbit%2Fnot-valid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewOrbit%2Fnot-valid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NewOrbit","download_url":"https://codeload.github.com/NewOrbit/not-valid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238641758,"owners_count":19506187,"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":["hacktoberfest","javascript","nodejs","package","typescript","validation"],"created_at":"2025-02-13T10:36:55.745Z","updated_at":"2025-10-28T11:31:05.062Z","avatar_url":"https://github.com/NewOrbit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# not-valid\n\nComposable message-based validation\n\n## Installation\n\n    $ npm install not-valid --save\n\n## Usage\n\n### Overview\n\n```typescript\nimport { validate } from \"not-valid\";\n\n// Use createValidator to specify a rule and the message given for breaking that rule\nconst mustContainA = createValidator\u003cstring\u003e(v =\u003e v.indexOf(\"A\") !== -1, \"Value must contain the letter 'a'\");\n\n// pass in array of validation functions and a value to validate\nvalidate([ mustContainA ], \"cheese\"); // [ \"Value must contain the letter 'a'\" ] - returns error messages\n\n// can use a factory pattern for your validation methods to make things nice\nconst mustContain = (requirement: any) =\u003e {\n    return createValidator\u003cstring | Array\u003cany\u003e\u003e(v =\u003e v.indexOf(requirement) !== -1, `Value must contain '${requirement}'`);\n};\n\nconst lengthWithinBounds = (min: number, max: number) =\u003e {\n    return createValidator\u003cstring\u003e(v =\u003e v.length \u003c min || v.length \u003e max, `Value must have length between ${min} and ${max}`);\n};\n\n// you can pass in multiple validators\nvalidate([ \n    mustContain(\"Z\"), \n    lengthWithinBounds(2, 6)\n], \"Too long a string, they say!\"); // [ \"Value must contain 'Z'\", \"Value must have length between 2 and 6\" ]\n```\n\n### Validators\n\nA number of validation functions come bundled with this package. You can use them like so:\n\n```typescript\nimport { validators } from \"not-valid\";\n\nvalidate([\n    validators.validLength({ min: 6, max: 12 })\n], \"Good value\");\n```\n\nThe validators included are as follows:\n\n- `requiredString`\n- `requiredNumber`\n- `validLength`\n- `validEmail`\n- `validAlphaNumeric`\n- `validOption`\n- `validPhoneNumber`\n- `validNINumber`\n- `validUKDrivingLicence`\n- `validSortCode`\n- `validBankAccountNumber`\n- `validVATNumber`\n\n### Creating validation functions\n\nA validation function must take in a value `value`, and return `Result.Pass` if `value` is valid, or `Result.Fail(message)` is `value` is invalid. They can also return `Result.Stop`, which will silently stop the validation cycle (no more errors).\n\nThis can be done with the helper method `createValidator` in `not-valid`:\n\n```typescript\nimport { createValidator } from \"not-valid\";\n\nconst mustContainA = createValidator\u003cstring\u003e(v =\u003e v.indexOf(\"A\") !== -1, \"Value must contain the letter 'a'\");\n```\n\nYou can use factory patterns around this to make it nicer:\n\n```typescript\nconst mustContain = (requirement: any) =\u003e {\n    return createValidator\u003cstring | Array\u003cany\u003e\u003e(v =\u003e v.indexOf(requirement) !== -1, `Value must contain '${requirement}'`);\n};\n```\n\nAll validators (except for validators that explicitly check for \"required\") should treat empty string, null and undefined\nas valid.\nThis is because we can combine validators with \"required\" validators in order to enforce something being valid and not empty,\nbut also allows us to accept nothing being entered if desired.\n\n### Options\n\nThe third parameter of `validate` is an object containing options.\n\n```typescript\ninterface ValidationOptions {\n    sequential?: boolean;\n}\n```\n\n#### `sequential`\n\nDefault: `true`\n\nThe validation will break on the first error, therefore only returning a single validation error.\n\n```typescript\nvalidate([ something, another ], 5, { sequential: false });\n```\n\nIf `something` fails validation, `another` will not be called.\n\n## License\n\nMade with :sparkling_heart: by [NewOrbit](https://www.neworbit.co.uk/) in Oxfordshire, and licensed under the [MIT Licence](LICENCE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneworbit%2Fnot-valid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneworbit%2Fnot-valid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneworbit%2Fnot-valid/lists"}