Blame view

node_modules/whet.extend/lib/whet.extend.js 2.46 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
  // Generated by CoffeeScript 1.3.3
  
  /*
   * whet.extend v0.9.7
   * Standalone port of jQuery.extend that actually works on node.js
   * https://github.com/Meettya/whet.extend
   *
   * Copyright 2012, Dmitrii Karpich
   * Released under the MIT License
  */
  
  
  (function() {
    var extend, _findValue, _isClass, _isOwnProp, _isPlainObj, _isPrimitiveType, _isTypeOf, _prepareClone,
      __slice = [].slice;
  
    module.exports = extend = function() {
      var args, copy, deep, name, options, target, _i, _len, _ref;
      deep = arguments[0], target = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
      if (!_isClass(deep, 'Boolean')) {
        args.unshift(target);
        _ref = [deep || {}, false], target = _ref[0], deep = _ref[1];
      }
      if (_isPrimitiveType(target)) {
        target = {};
      }
      for (_i = 0, _len = args.length; _i < _len; _i++) {
        options = args[_i];
        if (options != null) {
          for (name in options) {
            copy = options[name];
            target[name] = _findValue(deep, copy, target[name]);
          }
        }
      }
      return target;
    };
  
    /*
    Internal methods from now
    */
  
  
    _isClass = function(obj, str) {
      return ("[object " + str + "]") === Object.prototype.toString.call(obj);
    };
  
    _isOwnProp = function(obj, prop) {
      return Object.prototype.hasOwnProperty.call(obj, prop);
    };
  
    _isTypeOf = function(obj, str) {
      return str === typeof obj;
    };
  
    _isPlainObj = function(obj) {
      var key;
      if (!obj) {
        return false;
      }
      if (obj.nodeType || obj.setInterval || !_isClass(obj, 'Object')) {
        return false;
      }
      if (obj.constructor && !_isOwnProp(obj, 'constructor') && !_isOwnProp(obj.constructor.prototype, 'isPrototypeOf')) {
        return false;
      }
      for (key in obj) {
        key;
  
      }
      return key === void 0 || _isOwnProp(obj, key);
    };
  
    _isPrimitiveType = function(obj) {
      return !(_isTypeOf(obj, 'object') || _isTypeOf(obj, 'function'));
    };
  
    _prepareClone = function(copy, src) {
      if (_isClass(copy, 'Array')) {
        if (_isClass(src, 'Array')) {
          return src;
        } else {
          return [];
        }
      } else {
        if (_isPlainObj(src)) {
          return src;
        } else {
          return {};
        }
      }
    };
  
    _findValue = function(deep, copy, src) {
      var clone;
      if (deep && (_isClass(copy, 'Array') || _isPlainObj(copy))) {
        clone = _prepareClone(copy, src);
        return extend(deep, clone, copy);
      } else {
        return copy;
      }
    };
  
  }).call(this);