Asciifying File Names

35 views
Skip to first unread message

P. Douglas Reeder

unread,
Apr 29, 2012, 2:32:10 PM4/29/12
to nodejs
I have an external requirement to convert user-specified file name to
ASCII-only versions. My current code is:

function asciiOnly(str) {
var buffer = new Buffer(str, "ascii");
return buffer.toString();
}

...but this is not entirely satisfactory. In particular, I'd like to
do preserve meaning through conventional substitutions such as ae for
German ä. Any suggestions?

mscdex

unread,
Apr 29, 2012, 4:41:35 PM4/29/12
to nodejs
On Apr 29, 2:32 pm, "P. Douglas Reeder" <reeder...@gmail.com> wrote:
> ...but this is not entirely satisfactory.  In particular, I'd like to
> do preserve meaning through conventional substitutions such as ae for
> German ä.  Any suggestions?

Your best bet will probably be using the iconv module (https://
github.com/bnoordhuis/node-iconv) with the //TRANSLIT option.

Andrew Weeks

unread,
May 1, 2012, 7:17:56 AM5/1/12
to nod...@googlegroups.com
I used the code here to do this. It's just an array of substitutions, so you can obviously edit it if it doesn't meet your requirements. Clearly it's a lot less powerful than iconv, but it may be sufficient (and it runs on Windows too :). 

Reply all
Reply to author
Forward
0 new messages