{"id":21852603,"url":"https://github.com/caesarovich/legalize","last_synced_at":"2026-05-11T06:14:43.346Z","repository":{"id":236101270,"uuid":"791388434","full_name":"Caesarovich/legalize","owner":"Caesarovich","description":"Checks for/sanitizes illegal characters in file names for different platforms.","archived":false,"fork":false,"pushed_at":"2024-05-15T15:46:46.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T13:25:48.480Z","etag":null,"topics":["cross-platform","filename","flutter","library","sanitization"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Caesarovich.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-04-24T16:20:50.000Z","updated_at":"2024-12-22T10:47:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"3ee6a9a5-398f-42ef-a086-a7ace9efe3e5","html_url":"https://github.com/Caesarovich/legalize","commit_stats":null,"previous_names":["caesarovich/legalize"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caesarovich%2Flegalize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caesarovich%2Flegalize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caesarovich%2Flegalize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caesarovich%2Flegalize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Caesarovich","download_url":"https://codeload.github.com/Caesarovich/legalize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244852027,"owners_count":20521150,"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":["cross-platform","filename","flutter","library","sanitization"],"created_at":"2024-11-28T01:17:45.659Z","updated_at":"2026-05-11T06:14:43.303Z","avatar_url":"https://github.com/Caesarovich.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"This package provides a set of functions to validate and sanitize filenames for different operating systems.\n\nPlease read the [documentation](https://pub.dev/documentation/legalize/latest/) for more information.\n\n\u003e **Note:** This package is still in development and may not be stable. Please use with caution.\n\n## Features\n\n- ✅ Validate/Sanitize filenames for Windows\n- ✅ Validate/Sanitize filenames for macOS/iOS (HFS/HFS+)\n- ✅ Validate/Sanitize filenames for Android (FAT32)\n- ✅ Validate/Sanitize filenames for Linux, and other POSIX systems\n\n\u003e **Note:** While this package strives to provide a comprehensive solution for validating filenames, it may not cover all types of file system or edge cases. Please report any issues you encounter.\n\n## Installing\n\nAdd this to your package's `pubspec.yaml` file:\n\n```yaml\ndependencies:\n  legalize: ^1.2.2\n```\n\n## Usage\n\nYou can sanitize filenames by using the `legalizeFilename` function:\n\n```dart\nimport 'package:legalize/legalize.dart';\n\nvoid main() {\n\tconst someFilename = 'my?/?/?File.txt';\n\n\tfinal sanitizedFilename = legalizeFilename(someFilename);\n\n\tprint(sanitizedFilename); // myFile.txt\n}\n```\n\nYou can also specify the operating system to sanitize the filename for:\n\n```dart\nimport 'dart:io' show Platform;\n\nimport 'package:legalize/legalize.dart';\n\nvoid main() {\n\tconst someFilename = 'my?/?/?File.txt';\n\n\tfinal sanitizedFilename = legalizeFilename(someFilename, os: Platform.operatingSystem);\n\n\tprint(sanitizedFilename); // On Windows: my//File.txt, On other systems: my???File.txt\n}\n```\n\nYou can use specififc function for Windows:\n\n```dart\nimport 'package:legalize/legalize.dart';\n\nvoid main() {\n\tconst someFilename = 'my?\u003c|File.txt';\n\n\tfinal sanitizedFilename = legalizeWindowsFilename(someFilename);\n\tprint(sanitizedFilename); // myFile.txt\n}\n```\n\nOr for macOS/iOS:\n\n```dart\nimport 'package:legalize/legalize.dart';\n\nvoid main() {\n\tconst someFilename = 'my/:/:File.txt';\n\n\tfinal sanitizedFilename = legalizeHFSFilename(someFilename);\n\tprint(sanitizedFilename); // myFile.txt\n}\n```\n\nOr for other systems:\n\n```dart\nimport 'package:legalize/legalize.dart';\n\nvoid main() {\n\tconst someFilename = 'my///File.txt';\n\n\tfinal sanitizedFilename = legalizePosixFilename(someFilename);\n\tprint(sanitizedFilename); // myFile.txt\n}\n```\n\nYou can also validate filenames:\n\n```dart\nimport 'dart:io' show Platform;\n\nimport 'package:legalize/legalize.dart';\n\nvoid main() {\n  const someFilename = 'some???Filename.txt';\n\n  if (!isValidFilename(someFilename, os: Platform.operatingSystem)) {\n\t\tprint('Filename is invalid for this system');\n\t} else {\n\t\tprint('Filename is valid for this system');\n\t}\n\n}\n```\n\n## Specifics\n\nFor ease of use and development, this library makes the following assumptions:\n\n- The NUL character (0) is not allowed in filenames on any system. (Even though it is allowed on some systems)\n- The ASCII control characters (0-31 and 127) are not allowed in filenames on any system by default. These can be preserved for HFS (_MacOS/iOS_) and Posix (_Linux_) systems using the `shouldReplaceControlCharacters` parameter.\n- The slash (`/`) character is not allowed in filenames on any system.\n- A filename cannot be empty.\n- A filename cannot be `.` or `..`.\n- A filename's length cannot exceed 255 characters.\n\nThese assumptions are based on the most common restrictions across different operating systems.\n\nThe `legalizeFilename` and `isValidFilename` functions assume the most \"restrictive\" set of restrictions by default for a given operating system:\n\n- On Android, the FAT32 restrictions are applied even though Android also supports EXT filesystems (Which is less restrictive).\n- On MacOS/iOS, the HFS restrictions are applied even though MacOS/iOS also supports APFS (Which is less restrictive).\n- On Fuchsia, the universal restrictions are applied because I couldn't find any information on the filesystem used by Fuchsia.\n\n## Contributing\n\nIf you encounter any issues or have any suggestions, please open an issue. If you would like to contribute, please open a pull request. All contributions are welcome.\n\n## Additional information\n\nThis package was inspired by the [sanitize_filename](https://pub.dev/packages/sanitize_filename) package. I created this package because I needed a more flexible solution for my use case.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaesarovich%2Flegalize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaesarovich%2Flegalize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaesarovich%2Flegalize/lists"}