UNPKG

@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).

1 lines 1.22 kB
{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TRemoveChildNodesArgs = Parameters<typeof removeChildNodes>;\r\n\r\nexport type TRemoveChildNodesReturn = ReturnType<typeof removeChildNodes>;\r\n\r\n/**\r\n * Removes all child nodes of given node\r\n * @param el{Node} node\r\n * @throws {TypeError} removeChildNodes: el must be a Node\r\n * @example\r\n * // How to remove all child elements of a DOM node?\r\n * // <div id=\"myBlock\"><div>Block with child nodes</div></div>\r\n * const myDiv = document.getElementById(\"myBlock\");\r\n * removeChildNodes(myDiv);\r\n * console.log(Array.from(myDiv.children).length); // => 0\r\n */\r\nexport const removeChildNodes = (el: Node): void => {\r\n if (!el || typeof (el as any).nodeType !== \"number\") {\r\n throw new TypeError(\"removeChildNodes: el must be a Node\");\r\n }\r\n while ((el as any).firstChild) {\r\n (el as any).removeChild((el as any).lastChild as ChildNode);\r\n }\r\n};\r\n"],"names":["removeChildNodes","el","nodeType","TypeError","firstChild","removeChild","lastChild"],"mappings":";;;;;;;;;;;GAeO,MAAMA,iBAAoBC,KAC/B,IAAKA,WAAcA,GAAWC,WAAa,SACzC,MAAM,IAAIC,UAAU,uCAEtB,MAAQF,GAAWG,WAChBH,GAAWI,YAAaJ,GAAWK"}