Skip to content

Instantly share code, notes, and snippets.

@franklinjavier
Last active June 2, 2016 20:51
Show Gist options
  • Save franklinjavier/5525063 to your computer and use it in GitHub Desktop.
Save franklinjavier/5525063 to your computer and use it in GitHub Desktop.
slugify.js
'use strict';
module.exports = function(str) {
return (str || '').toLowerCase()
.replace(/[\u00C0-\u00C5]/gi, 'a')
.replace(/[\u00E7]/gi, 'c')
.replace(/[\u00C8-\u00CB]/gi, 'e')
.replace(/[\u00CC-\u00CF]/gi, 'i')
.replace(/[\u00D2-\u00D6]/gi, 'o')
.replace(/[\u00D9-\u00DC]/gi, 'u')
.replace(/[\u00D1]/gi, 'n')
.replace(/[^a-z0-9\s]+/g, '')
.trim().replace(/\s+/g, '-')
.replace(/[\-]{2,}/g, '')
.replace(/[^a-z\-\s]*/gi, '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment