kaguranana-birthday-project/node_modules/granim/lib/getElement.js
2021-12-12 18:49:32 -08:00

18 lines
432 B
JavaScript

'use strict';
module.exports = function(element) {
if (element instanceof HTMLCanvasElement) {
this.canvas = element;
} else if (typeof element === 'string') {
this.canvas = document.querySelector(element);
} else {
throw new Error('The element you used is neither a String, nor a HTMLCanvasElement');
}
if (!this.canvas) {
throw new Error('`' + element + '` could not be found in the DOM');
}
};