1 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.isEmptyObject = function (obj) {
|
7 | if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') return false;
|
8 | for (var n in obj) {
|
9 | if (obj.hasOwnProperty(n)) {
|
10 | return false;
|
11 | }
|
12 | }
|
13 | return true;
|
14 | };
|
15 |
|
16 |
|
17 |
|
18 | Object.isPlainObject = function (obj) {
|
19 | var proto;
|
20 | var Ctor;
|
21 | if (!obj || toString.call(obj) !== '[object Object]') {
|
22 | return false;
|
23 | }
|
24 |
|
25 | proto = Object.getPrototypeOf(obj);
|
26 |
|
27 |
|
28 | if (!proto) {
|
29 | return true;
|
30 | }
|
31 |
|
32 |
|
33 | Ctor = {}.hasOwnProperty.call(proto, 'constructor') && proto.constructor;
|
34 | return typeof Ctor === 'function' && {}.hasOwnProperty.toString.call(Ctor) === {}.hasOwnProperty.toString.call(Object);
|
35 | };
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | Object.clone = function (obj) {
|
41 | var copy;
|
42 | if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
|
43 | if (obj === null) {
|
44 | copy = null;
|
45 | } else {
|
46 | if (obj instanceof Array) {
|
47 | copy = [];
|
48 | for (var i = 0; i < obj.length; i++) {
|
49 | copy.push(this.clone(obj[i]));
|
50 | }
|
51 | } else {
|
52 | copy = {};
|
53 | for (var j in obj) {
|
54 | copy[j] = this.clone(obj[j]);
|
55 | }
|
56 | }
|
57 | }
|
58 | } else {
|
59 | copy = obj;
|
60 | }
|
61 | return copy;
|
62 | };
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | Object.params = function (obj, splitter, isNotEnCode) {
|
70 | if (!Object.isPlainObject(obj)) return obj;
|
71 | if (obj instanceof Object && obj.length > 0) return '';
|
72 |
|
73 | if (splitter === 'dot') {
|
74 | var arr = [];
|
75 | for (var n in obj) {
|
76 | arr.push(n + '=' + JSON.stringify(obj[n]));
|
77 | }
|
78 | return arr.join('&');
|
79 | }
|
80 |
|
81 | var result = '';
|
82 | function buildParams(obj, prevKey) {
|
83 | for (var key in obj) {
|
84 | if (obj[key] instanceof Object) {
|
85 | var prefix = prevKey ? prevKey + '.' + key : key;
|
86 | buildParams(obj[key], prefix);
|
87 | } else {
|
88 | if (prevKey) {
|
89 |
|
90 | if (splitter !== 'bracket') result += '&' + prevKey + '.' + key + '=' + (isNotEnCode ? obj[key] : encodeURIComponent(obj[key]));
|
91 | if (splitter === 'bracket') result += '&' + prevKey + '[' + key + ']=' + (isNotEnCode ? obj[key] : encodeURIComponent(obj[key]));
|
92 | } else {
|
93 |
|
94 | result += '&' + key + '=' + (isNotEnCode ? obj[key] : encodeURIComponent(obj[key]));
|
95 | }
|
96 | }
|
97 | }
|
98 | return result;
|
99 | }
|
100 | buildParams(obj);
|
101 |
|
102 | if (result) {
|
103 | result = result.slice(1);
|
104 | }
|
105 | return result;
|
106 | };
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | Object.type = function (obj) {
|
124 | if (!obj) {
|
125 | return obj + '';
|
126 | }
|
127 | var type = Object.prototype.toString.call(obj).replace('[', '').replace(']', '').split(' ')[1].toLowerCase();
|
128 | if (type === 'object') {
|
129 | var objStr = JSON.stringify(obj);
|
130 | try {
|
131 | JSON.parse(objStr);
|
132 | return 'json';
|
133 | } catch (e) {}
|
134 | }
|
135 | return type;
|
136 | };
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | Object.charType = function (char) {
|
142 | if (char >= 48 && char <= 57) return 'number';
|
143 | if (char >= 65 && char <= 90) return 'capitalize';
|
144 | if (char >= 97 && char <= 122) return 'lowercase';
|
145 | else return 'other';
|
146 | };
|
147 | Object.passwordLvl = function (value) {
|
148 | var mode = {};
|
149 | for (var i = 0; i < value.length; i++) {
|
150 | mode[Object.charType(value.charCodeAt(i))] = '';
|
151 | }
|
152 | var lvl = 0;
|
153 |
|
154 | for (m in mode) {
|
155 | lvl++;
|
156 | }
|
157 |
|
158 | if (value.length > 0 && value.length < 6) return 1;
|
159 | return lvl;
|
160 | };
|
161 |
|
162 |
|
163 |
|
164 | Object.isFunction = function (obj) {
|
165 | return Object.type(obj) === 'function';
|
166 | };
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | Object.isWindow = function (obj) {
|
172 | return obj != null && obj === obj.window;
|
173 | };
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | Object.extend = function () {
|
179 | var options;
|
180 | var name;
|
181 | var src;
|
182 | var copy;
|
183 | var copyIsArray;
|
184 | var clone;
|
185 | var target = arguments[0] || {};
|
186 | var i = 1;
|
187 | var length = arguments.length;
|
188 | var deep = false;
|
189 |
|
190 |
|
191 | if (typeof target === 'boolean') {
|
192 | deep = target;
|
193 |
|
194 |
|
195 | target = arguments[i] || {};
|
196 | i++;
|
197 | }
|
198 |
|
199 |
|
200 | if ((typeof target === 'undefined' ? 'undefined' : _typeof(target)) !== 'object' && !Object.isFunction(target)) {
|
201 | target = {};
|
202 | }
|
203 |
|
204 |
|
205 | if (i === length) {
|
206 | target = this;
|
207 | i--;
|
208 | }
|
209 |
|
210 | for (; i < length; i++) {
|
211 |
|
212 | options = arguments[i];
|
213 | if (options != null) {
|
214 |
|
215 | for (name in options) {
|
216 | src = target[name];
|
217 | copy = options[name];
|
218 |
|
219 |
|
220 | if (target === copy) {
|
221 | continue;
|
222 | }
|
223 |
|
224 |
|
225 | if (deep && copy && (Object.isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) {
|
226 |
|
227 | if (copyIsArray) {
|
228 | copyIsArray = false;
|
229 | clone = src && Array.isArray(src) ? src : [];
|
230 | } else {
|
231 | clone = src && Object.isPlainObject(src) ? src : {};
|
232 | }
|
233 |
|
234 |
|
235 | target[name] = Object.extend(deep, clone, copy);
|
236 |
|
237 |
|
238 | } else if (copy !== undefined) {
|
239 | target[name] = copy;
|
240 | }
|
241 | }
|
242 | }
|
243 | }
|
244 |
|
245 |
|
246 | return target;
|
247 | };
|
248 |
|
249 |
|
250 |
|
251 | Object.generateGUID = function () {
|
252 | var d = new Date().getTime();
|
253 | var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
254 | var r = (d + Math.random() * 16) % 16 | 0;
|
255 | d = Math.floor(d / 16);
|
256 | return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
257 | });
|
258 | return uuid;
|
259 | };
|
260 |
|
261 |
|
262 |
|
263 | Object.equals = function (object1, object2) {
|
264 |
|
265 |
|
266 | for (var propName in object1) {
|
267 |
|
268 |
|
269 | if (object1.hasOwnProperty(propName) !== object2.hasOwnProperty(propName)) {
|
270 | return false;
|
271 | }
|
272 |
|
273 | else if (_typeof(object1[propName]) !== _typeof(object2[propName])) {
|
274 |
|
275 | return false;
|
276 | }
|
277 | }
|
278 |
|
279 | for (propName in object2) {
|
280 |
|
281 | if (object1.hasOwnProperty(propName) !== object2.hasOwnProperty(propName)) {
|
282 | return false;
|
283 | } else if (_typeof(object1[propName]) !== _typeof(object2[propName])) {
|
284 | return false;
|
285 | }
|
286 |
|
287 | if (!object1.hasOwnProperty(propName)) continue;
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 | if (object1[propName] instanceof Array && object2[propName] instanceof Array) {
|
294 |
|
295 | if (!Object.equals(object1[propName], object2[propName])) return false;
|
296 | } else if (object1[propName] instanceof Object && object2[propName] instanceof Object) {
|
297 |
|
298 |
|
299 | if (!Object.equals(object1[propName], object2[propName])) return false;
|
300 | }
|
301 |
|
302 | else if (object1[propName] !== object2[propName]) {
|
303 | return false;
|
304 | }
|
305 | }
|
306 |
|
307 | return true;
|
308 | };
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 | Object.getArgs = function (e, parameters) {
|
317 | var args = parameters ? Object.clone(parameters) : parameters;
|
318 | if (args !== undefined) {
|
319 | if (typeof args === 'string' && args === '$event') {
|
320 | args = e;
|
321 | } else if (Array.isArray(args) && args.indexOf('$event') > -1) {
|
322 | args[args.indexOf('$event')] = e;
|
323 | }
|
324 | } else {
|
325 | args = e;
|
326 | }
|
327 | return args;
|
328 | }; |
\ | No newline at end of file |