swup
Version:
Complete, flexible, extensible and easy to use page transition library for your web.
13 lines (12 loc) • 533 B
JavaScript
module.exports = function (text) {
var output = text.toString().toLowerCase().replace(/\s+/g, '-') // Replace spaces with -
.replace(/\//g, '-') // Replace / with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
if (output[0] == "/") output = output.splice(1);
if (output == '') output = 'homepage';
return output;
};
;