Skip to content

Commit ec23e34

Browse files
author
vvo
committed
fix: strict container check
1 parent 5916e4f commit ec23e34

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/utils.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
var isString = require('lodash/lang/isString');
2-
3-
function getContainerNode(value) {
4-
if (isString(value)) {
5-
return document.querySelector(value);
1+
function getContainerNode(selectorOrHTMLElement) {
2+
if (typeof selectorOrHTMLElement === 'string') {
3+
return document.querySelector(selectorOrHTMLElement);
4+
} else if (!isDomElement(selectorOrHTMLElement)) {
5+
throw new Error('Container must be `string` or `HTMLElement`');
66
}
7-
return value;
7+
8+
return selectorOrHTMLElement;
9+
}
10+
11+
function isDomElement(o) {
12+
return o instanceof HTMLElement || o && o.nodeType > 0;
813
}
914

1015
function renderTemplate(template, data) {

0 commit comments

Comments
 (0)