1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | Object.type = function (obj) {
|
12 | return typeof obj;
|
13 | };
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | Object.rawType = function (obj) {
|
21 | return Object.prototype.toString.call(obj).slice(8, -1);
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | Object.isObject = function (obj) {
|
30 | return obj !== null && typeof obj === "object";
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | Object.isPlainObject = function (obj) {
|
39 | return Object.prototype.toString.call(obj) === "[object Object]";
|
40 | };
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | Object.isMap = function (obj) {
|
48 | return Object.prototype.toString.call(obj) === "[object Map]";
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | Object.isSet = function (obj) {
|
57 | return Object.prototype.toString.call(obj) === "[object Set]";
|
58 | };
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | Object.isFunction = function (obj) {
|
66 | return Object.type(obj) === "function";
|
67 | };
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | Object.isSymbol = function (obj) {
|
75 | if (typeof obj === "symbol") {
|
76 | return true;
|
77 | }
|
78 | try {
|
79 | var toString_1 = Symbol.prototype.toString;
|
80 | if (typeof obj.valueOf() !== "symbol") {
|
81 | return false;
|
82 | }
|
83 | return /^Symbol\(.*\)$/.test(toString_1.call(obj));
|
84 | }
|
85 | catch (e) {
|
86 | return false;
|
87 | }
|
88 | };
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | Object.isPromise = function (obj) {
|
96 | return Object.isUndefinedOrNull(obj) === false && Object.isFunction(obj.then) && Object.isFunction(obj.catch);
|
97 | };
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | Object.isPrimitive = function (obj) {
|
105 | return Object.isBoolean(obj) || Object.isString(obj) || Object.isNumber(obj);
|
106 | };
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | Object.isArray = function (obj) {
|
114 | return Array.isArray(obj);
|
115 | };
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | Object.isString = function (obj) {
|
123 | return Object.type(obj) === "string";
|
124 | };
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | Object.isNumber = function (obj) {
|
132 | return Object.type(obj) === "number";
|
133 | };
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | Object.isBoolean = function (obj) {
|
141 | return Object.type(obj) === "boolean";
|
142 | };
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | Object.isRegExp = function (obj) {
|
150 | return Object.rawType(obj) === 'RegExp';
|
151 | };
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | Object.isFile = function (obj) {
|
159 | return obj instanceof File;
|
160 | };
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | Object.isWindow = function (obj) {
|
168 | return Object.isUndefinedOrNull(obj) && obj == obj.window;
|
169 | };
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | Object.isElement = function (obj) {
|
177 | if (Object.isUndefinedOrNull(obj)) {
|
178 | return false;
|
179 | }
|
180 | return !!(obj.nodeType == 1);
|
181 | };
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | Object.isEvent = function (obj) {
|
189 | return obj instanceof Event;
|
190 | };
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 | Object.isNull = function (obj) {
|
198 | return obj === null;
|
199 | };
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | Object.isUndefined = function (obj) {
|
207 | return obj === undefined;
|
208 | };
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | Object.isUndefinedOrNull = function (obj) {
|
216 | return Object.isUndefined(obj) || Object.isNull(obj);
|
217 | };
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | Object.equals = function (obj1, obj2) {
|
226 | if (obj1 === obj2) {
|
227 | return true;
|
228 | }
|
229 | else if (!(obj1 instanceof Object) || !(obj2 instanceof Object)) {
|
230 | return false;
|
231 | }
|
232 | else if (obj1.constructor !== obj2.constructor) {
|
233 | return false;
|
234 | }
|
235 | else if (Object.isArray(obj1) && Object.isArray(obj2) && obj1.length === obj2.length) {
|
236 | for (var i = 0; i < obj1.length; i++) {
|
237 | if (Object.equals(obj1[i], obj2[i]) === false) {
|
238 | return false;
|
239 | }
|
240 | }
|
241 | }
|
242 | else if (Object.isObject(obj1) && Object.isObject(obj2) && Object.keys(obj1).length === Object.keys(obj2).length) {
|
243 | for (var key in obj1) {
|
244 | if (obj1.hasOwnProperty.call(key)) {
|
245 | if (Object.equals(obj1[key], obj2[key]) === false) {
|
246 | return false;
|
247 | }
|
248 | }
|
249 | }
|
250 | }
|
251 | else {
|
252 | return false;
|
253 | }
|
254 | return true;
|
255 | };
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 | Object.clone = function (obj) {
|
263 | if (Object.isString(obj)) {
|
264 | return String(obj);
|
265 | }
|
266 | else if (Object.isArray(obj)) {
|
267 | return Array.prototype.slice.apply(obj);
|
268 | }
|
269 | else if (Object.isPlainObject(obj)) {
|
270 | var result_1 = Object.create(null);
|
271 | Object.keys(obj).forEach(function (key) {
|
272 | result_1[key] = Object.clone(obj[key]);
|
273 | });
|
274 | return result_1;
|
275 | }
|
276 | return obj;
|
277 | };
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 | Object.omit = function (obj) {
|
286 | var fields = [];
|
287 | for (var _i = 1; _i < arguments.length; _i++) {
|
288 | fields[_i - 1] = arguments[_i];
|
289 | }
|
290 | var result = Object.clone(obj);
|
291 | for (var i = 0; i < fields.length; i++) {
|
292 | var key = fields[i];
|
293 | delete result[key];
|
294 | }
|
295 | return result;
|
296 | };
|
297 |
|
\ | No newline at end of file |