PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/server/node_modules/rewire/test/shims.js

https://github.com/debdayal/TestApp
JavaScript | 48 lines | 42 code | 3 blank | 3 comment | 21 complexity | d0de25ee988fc8c4733cec5509285f55 MD5 | raw file
 1// Taken from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf#Compatibility
 2if (!Array.prototype.indexOf) {
 3    Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
 4        "use strict";
 5        if (this == null) {
 6            throw new TypeError();
 7        }
 8        var t = Object(this);
 9        var len = t.length >>> 0;
10        if (len === 0) {
11            return -1;
12        }
13        var n = 0;
14        if (arguments.length > 0) {
15            n = Number(arguments[1]);
16            if (n != n) { // shortcut for verifying if it's NaN
17                n = 0;
18            } else if (n != 0 && n != Infinity && n != -Infinity) {
19                n = (n > 0 || -1) * Math.floor(Math.abs(n));
20            }
21        }
22        if (n >= len) {
23            return -1;
24        }
25        var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
26        for (; k < len; k++) {
27            if (k in t && t[k] === searchElement) {
28                return k;
29            }
30        }
31        return -1;
32    };
33}
34
35
36// Taken from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/trim#Compatibility
37if(!String.prototype.trim) {
38  String.prototype.trim = function () {
39    return this.replace(/^\s+|\s+$/g,'');
40  };
41}
42
43// Taken from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray#Compatibility
44if(!Array.isArray) {
45  Array.isArray = function (vArg) {
46    return Object.prototype.toString.call(vArg) === "[object Array]";
47  };
48}