(parent: string | Element, before: string, child: Node)
| 26 | </parent> |
| 27 | */ |
| 28 | export const appendBefore = (parent: string | Element, before: string, child: Node): void => { |
| 29 | if (typeof parent === 'string') { |
| 30 | parent = $(parent); |
| 31 | } |
| 32 | |
| 33 | // Select direct children only |
| 34 | const beforeElement = $optional(`:scope > :is(${before})`, parent); |
| 35 | if (beforeElement) { |
| 36 | beforeElement.before(child); |
| 37 | } else { |
| 38 | parent.append(child); |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | export const wrap = (target: Element | ChildNode, wrapper: Element): void => { |
| 43 | target.before(wrapper); |
no test coverage detected