Invalid path and filename in Windows
Firstly, thanks for the utility it helped me split my large MD files (and learn a bit about Node JS).
I'm posting my solution because I have never done a pull request before.
My MD file has headings like this (note the embedded ':' and '/')
#### AAA-BBB-1100: Some Title / Other Text
My split-md args were:
cli.args[0]="F:/a/b/c/markdownfile.md";
cli.args[1]="#### ";
cli.args[2]="####";
cli.args[3]="F:/a/b/c/";
So after Line 28
title="F:/a/b/c/AAA-BBB-1100: Some Title / Other Text"
The title/path is still ok at this point. but after Line 29
title="F/a/b/c/AAA-BBB-1100:Some Title / Other Text.md"
The first ':' is removed making the drive field invalid. Remaining ':' are not removed because title.replace() only replaces the first occurrence. The same happens with the space ' ' replacement. Anothe problem is that the '/' in the ""filename" is not removed also making it an invalid path.
I replaced these two lines... https://github.com/accraze/split-md/blob/495101ecef2fc1dd07729c359487a2d4edb73ad1/src/splitter.js#L28-L29
With these 3 lines...
title = array[i].replace(cleanName, "").trim()
title = sanitize(title, {replacement: "-"});
title = writePath + title + ".md";
The writePath is only added after the title is cleaned otherwise it messes up the path. I used the sanitize-filename library.
const sanitize = require('sanitize-filename');
p.s. I prefer leaving the spaces in the filename and replace illegal characters with a dash. '-'