#filename #sanitizer

bin+lib sanitize-filename-reader-friendly

A filename sanitizer aiming to produce reader friendly filenames

11 releases (stable)

2.2.1 Nov 16, 2021
2.1.1 Aug 12, 2021
2.1.0 May 9, 2021
1.1.1 Mar 26, 2021
0.9.2 Mar 21, 2020

#457 in Text processing

Download history 466/week @ 2023-12-05 388/week @ 2023-12-12 312/week @ 2023-12-19 173/week @ 2023-12-26 456/week @ 2024-01-02 496/week @ 2024-01-09 663/week @ 2024-01-16 675/week @ 2024-01-23 622/week @ 2024-01-30 1132/week @ 2024-02-06 512/week @ 2024-02-13 565/week @ 2024-02-20 721/week @ 2024-02-27 782/week @ 2024-03-05 646/week @ 2024-03-12 1034/week @ 2024-03-19

3,255 downloads per month
Used in 5 crates (4 directly)

MIT/Apache

16KB
228 lines

sanitize-filename-reader-friendly

A filename sanitizer aiming to produce reader friendly filenames, while preserving as much information as possible.

Cargo Documentation License

Unlike Node's sanitize-filename, this library replaces non-file-system-compatible characters with underscore and space. Both are trimmed when they appear at the beginning or at the end of a line or when they repeat within. Non-printable punctuation marks are replaced by underscores, other non-printable characters by spaces, except the non-printable space U+200b which is filtered out. Newlines are replaced by dashes.

Sample usage:

extern crate sanitize_filename_reader_friendly;
use crate::sanitize_filename_reader_friendly::sanitize;

fn main() {
    println!("{}",
        sanitize("Read: http://blog.getreu.net/projects/tp-note/"));
    // Prints: "Read_ http_blog.getreu.net_projects_tp-note"
}

This library comes with a simple command-line application. Usage:

cargo install sanitize-filename-reader-friendly
sanitize-filename <input.txt >output.txt

Dependencies

~535KB