@fastkit/helpers
Advanced tools
Comparing version 0.7.28 to 0.7.29
@@ -477,2 +477,3 @@ 'use strict'; | ||
const IN_DOCUMENT = typeof document !== 'undefined'; | ||
function isFocusable(element) { | ||
@@ -521,2 +522,3 @@ if (element.tabIndex > 0 || | ||
} | ||
function pushDynamicStyle(styleContent) { | ||
@@ -529,2 +531,36 @@ if (!IN_WINDOW) | ||
} | ||
function loadScript(src, attrs, parentNode) { | ||
return new Promise((resolve, reject) => { | ||
const script = document.createElement('script'); | ||
if (attrs) { | ||
for (const attr in attrs) { | ||
script.setAttribute(attr, attrs[attr]); | ||
} | ||
} | ||
script.onload = () => { | ||
script.onerror = script.onload = null; | ||
resolve(script); | ||
}; | ||
script.onerror = () => { | ||
script.onerror = script.onload = null; | ||
reject(new Error(`Failed to load ${src}`)); | ||
}; | ||
script.async = true; | ||
script.src = src; | ||
const node = parentNode || document.head || document.getElementsByTagName('head')[0]; | ||
node.appendChild(script); | ||
}); | ||
} | ||
const _ensureScriptMap = {}; | ||
function ensureScript(src) { | ||
if (!_ensureScriptMap[src]) { | ||
_ensureScriptMap[src] = loadScript(src).catch((err) => { | ||
delete _ensureScriptMap[src]; | ||
throw err; | ||
}); | ||
} | ||
return _ensureScriptMap[src]; | ||
} | ||
function addTransitionEvent(type, el, handler, opts) { | ||
@@ -582,2 +618,3 @@ const types = Array.isArray(type) ? type : [type]; | ||
} | ||
function ownerDocument(node) { | ||
@@ -867,2 +904,3 @@ return (node && node.ownerDocument) || document; | ||
exports.deepmerge = deepmerge; | ||
exports.ensureScript = ensureScript; | ||
exports.escapeRegExp = escapeRegExp; | ||
@@ -887,2 +925,3 @@ exports.flattenComparatorCondition = flattenComparatorCondition; | ||
exports.isString = isString; | ||
exports.loadScript = loadScript; | ||
exports.mergeDefaults = mergeDefaults; | ||
@@ -889,0 +928,0 @@ exports.mergeObject = mergeObject; |
@@ -477,2 +477,3 @@ 'use strict'; | ||
const IN_DOCUMENT = typeof document !== 'undefined'; | ||
function isFocusable(element) { | ||
@@ -521,2 +522,3 @@ if (element.tabIndex > 0 || | ||
} | ||
function pushDynamicStyle(styleContent) { | ||
@@ -529,2 +531,36 @@ if (!IN_WINDOW) | ||
} | ||
function loadScript(src, attrs, parentNode) { | ||
return new Promise((resolve, reject) => { | ||
const script = document.createElement('script'); | ||
if (attrs) { | ||
for (const attr in attrs) { | ||
script.setAttribute(attr, attrs[attr]); | ||
} | ||
} | ||
script.onload = () => { | ||
script.onerror = script.onload = null; | ||
resolve(script); | ||
}; | ||
script.onerror = () => { | ||
script.onerror = script.onload = null; | ||
reject(new Error(`Failed to load ${src}`)); | ||
}; | ||
script.async = true; | ||
script.src = src; | ||
const node = parentNode || document.head || document.getElementsByTagName('head')[0]; | ||
node.appendChild(script); | ||
}); | ||
} | ||
const _ensureScriptMap = {}; | ||
function ensureScript(src) { | ||
if (!_ensureScriptMap[src]) { | ||
_ensureScriptMap[src] = loadScript(src).catch((err) => { | ||
delete _ensureScriptMap[src]; | ||
throw err; | ||
}); | ||
} | ||
return _ensureScriptMap[src]; | ||
} | ||
function addTransitionEvent(type, el, handler, opts) { | ||
@@ -582,2 +618,3 @@ const types = Array.isArray(type) ? type : [type]; | ||
} | ||
function ownerDocument(node) { | ||
@@ -867,2 +904,3 @@ return (node && node.ownerDocument) || document; | ||
exports.deepmerge = deepmerge; | ||
exports.ensureScript = ensureScript; | ||
exports.escapeRegExp = escapeRegExp; | ||
@@ -887,2 +925,3 @@ exports.flattenComparatorCondition = flattenComparatorCondition; | ||
exports.isString = isString; | ||
exports.loadScript = loadScript; | ||
exports.mergeDefaults = mergeDefaults; | ||
@@ -889,0 +928,0 @@ exports.mergeObject = mergeObject; |
@@ -132,2 +132,4 @@ /// <reference types="node" /> | ||
export declare function ensureScript(src: string): Promise<HTMLScriptElement>; | ||
/** Escapes regular expression control chars */ | ||
@@ -225,2 +227,12 @@ export declare function escapeRegExp(str: string): string; | ||
export declare function loadScript(src: string, attrs?: LoadScriptAttrs | null, parentNode?: Node): Promise<HTMLScriptElement>; | ||
export declare interface LoadScriptAttrs { | ||
crossorigin?: 'anonymous' | 'use-credentials' | ''; | ||
integrity?: string; | ||
nomodule?: boolean; | ||
nonce?: string; | ||
type?: string; | ||
} | ||
export declare function mergeDefaults<T>(base: T, scheme: DefaultsScheme<T>): T; | ||
@@ -227,0 +239,0 @@ |
{ | ||
"name": "@fastkit/helpers", | ||
"version": "0.7.28", | ||
"version": "0.7.29", | ||
"description": "@fastkit/helpers", | ||
@@ -5,0 +5,0 @@ "buildOptions": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105010
2941