heyujie
2021-06-07 8f8155aa4c83f7c2577ac123add550766b6a7ce3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"use strict";
 
var isPrototype = require("../prototype/is");
 
var isArray;
if (typeof Array.isArray === "function") {
    isArray = Array.isArray;
} else {
    var objectToString = Object.prototype.toString, objectTaggedString = objectToString.call([]);
    isArray = function (value) { return objectToString.call(value) === objectTaggedString; };
}
 
module.exports = function (value) {
    if (!isArray(value)) return false;
 
    // Sanity check (reject objects which do not expose common Array interface)
    if (!hasOwnProperty.call(value, "length")) return false;
    try {
        if (typeof value.length !== "number") return false;
        if (typeof value.push !== "function") return false;
        if (typeof value.splice !== "function") return false;
    } catch (error) {
        return false;
    }
 
    return !isPrototype(value);
};