slugo
Version:
The smallest possible slug utility for Node.js and Browser
27 lines (22 loc) • 949 B
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.slugo = factory());
}(this, (function () { 'use strict';
function slugo(input) {
return input // Remove html tags
.replace(/<(?:.|\n)*?>/gm, '') // Remove special characters
.replace(/[!\"#$%&'\(\)\*\+,\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, '') // eslint-disable-line no-useless-escape
// Replace dots and spaces with a short dash
.replace(/(\s|\.)/g, '-') // Replace multiple dashes with a single dash
.replace(/-{2,}/g, '-') // Replace long dash with two short dashes
.replace(/—/g, '--') // Make the whole thing lowercase
.toLowerCase();
}
if (typeof module !== 'undefined') {
// For CommonJS default export support
module.exports = slugo;
module.exports.default = slugo;
}
return slugo;
})));