-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
28 lines (19 loc) · 835 Bytes
/
helpers.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
"use strict"
exports.isEmptyContent = content => (
content == null ||
content === '' ||
(Array.isArray(content) && !content.length) ||
(typeof content === 'object' && !Object.keys(content).length)
)
const findEl = (key, type, parent) => parent.querySelector(`[data-${type}=${key}]`)
const findEls = (key, type, parent) => parent.querySelectorAll(`[data-${type}=${key}]`)
const findElOrThrow = (key, type, parent) => {
const el = findEl(key, type, parent)
if (!el) {
throw new Error(`No ${type} container found for ${key}. Use data-${type}="${key}"`)
}
return el
}
exports.findTemplateEl = (key, parent) => findElOrThrow(key, 'template', parent)
exports.findContainerEl = (key, parent) => (findEl(key, 'container', parent) || parent)
exports.findConditionalEls = (key, parent) => findEls(key, 'if', parent)