(href: string, attributes?: Record<string, string>)
| 4 | * @param attributes - optional attributes to add to the tag |
| 5 | */ |
| 6 | const createLinkInHead = (href: string, attributes?: Record<string, string>) => { |
| 7 | const link = document.createElement("link"); |
| 8 | link.type = "text/css"; |
| 9 | link.rel = "stylesheet"; |
| 10 | |
| 11 | if (attributes) { |
| 12 | Object.entries(attributes).forEach(pair => link.setAttribute(...pair)); |
| 13 | } |
| 14 | |
| 15 | link.href = href; |
| 16 | |
| 17 | document.head.appendChild(link); |
| 18 | |
| 19 | return new Promise<Event>(resolve => { |
| 20 | link.addEventListener("load", resolve); |
| 21 | link.addEventListener("error", resolve); // intended |
| 22 | }); |
| 23 | }; |
| 24 | |
| 25 | export default createLinkInHead; |
no test coverage detected
searching dependent graphs…