@ou-imdt/utils
Version:
Utility library for interactive media development
14 lines • 465 B
JavaScript
/**
* Wraps the given target with tag, either as an element or string depending on target type.
* @param {string} type - The wrapping tag.
* @param {string|Node} target - The target to wrap.
* @returns {string|Node} The wrapped target.
*/
export default function wrapWith(tag, target) {
if (target instanceof Node) {
const wrapper = document.createElement(tag);
wrapper.append(target);
return wrapper;
}
return `<${tag}>${target}</${tag}>`;
}