UNPKG

slugo

Version:

The smallest possible slug utility for Node.js and Browser

19 lines (16 loc) 661 B
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; } export default slugo;