-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
47 lines (44 loc) · 1.12 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
function setPropEntry(def, key, value) {
let exists = false
def.some(entry => {
if (entry.key === key) {
exists = true
entry.value = value
return true
}
})
if (!exists) {
def.push({ key: key, value: value })
}
}
function addAnnotations(props, values) {
const propEntry = props.find(entry => entry.key === `'@'`)
if (propEntry) {
if (propEntry.value.length === 0) {
propEntry.value = `['${values.join('\', \'')}']`
} else {
values.forEach(value => {
if (!propEntry.value.includes(value)) {
propEntry.value = propEntry.value.substring(0, propEntry.value.length - 1) + ',\'' + value + '\']'
}
})
}
} else {
setPropEntry(props, `'@'`, `['${values.join('\', \'')}']`)
}
}
function hasAnnotation(props, value) {
const propEntry = props.find(entry => entry.key === `'@'`)
if (!propEntry) {
return false
}
if (propEntry.value.length === 0) {
return false
}
return propEntry.value.includes(value)
}
module.exports = {
setPropEntry: setPropEntry,
addAnnotations: addAnnotations,
hasAnnotation: hasAnnotation
}