Files
js-xss/lib/util.js

35 lines
761 B
JavaScript
Raw Normal View History

2015-03-27 16:09:45 +11:00
module.exports = {
2017-12-21 14:22:34 +08:00
indexOf: function(arr, item) {
2015-03-27 16:09:45 +11:00
var i, j;
if (Array.prototype.indexOf) {
return arr.indexOf(item);
}
for (i = 0, j = arr.length; i < j; i++) {
if (arr[i] === item) {
return i;
}
}
return -1;
},
2017-12-21 14:22:34 +08:00
forEach: function(arr, fn, scope) {
2015-03-27 16:09:45 +11:00
var i, j;
if (Array.prototype.forEach) {
return arr.forEach(fn, scope);
}
for (i = 0, j = arr.length; i < j; i++) {
fn.call(scope, arr[i], i, arr);
}
},
2017-12-21 14:22:34 +08:00
trim: function(str) {
2015-05-06 00:45:28 +08:00
if (String.prototype.trim) {
2015-03-27 16:09:45 +11:00
return str.trim();
}
2017-12-21 14:22:34 +08:00
return str.replace(/(^\s*)|(\s*$)/g, "");
},
2017-12-21 14:22:34 +08:00
spaceIndex: function(str) {
var reg = /\s|\n|\t/;
var match = reg.exec(str);
return match ? match.index : -1;
2015-03-27 16:09:45 +11:00
}
};