import "core-js" ; import { assignIn } from "lodash" ; export interface LinkState { hasLoaded : boolean ; wasRejected : boolean ; error ? : any ; link : HTMLLinkElement ; } type { Map < string , LinkState > } const loadedLinks = new Map < string , LinkState > ( ) ; param name { string } param url { string } export function getLink ( url , name ) { if ( ! loadedLinks . has ( name ) && ! document . querySelector ( `link[href="${ url }"]` ) ) { const link = document . createElement ( "link" ) ; const body = document . getElementsByTagName ( "body" ) [ 0 ] ; assignIn ( link , { href : url , rel : "stylesheet" , type : "text/css" , } ) ; body . appendChild ( link ) ; const linkObject = { hasLoaded : false , link , wasRejected : false , } ; loadedLinks . set ( name , linkObject ) ; } return loadedLinks . get ( name ) ; } export default getLink ;