forked from zack24q/vue-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
43 lines (40 loc) · 1.02 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
export function genKey() {
// const t = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
const t = 'xxxxxxxx'
return t.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0
const v = c === 'x' ? r : (r & 0x3 | 0x8)
return v.toString(16)
})
}
export function getKey(route, keyName) {
return `${route.name || route.path}?${route.query[keyName]}`
}
export function matches(pattern, name) {
if (Array.isArray(pattern)) {
return pattern.indexOf(name) > -1
} else if (typeof pattern === 'string') {
return pattern.split(',').indexOf(name) > -1
} else if (isRegExp(pattern)) {
return pattern.test(name)
}
return false
}
export function isObjEqual(obj1, obj2) {
if (obj1 === obj2) {
return true
}
else {
const keys1 = Object.getOwnPropertyNames(obj1)
const keys2 = Object.getOwnPropertyNames(obj2)
if (keys1.length !== keys2.length) {
return false
}
for (const key of keys1) {
if (obj1[key] !== obj2[key]) {
return false
}
}
return true
}
}