UNPKG

761 BJavaScriptView Raw
1module.exports = {
2 indexOf: function(arr, item) {
3 var i, j;
4 if (Array.prototype.indexOf) {
5 return arr.indexOf(item);
6 }
7 for (i = 0, j = arr.length; i < j; i++) {
8 if (arr[i] === item) {
9 return i;
10 }
11 }
12 return -1;
13 },
14 forEach: function(arr, fn, scope) {
15 var i, j;
16 if (Array.prototype.forEach) {
17 return arr.forEach(fn, scope);
18 }
19 for (i = 0, j = arr.length; i < j; i++) {
20 fn.call(scope, arr[i], i, arr);
21 }
22 },
23 trim: function(str) {
24 if (String.prototype.trim) {
25 return str.trim();
26 }
27 return str.replace(/(^\s*)|(\s*$)/g, "");
28 },
29 spaceIndex: function(str) {
30 var reg = /\s|\n|\t/;
31 var match = reg.exec(str);
32 return match ? match.index : -1;
33 }
34};