source: imaps-frontend/node_modules/utila/lib/_common.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.4 KB
Line 
1// Generated by CoffeeScript 1.6.3
2var common;
3
4module.exports = common = {
5 /*
6 Checks to see if o is an object, and it isn't an instance
7 of some class.
8 */
9
10 isBareObject: function(o) {
11 if ((o != null) && o.constructor === Object) {
12 return true;
13 }
14 return false;
15 },
16 /*
17 Returns type of an object, including:
18 undefined, null, string, number, array,
19 arguments, element, textnode, whitespace, and object
20 */
21
22 typeOf: function(item) {
23 var _ref;
24 if (item === null) {
25 return 'null';
26 }
27 if (typeof item !== 'object') {
28 return typeof item;
29 }
30 if (Array.isArray(item)) {
31 return 'array';
32 }
33 if (item.nodeName) {
34 if (item.nodeType === 1) {
35 return 'element';
36 }
37 if (item.nodeType === 3) {
38 return (_ref = /\S/.test(item.nodeValue)) != null ? _ref : {
39 'textnode': 'whitespace'
40 };
41 }
42 } else if (typeof item.length === 'number') {
43 if (item.callee) {
44 return 'arguments';
45 }
46 }
47 return typeof item;
48 },
49 clone: function(item, includePrototype) {
50 if (includePrototype == null) {
51 includePrototype = false;
52 }
53 switch (common.typeOf(item)) {
54 case 'array':
55 return common._cloneArray(item, includePrototype);
56 case 'object':
57 return common._cloneObject(item, includePrototype);
58 default:
59 return item;
60 }
61 },
62 /*
63 Deep clone of an object.
64 From MooTools
65 */
66
67 _cloneObject: function(o, includePrototype) {
68 var clone, key;
69 if (includePrototype == null) {
70 includePrototype = false;
71 }
72 if (common.isBareObject(o)) {
73 clone = {};
74 for (key in o) {
75 clone[key] = common.clone(o[key], includePrototype);
76 }
77 return clone;
78 } else {
79 if (!includePrototype) {
80 return o;
81 }
82 if (o instanceof Function) {
83 return o;
84 }
85 clone = Object.create(o.constructor.prototype);
86 for (key in o) {
87 if (o.hasOwnProperty(key)) {
88 clone[key] = common.clone(o[key], includePrototype);
89 }
90 }
91 return clone;
92 }
93 },
94 /*
95 Deep clone of an array.
96 From MooTools
97 */
98
99 _cloneArray: function(a, includePrototype) {
100 var clone, i;
101 if (includePrototype == null) {
102 includePrototype = false;
103 }
104 i = a.length;
105 clone = new Array(i);
106 while (i--) {
107 clone[i] = common.clone(a[i], includePrototype);
108 }
109 return clone;
110 }
111};
Note: See TracBrowser for help on using the repository browser.