From 1c77aa06e10f44c5d44bcc5318ceeaa4b6b90820 Mon Sep 17 00:00:00 2001 From: Christian James Date: Thu, 13 Aug 2015 18:12:03 -0300 Subject: [PATCH] Update string-prototypes.js --- string-prototypes.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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