diff --git a/string-prototypes.js b/string-prototypes.js index cfb3681..5cfe294 100644 --- a/string-prototypes.js +++ b/string-prototypes.js @@ -27,3 +27,23 @@ String.prototype.ucwords = function () { }); } + +String.prototype.createSlug = function () { + var str = this; + str = str.replace(/^\s+|\s+$/g, ''); // trim + str = str.toLowerCase(); + + // remove accents, swap ñ for n, etc + var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;"; + var to = "aaaaeeeeiiiioooouuuunc------"; + for (var i=0, l=from.length ; i