Skip to content

Commit

Permalink
Properly check insertions argument type
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber623 committed Sep 27, 2023
1 parent 3bd434d commit 68d8081
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/templatetemplate.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/**
* @param {(string|HTMLTemplateElement)} template
* @param {Object} insertions
*
* @throws {TypeError} Argument template must be a string or an HTMLTemplateElement.
* @throws {TypeError} Argument insertions must be an Object.
*/
export default function TemplateTemplate(template, insertions = {}) {
template = template instanceof HTMLElement ? template : document.querySelector(template);

if (template === null || !(template instanceof HTMLTemplateElement)) {
throw new TypeError(`${template} is not an HTMLTemplateElement`);
}

if (typeof insertions !== 'object') {
if (typeof insertions !== 'object' || insertions === null || Array.isArray(insertions)) {
throw new TypeError(`${insertions} is not an Object`);
}

Expand Down

0 comments on commit 68d8081

Please sign in to comment.