{"id":13469513,"url":"https://github.com/ryasmi/rulr","last_synced_at":"2025-04-05T18:08:57.699Z","repository":{"id":37616559,"uuid":"76304512","full_name":"ryasmi/rulr","owner":"ryasmi","description":"📐 Validation and unit conversion errors in TypeScript at compile-time. Started in 2016. Publicised in 2020.","archived":false,"fork":false,"pushed_at":"2025-04-04T05:58:30.000Z","size":11529,"stargazers_count":46,"open_issues_count":8,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T06:30:23.469Z","etag":null,"topics":["javascript","sanitization","typescript","unit-conversion","validation"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/rulr","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/ryasmi.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-12T23:27:48.000Z","updated_at":"2025-04-04T05:58:33.000Z","dependencies_parsed_at":"2022-07-14T06:30:31.736Z","dependency_job_id":"a652bb33-be6b-4c52-a7bd-0134605f1c5a","html_url":"https://github.com/ryasmi/rulr","commit_stats":null,"previous_names":["ryasmi/rulr","ryansmith94/rulr"],"tags_count":93,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryasmi%2Frulr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryasmi%2Frulr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryasmi%2Frulr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryasmi%2Frulr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryasmi","download_url":"https://codeload.github.com/ryasmi/rulr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135041,"owners_count":20889414,"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":["javascript","sanitization","typescript","unit-conversion","validation"],"created_at":"2024-07-31T15:01:43.047Z","updated_at":"2025-04-05T18:08:57.682Z","avatar_url":"https://github.com/ryasmi.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e📐\u003c/br\u003erulr\u003c/h1\u003e\n\t\u003cp\u003eValidation and \u003ca href=\"./docs/unitConversionErrorProtection.md\"\u003eunit conversion errors\u003c/a\u003e in TypeScript at compile-time.\u003c/p\u003e\n\t\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-d9207b.svg\" alt=\"License: MIT\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/semantic-release/semantic-release\"\u003e\u003cimg src=\"https://img.shields.io/badge/%F0%9F%93%A6%F0%9F%9A%80%20-semantic%20release-d9207b.svg\" alt=\"Uses Semantic Release to correctly bump versions especially for breaking changes\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://renovatebot.com/\"\u003e\u003cimg src=\"https://img.shields.io/badge/%F0%9F%94%84%F0%9F%A4%96%20-renovate%20bot-d9207b.svg\" alt=\"Uses Renovate to keep dependencies updated\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://codecov.io/gh/ryasmi/rulr\"\u003e\u003cimg alt=\"Master branch coverage percentage from Codecov\" src=\"https://codecov.io/gh/ryasmi/rulr/branch/master/graph/badge.svg\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://bundlephobia.com/result?p=rulr\"\u003e\u003cimg alt=\"Package size from BundlePhobia\" src=\"https://img.shields.io/bundlephobia/minzip/rulr.svg\" /\u003e\u003c/a\u003e\n\t\u003cdiv\u003e\n\t\u003c/div\u003e\n\u003c/div\u003e\n\n```ts\n// Install it with `npm i rulr`\nimport * as rulr from 'rulr'\n\n// Compile-time error.\nconst positiveNumber1: rulr.PositiveNumber = -1\n\n// Run-time error.\nconst positiveNumber2 = rulr.positiveNumber(-1)\n\n// Convenient rules and guards like `object`.\nconst example = rulr.object({\n\trequired: {\n\t\tprice: rulr.positiveNumber,\n\t},\n})\n\n// Turn rules into types to avoid duplicating information.\ntype Example = rulr.Static\u003ctypeof example\u003e\n\n// Turn rules into guards to avoid duplicating code.\nconst isExample = rulr.guard(example)\n\n// Use rules and/or guards to guarantee your data is valid.\nconst myExample: Example = example({ price: 12.34 })\nif (isExample(myExample)) {\n\tconsole.log(myExample.price)\n}\n```\n\n### Getting Started ✨\n\nTo save you some time, Rulr comes with the following rules.\n\n- [allowNull](./src/higherOrderRules/allowNull/readme.md)\n- [allowUndefined](./src/higherOrderRules/allowUndefined/readme.md)\n- [any](./src/valueRules/any/readme.md)\n- [array](./src/higherOrderRules/array/readme.md)\n- [bigint](./src/valueRules/bigint/readme.md)\n- [boolean](./src/valueRules/boolean/readme.md)\n  - [trueRule](./src/valueRules/trueRule/readme.md)\n  - [falseRule](./src/valueRules/falseRule/readme.md)\n- [constant](./src/valueRules/constant/readme.md)\n- [date](./src/valueRules/date/readme.md)\n- [dictionary](./src/higherOrderRules/dictionary/readme.md)\n- [enum](./src/valueRules/enum/readme.md)\n- [literal](./src/valueRules/literal/readme.md)\n- [number](./src/valueRules/number/readme.md)\n- [object](./src/higherOrderRules/object/readme.md)\n- [string](./src/valueRules/string/readme.md)\n- [symbol](./src/valueRules/symbol/readme.md)\n- [tuple](./src/higherOrderRules/tuple/readme.md)\n- [union](./src/higherOrderRules/union/readme.md)\n- [unknown](./src/valueRules/unknown/readme.md)\n\n### Sized Strings\n\nSince it's quite common to want to restrict the size of strings to avoid UI overflow bugs and DB storage errors, Rulr comes with some convenient rules for doing just that.\n\n- [nonEmptyString](./src/sizedStrings/nonEmptyString/readme.md)\n- [tinyText](./src/sizedStrings/tinyText/readme.md) (0 - 255 characters)\n- [text](./src/sizedStrings/text/readme.md) (0 - 65,535 characters)\n- [mediumText](./src/sizedStrings/mediumText/readme.md) (0 - 16,777,215 characters)\n\n### Constraining Strings\n\nRulr comes with a growing list of convenient rules for constraining strings that are mostly built on [Chris O'Hara's extensive and much loved validator package](https://www.npmjs.com/package/validator). As with the rules for sized strings above, this can help prevent UI overflow bugs, DB storage errors, and processing errors.\n\n- [email](./src/constrainedStrings/email/readme.md)\n- [iri](./src/constrainedStrings/iri/readme.md)\n- [iso8601Duration](./src/constrainedStrings/iso8601Duration/readme.md)\n- [iso8601FullDate](./src/constrainedStrings/iso8601FullDate/readme.md)\n- [iso8601Timestamp](./src/constrainedStrings/iso8601Timestamp/readme.md)\n- [locale](./src/constrainedStrings/locale/readme.md)\n- [mailto](./src/constrainedStrings/mailto/readme.md)\n- [mimeType](./src/constrainedStrings/mimeType/readme.md)\n- [mongoId](./src/constrainedStrings/mongoId/readme.md)\n- [scormInteractionType](./src/constrainedStrings/scormInteractionType/readme.md)\n- [semanticVersion](./src/constrainedStrings/semanticVersion/readme.md)\n- [sha1](./src/constrainedStrings/sha1/readme.md)\n- [url](./src/constrainedStrings/url/readme.md)\n- [uuidv4](./src/constrainedStrings/uuidv4/readme.md)\n\n### Constraining Non-Strings\n\nIn addition to the constrained strings, Rulr comes with a few convenient rules to help you quickly validate non-string values.\n\n- [integer](./src/constrainedValues/integer/readme.md)\n- [negativeInteger](./src/constrainedValues/negativeInteger/readme.md)\n- [negativeNumber](./src/constrainedValues/negativeNumber/readme.md)\n- [positiveInteger](./src/constrainedValues/positiveInteger/readme.md)\n- [positiveNumber](./src/constrainedValues/positiveNumber/readme.md)\n\n### Sanitization Rules\n\nRulr provides rules that sanitize inputs from HTTP headers and URL params.\n\n- [sanitizeBooleanFromString](./src/sanitizationRules/sanitizeBooleanFromString/readme.md)\n- [sanitizeJsonFromString](./src/sanitizationRules/sanitizeJsonFromString/readme.md)\n- [sanitizeNumberFromString](./src/sanitizationRules/sanitizeNumberFromString/readme.md)\n- [sanitizeBasicAuthFromString](./src/sanitizationRules/sanitizeBasicAuthFromString/readme.md)\n- [sanitizeJWTBearerAuthFromString](./src/sanitizationRules/sanitizeJWTBearerAuthFromString/readme.md)\n\n### Rule Constructors\n\nFinally, Rulr is starting to provide rule constructors that allow you quickly make your own rules.\n\n- [regexRuleConstructor](./src/ruleConstructors/regexRuleConstructor/readme.md)\n- [sizedArrayRuleConstructor](./src/ruleConstructors/sizedArrayRuleConstructor/readme.md)\n\n### Frequently Awesome Questions 🤘\n\n- [How does Rulr protect against unit conversion errors?](./docs/unitConversionErrorProtection.md)\n- [How do I create my own rules?](./docs/customRules.md)\n- [Can I add new rules to this package?](./docs/newRules.md)\n- [Why not use classes?](./docs/classValidationProblems.md)\n- [Why are unique symbols needed for each type?](./docs/symbolRequirement.md)\n- [How are recursive rules defined?](./docs/recursiveRules.md)\n- [Can Rulr be used with React Hooks and PropTypes?](./docs/react.md)\n- [Can Rulr be used with Express?](./docs/express.md)\n- [Why are you using tabs!?!](https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/)\n- [Why is the bundle size quite large?](https://bundlephobia.com/result?p=rulr)\n- [How does the performance compare to other validation packages?](https://github.com/moltar/typescript-runtime-type-benchmarks)\n- [How often are breaking changes/major version bumps released?](./docs/breakingChangeFrequency.md)\n\n### Background\n\nRulr was started in 2016 and [first publicised in 2020](https://www.reddit.com/r/typescript/comments/hb1nt6/rulr_typescript_package_to_save_you_time_writing/). It continues to be maintained to save us time writing validation logic and correcting data by returning as many validation errors as possible in one function call.\n\nRulr has been influenced by [Tom Crockett in RunTypes](https://github.com/pelotom/runtypes) and more recently [Colin McDonnell in Zod](https://github.com/vriad/zod). It's hoped that if nothing else, publicising Rulr will influence existing and future validation packages for the better.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryasmi%2Frulr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryasmi%2Frulr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryasmi%2Frulr/lists"}