-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathstrings.js
More file actions
47 lines (36 loc) · 1.39 KB
/
strings.js
File metadata and controls
47 lines (36 loc) · 1.39 KB
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
export const camelToDash = (camelString = "") =>
camelString.replace(/([A-Z])/g, ($1) =>
"-"+$1.toLowerCase())
export const nodeKey = node => {
let tree = []
let furthest_leaf = node
while (furthest_leaf) {
tree.push(furthest_leaf)
furthest_leaf = furthest_leaf.parentNode
? furthest_leaf.parentNode
: false
}
return tree.reduce((path, branch) => `
${path}${branch.tagName}_${branch.className}_${[...node.parentNode.children].indexOf(node)}_${node.children.length}
`, '')
}
export const createClassname = (el, ellipse = false) => {
if (!el.className) return ''
const combined = Array.from(el.classList).reduce((classnames, classname) =>
classnames += '.' + escapeSpecialCharacters(classname)
, '')
return ellipse && combined.length > 30
? combined.substring(0,30) + '...'
: combined
}
const escapeSpecialCharacters = (query) =>
Array.from(query)
.map((char) => /[0-9a-zA-Z_\s-]/.test(char) ? char : `\\${char}`)
.join("")
export const metaKey = window.navigator.platform.includes('Mac')
? 'cmd'
: 'ctrl'
export const altKey = window.navigator.platform.includes('Mac')
? 'opt'
: 'alt'
export const notList = ':not(vis-bug):not(script):not(hotkey-map):not(.visbug-metatip):not(visbug-label):not(visbug-handles):not(visbug-corners):not(visbug-grip):not(visbug-gridlines):not(.moveable-control):not(visbug-moveable-delete-button)'