Blame view

node_modules/utila/lib/_common.js 2.42 KB
aaac7fed   liuqimichale   add
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  // Generated by CoffeeScript 1.6.3
  var common;
  
  module.exports = common = {
    /*
    	Checks to see if o is an object, and it isn't an instance
    	of some class.
    */
  
    isBareObject: function(o) {
      if ((o != null) && o.constructor === Object) {
        return true;
      }
      return false;
    },
    /*
    	Returns type of an object, including:
    	undefined, null, string, number, array,
    	arguments, element, textnode, whitespace, and object
    */
  
    typeOf: function(item) {
      var _ref;
      if (item === null) {
        return 'null';
      }
      if (typeof item !== 'object') {
        return typeof item;
      }
      if (Array.isArray(item)) {
        return 'array';
      }
      if (item.nodeName) {
        if (item.nodeType === 1) {
          return 'element';
        }
        if (item.nodeType === 3) {
          return (_ref = /\S/.test(item.nodeValue)) != null ? _ref : {
            'textnode': 'whitespace'
          };
        }
      } else if (typeof item.length === 'number') {
        if (item.callee) {
          return 'arguments';
        }
      }
      return typeof item;
    },
    clone: function(item, includePrototype) {
      if (includePrototype == null) {
        includePrototype = false;
      }
      switch (common.typeOf(item)) {
        case 'array':
          return common._cloneArray(item, includePrototype);
        case 'object':
          return common._cloneObject(item, includePrototype);
        default:
          return item;
      }
    },
    /*
    	Deep clone of an object.
    	From MooTools
    */
  
    _cloneObject: function(o, includePrototype) {
      var clone, key;
      if (includePrototype == null) {
        includePrototype = false;
      }
      if (common.isBareObject(o)) {
        clone = {};
        for (key in o) {
          clone[key] = common.clone(o[key], includePrototype);
        }
        return clone;
      } else {
        if (!includePrototype) {
          return o;
        }
        if (o instanceof Function) {
          return o;
        }
        clone = Object.create(o.constructor.prototype);
        for (key in o) {
          if (o.hasOwnProperty(key)) {
            clone[key] = common.clone(o[key], includePrototype);
          }
        }
        return clone;
      }
    },
    /*
    	Deep clone of an array.
    	From MooTools
    */
  
    _cloneArray: function(a, includePrototype) {
      var clone, i;
      if (includePrototype == null) {
        includePrototype = false;
      }
      i = a.length;
      clone = new Array(i);
      while (i--) {
        clone[i] = common.clone(a[i], includePrototype);
      }
      return clone;
    }
  };