#filename #sanitizer #node #name #file #replace #windows

bin+lib sanitize-filename

A simple filename sanitizer, based on Node's sanitize-filename

6 releases (breaking)

Uses old Rust 2015

0.5.0 Jul 31, 2023
0.4.0 May 7, 2022
0.3.0 Oct 18, 2020
0.2.1 Oct 24, 2018
0.1.0 Oct 24, 2018

#72 in Parser implementations

Download history 20150/week @ 2023-12-13 14907/week @ 2023-12-20 15113/week @ 2023-12-27 22115/week @ 2024-01-03 22126/week @ 2024-01-10 25475/week @ 2024-01-17 20943/week @ 2024-01-24 21664/week @ 2024-01-31 19144/week @ 2024-02-07 22259/week @ 2024-02-14 19699/week @ 2024-02-21 21366/week @ 2024-02-28 20688/week @ 2024-03-06 21842/week @ 2024-03-13 27183/week @ 2024-03-20 20622/week @ 2024-03-27

94,732 downloads per month
Used in 136 crates (54 directly)

MIT license

12KB
308 lines

sanitize-filename

A basic filename sanitizer, based on Node's sanitize-filename.

Use like:

extern crate sanitize_filename;

fn main() {
    println!("{}", sanitize_filename::sanitize("some-user-defined/../../../string"));
    // prints some-user-defined......string
}

You can also configure a few basic options:

let options = sanitize_filename::Options {
    truncate: true, // true by default, truncates to 255 bytes
    windows: true, // default value depends on the OS, removes reserved names like `con` from start of strings on Windows
    replacement: "" // str to replace sanitized chars/strings
};

let sanitized = sanitize_filename::sanitize_with_options("some-user-defined/../../../string", options);

Also provides a basic command line binary. Use like:

cargo install sanitize-filename
sanitize-filename my_filename.txt
Pass a file name to clean to the program (also reads STDIN)

FLAGS:
    -r, --replace <r>          Replacement characters
    --windows, --no-windows    Whether to handle filenames for Windows
    --truncate, --no-truncate  Whether to truncate file names to 255 bytes

Dependencies

~2.8–4MB
~67K SLoC