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