Skip to content
pubscout

sanitize_filename

1.0.5, released 4 years ago by e-go-mobile.de

Sanitizes strings by removing or replacing characters illegal for filenames.

WASM-readyRepository archived
$ flutter pub add sanitize_filename
Source repository

What it does

The package replaces characters that are unsafe or illegal in filenames with a safe alternative. You can specify a custom replacement character. It works on all supported Dart platforms.

AI-written summary of version 1.0.5, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to store user‑provided text as a file name
  • Cross‑platform filename safety without extra dependencies

Skip it when

  • You require full path validation or complex sanitization rules
  • You need asynchronous or stream‑based processing

Strengths

  • Zero dependencies
  • Works on all Dart platforms
  • Customizable replacement character

Weaknesses

  • Only handles character replacement, no path normalization
  • Limited configurability

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
import 'package:sanitize_filename/sanitize_filename.dart';

void main() {
  const unsafe = "~/.ssh/authorized_keys";
  final safe1 = sanitizeFilename(unsafe);
  final safe2 = sanitizeFilename(unsafe, replacement: '-');
  print(safe1); // "~.sshauthorized_keys"
  print(safe2); // "~-.-ssh-authorized_keys"
}

Alternatives

Packages that do the same job and could replace sanitize_filename.

  • validators2

    String validation and sanitization for Dart.

  • ulid

    Lexicographically sortable 128-bit identifier generator.

  • uid

    Generates timestamp‑based unique IDs and random barcodes with configurable length and charset.

  • diacritic

    Removes common accents and diacritical signs from strings.