Dirify Function in Javascript

Was messing around with JavaScript and jQuery and needed a dirify function… found one in the Movable Type core JavaScript file. Thought I’d post it here for the value of all vis-à-vis Google as the first results weren’t as useful as I hope this is.

And I added two features to the default code in MT:

I like to use ampersands in my titles because they look spiffy, so I added ampersands to the dirify_table such that “&” is now dirified to “and”.

dirify("Me & Ed's Pizza");
// result: me_and_eds_pizza

Sometimes you want dashes instead of underscores. This dirify function takes a second parameter that is the default separator.