UNPKG

@ideal-postcodes/jsutil

Version:

Browser Address Autocomplete for api.ideal-postcodes.co.uk

37 lines (36 loc) 1.09 kB
const cache = {}; export const clearCache = () => { for (const url of Object.keys(cache)) { delete cache[url]; } }; export const downloadScript = (url, integrity) => (d) => { if (cache[url]) return cache[url]; const document = d || window.document; const script = loadScript(url, integrity, document); document.head.appendChild(script); cache[url] = script; return script; }; export const loadStyle = (href, document) => { const link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = href; return link; }; export const loadScript = (src, integrity, document) => { const script = document.createElement("script"); script.type = "text/javascript"; script.crossOrigin = "anonymous"; script.integrity = integrity; script.src = src; return script; }; export const injectStyle = (css, document) => { const style = document.createElement("style"); style.appendChild(document.createTextNode(css)); document.head.appendChild(style); return style; };