UNPKG

@ideal-postcodes/jsutil

Version:

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

45 lines (44 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.injectStyle = exports.loadScript = exports.loadStyle = exports.downloadScript = exports.clearCache = void 0; const cache = {}; const clearCache = () => { for (const url of Object.keys(cache)) { delete cache[url]; } }; exports.clearCache = clearCache; const downloadScript = (url, integrity) => (d) => { if (cache[url]) return cache[url]; const document = d || window.document; const script = (0, exports.loadScript)(url, integrity, document); document.head.appendChild(script); cache[url] = script; return script; }; exports.downloadScript = downloadScript; const loadStyle = (href, document) => { const link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = href; return link; }; exports.loadStyle = loadStyle; 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; }; exports.loadScript = loadScript; const injectStyle = (css, document) => { const style = document.createElement("style"); style.appendChild(document.createTextNode(css)); document.head.appendChild(style); return style; }; exports.injectStyle = injectStyle;