swup
Version:
Complete, flexible, extensible and easy to use page transition library for your web.
18 lines (16 loc) • 607 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var classify = function classify(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;
};
exports.default = classify;
;