{"id":20284719,"url":"https://github.com/dashxhq/sanitizer","last_synced_at":"2025-08-21T11:15:14.699Z","repository":{"id":37782690,"uuid":"317129486","full_name":"dashxhq/sanitizer","owner":"dashxhq","description":"Dead easy sanitizing for rust structs","archived":false,"fork":false,"pushed_at":"2025-06-04T08:39:18.000Z","size":130,"stargazers_count":10,"open_issues_count":1,"forks_count":3,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2025-06-04T13:25:00.741Z","etag":null,"topics":["rust","sanitize","structs"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/dashxhq.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,"zenodo":null}},"created_at":"2020-11-30T06:20:29.000Z","updated_at":"2024-08-22T20:00:28.000Z","dependencies_parsed_at":"2025-04-11T08:56:26.832Z","dependency_job_id":"1eb69222-8671-4ee4-9994-199e8b446a83","html_url":"https://github.com/dashxhq/sanitizer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dashxhq/sanitizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashxhq%2Fsanitizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashxhq%2Fsanitizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashxhq%2Fsanitizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashxhq%2Fsanitizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashxhq","download_url":"https://codeload.github.com/dashxhq/sanitizer/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashxhq%2Fsanitizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271469227,"owners_count":24765124,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["rust","sanitize","structs"],"created_at":"2024-11-14T14:21:17.285Z","updated_at":"2025-08-21T11:15:14.681Z","avatar_url":"https://github.com/dashxhq.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sanitizer\n\nInspired by the [validator](https://github.com/Keats/validator) crate. The Sanitizer crate is a collection of\nmethods and a macro to sanitize struct fields, leveraging the macros of rust, it follows the elegant approach by\nthe validator crate.\n\n# Overview\n\n```rust\n[dependencies]\nsanitizer = { version = \"0.1\", features = [\"derive\"] }\n```\n\nThen to use the crate\n\n```rust\nuse sanitizer::prelude::*;\n\n#[derive(Debug, Sanitize)]\nstruct SignupData {\n    #[sanitize(trim, lower_case)]\n    mail: String,\n    #[sanitize(clamp(1, 60))]\n    age: u8,\n    #[sanitize]\n    user: User,\n}\n\n#[derive(Debug, Sanitize)]\nstruct User {\n    id: u64,\n    #[sanitize(trim, clamp(50))]\n    name: String,\n}\n\nfn main() {\n    let instance = SignupData::new();\n    instance.sanitize();\n}\n```\n\nIf you do not want to use the derive macro, then the sanitizer crate provides structures and methods for sanitizing\nints\n\n```rust\nlet int: u8 = 50;\nlet mut instance = IntSanitizer::from(int);\ninstance.clamp(99, 101);\nassert_eq!(99, instance.get());\n```\n\nand strings\n\n```rust\nlet mut sanitize = StringSanitizer::from(\"    some_string12 \");\nsanitize.trim().numeric();\nassert_eq!(\"12\", sanitize.get());\n```\n\n# Sanitizers\n\n### trim\n\nRemoves whitespace from ends.\n\n### numeric\n\nRemoves any character that is not a numeric.\n\n### alphanumeric\n\nRemoves any character that is not an alphanumeric.\n\n### lower_case\n\nConverts string input to lowercase.\n\n### upper_case\n\nConverts string input to UPPERCASE.\n\n### camel_case\n\nConverts string input to camelCase.\n\n### snake_case\n\nConverts string input to snake_case.\n\n### screaming_snake_case\n\nConverts string input to SCREAMING_SNAKE_CASE using the [Inflector](https://github.com/whatisinternet/Inflector) crate.\n\n### e164\n\nConverts string input to E164 International Phone Number format. This panics if the phone number is not a valid one.\n\n### clamp(min, max)\n\nLimit an valid integer field with the given min and max.\n\n### clamp(max)\n\nLimit a string input length to the following number\n\n### custom(function)\n\nUse a custom function to sanitize a field differently. For example\n\n```rust\n\n#[derive(Sanitize)]\nstruct SanitizerTest {\n    #[sanitize(custom(func_string))]\n    field_string: String,\n}\n\nfn func_string(field: \u0026str) -\u003e String {\n    let mut sanitizer = StringSanitizer::from(field);\n    sanitizer.trim();\n    sanitizer.get()\n}\n\n#[test]\nfn sanitizer_check_custom_functions() {\n    let mut instance = SanitizerTest {\n        field_string: String::from(\"Hello    \"),\n    };\n    instance.sanitize();\n    assert_eq!(instance.field_string, String::from(\"Hello\"));\n}\n```\n\n### nesting\n\n```rust\n#[derive(Sanitize)]\nstruct First {\n    #[sanitize(trim)]\n    name: String,\n    #[sanitize]\n    info: OtherInfo,\n}\n\n#[derive(Sanitize)]\nstruct OtherInfo {\n    #[sanitize(numeric)]\n    id: String,\n    #[sanitize(lower_case, trim)]\n    email: String,\n}\n\n```\n\nThe `sanitize` method of `First` will call the sanitizer method of `OtherInfo` automatically,\nif you would like to individually snaitize `OtherInfo` then you can just call `snaitize` on one of its instance.\n\n# LICENSE\n\ndashxhq/sanitizer is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashxhq%2Fsanitizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashxhq%2Fsanitizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashxhq%2Fsanitizer/lists"}