-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.js
55 lines (54 loc) · 1.34 KB
/
util.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
const util = {
uniStr() {
return Date.now().toString(32);
},
assign(target, ...from) {
return Object.assign(target, ...from);
},
createObject() {
return Object.create(null);
},
throwError(msg) {
throw `DragDrop Error: ${msg}`;
},
isString(str) {
return typeof str === 'string';
},
isFunction(fn) {
return typeof fn === 'function';
},
isArray(arr) {
return Array.isArray(arr);
},
isPlainObject(obj) {
const toString = Object.prototype.toString;
return toString.call(obj) === '[object Object]';
},
isHtmlElement(node) {
return node instanceof HTMLElement;
},
capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
},
createEvent(name) {
let evt;
if (window.CustomEvent) {
evt = new CustomEvent(name, {
bubbles: true,
cancelable: true
});
} else {
evt = document.createEvent('Event');
evt.initEvent(name, true, true);
}
return evt;
},
clearSelection() {
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (doc.selection) {
document.selection.empty();
}
}
};
export default util;