@web3r/flowerkit
Version:
Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).
23 lines (22 loc) • 990 B
text/typescript
export type TGetElWrapperArgs = Parameters<typeof getElWrapper>;
export type TGetElWrapperReturn = ReturnType<typeof getElWrapper>;
/**
* Gets a wrapper for specific element
* @param el{HTMLElement} DOM element
* @param str{String} string of wrapper HTML layout (supports nested blocks)
* @returns {HTMLElement}
* @throws {TypeError} getElWrapper: el must be an HTMLElement
* @throws {TypeError} getElWrapper: str must be a non-empty string
* @example
* // How to wrap content to the few nested `div` blocks?
* // <div id="block">My Element</div>
* const wrapperLayout = `
* <div class="wrapper">
* <div class="wrapper__inner"></div>
* </div>
* `;
* const el = document.getElementById("block");
* const wrapped = getElWrapper(el, wrapperLayout);
* console.log(wrapped.outerHTML); // => `<div class="wrapper"><div class="wrapper__inner"><div id="block">My Element</div></div></div>`
*/
export declare const getElWrapper: (el: HTMLElement, str: string) => HTMLElement;