Skip to content

Commit

Permalink
Removed forEach function call to improve compatibility with older bro…
Browse files Browse the repository at this point in the history
…wsers (< IE8)
  • Loading branch information
prozacgod committed Mar 17, 2015
1 parent 380967a commit 4936396
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ function slug(string, opts) {
opts = {replacement:opts};
opts.mode = opts.mode || slug.defaults.mode;
var defaults = slug.defaults.modes[opts.mode];
['replacement','multicharmap','charmap','remove'].forEach(function (key) {
opts[key] = opts[key] || defaults[key];
});

opts['replacement'] = opts['replacement'] || defaults['replacement'];
opts['multicharmap'] = opts['multicharmap'] || defaults['multicharmap'];
opts['charmap'] = opts['charmap'] || defaults['charmap'];
opts['remove'] = opts['remove'] || defaults['remove'];

if ('undefined' === typeof opts.symbols)
opts.symbols = defaults.symbols;

var lengths = [];
Object.keys(opts.multicharmap).forEach(function (key) {
for (var key in opts.multicharmap) {
if (!opts.multicharmap.hasOwnProperty(key))
continue;

var len = key.length;
if (lengths.indexOf(len) === -1)
lengths.push(len);
});
}

var code, unicode, result = "";
for (var char, i = 0, l = string.length; i < l; i++) { char = string[i];
if (!lengths.some(function (len) {
Expand Down Expand Up @@ -161,18 +169,25 @@ slug.defaults.modes = {

if (typeof define !== 'undefined' && define.amd) { // AMD
// dont load symbols table in the browser
Object.keys(slug.defaults.modes).forEach(function (key) {

for (var key in slug.defaults.modes) {
if (!slug.defaults.modes.hasOwnProperty(key))
continue;

slug.defaults.modes[key].symbols = false;
});
}
define([], function () {return slug});
} else if (typeof module !== 'undefined' && module.exports) { // CommonJS
symbols(); // preload symbols table
module.exports = slug;
} else { // Script tag
// dont load symbols table in the browser
Object.keys(slug.defaults.modes).forEach(function (key) {
for (var key in slug.defaults.modes) {
if (!slug.defaults.modes.hasOwnProperty(key))
continue;

slug.defaults.modes[key].symbols = false;
});
}
root.slug = slug;
}

Expand Down

0 comments on commit 4936396

Please sign in to comment.