-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathutils.js
85 lines (70 loc) · 1.95 KB
/
utils.js
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
import SHA256 from 'crypto-js/sha256';
import _ from 'underscore';
var i = 0;
export function uniqueId() {
return (i++).toString();
}
export function hashPassword(password) {
return {
digest: SHA256(password).toString(), // lgtm [js/insufficient-password-hash]
algorithm: 'sha-256',
};
}
//From Meteor core
var class2type = {};
var toString = class2type.toString;
var hasOwn = class2type.hasOwnProperty;
var support = {};
// Populate the class2type map
_.each(
'Boolean Number String Function Array Date RegExp Object Error'.split(' '),
function(name, i) {
class2type['[object ' + name + ']'] = name.toLowerCase();
}
);
function type(obj) {
if (obj == null) {
return obj + '';
}
return typeof obj === 'object' || typeof obj === 'function'
? class2type[toString.call(obj)] || 'object'
: typeof obj;
}
function isWindow(obj) {
/* jshint eqeqeq: false */
return obj != null && obj == obj.window;
}
export function isPlainObject(obj) {
var key;
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
if (!obj || type(obj) !== 'object' || obj.nodeType || isWindow(obj)) {
return false;
}
try {
// Not own constructor property must be Object
if (
obj.constructor &&
!hasOwn.call(obj, 'constructor') &&
!hasOwn.call(obj.constructor.prototype, 'isPrototypeOf')
) {
return false;
}
} catch (e) {
// IE8,9 Will throw exceptions on certain host objects #9897
return false;
}
// Support: IE<9
// Handle iteration over inherited properties before own properties.
if (support.ownLast) {
for (key in obj) {
return hasOwn.call(obj, key);
}
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
for (key in obj) {
}
return key === undefined || hasOwn.call(obj, key);
}