2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-07 15:44:05 +00:00

Clean up code for IconifyPreload and IconifyProviders

This commit is contained in:
Vjacheslav Trushkin 2021-05-13 22:33:33 +03:00
parent 3f6265fdac
commit 7214c077b4
6 changed files with 50 additions and 98 deletions

View File

@ -211,18 +211,14 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
// addFinder(iconifyIconFinder); // addFinder(iconifyIconFinder);
addFinder(iconifyFinder); addFinder(iconifyFinder);
const _window = window; interface WindowWithIconifyStuff {
IconifyPreload?: IconifyJSON[] | IconifyJSON;
}
const _window = window as WindowWithIconifyStuff;
// Load icons from global "IconifyPreload" // Load icons from global "IconifyPreload"
interface WindowWithIconifyPreload { if (_window.IconifyPreload !== void 0) {
IconifyPreload: IconifyJSON[] | IconifyJSON; const preload = _window.IconifyPreload;
}
if (
(_window as unknown as WindowWithIconifyPreload).IconifyPreload !==
void 0
) {
const preload = (_window as unknown as WindowWithIconifyPreload)
.IconifyPreload;
const err = 'Invalid IconifyPreload syntax.'; const err = 'Invalid IconifyPreload syntax.';
if (typeof preload === 'object' && preload !== null) { if (typeof preload === 'object' && preload !== null) {
(preload instanceof Array ? preload : [preload]).forEach((item) => { (preload instanceof Array ? preload : [preload]).forEach((item) => {

View File

@ -130,10 +130,10 @@ const browserCacheFunctions: IconifyBrowserCacheFunctions = {
/** /**
* Global variable * Global variable
*/ */
const Iconify = ({ const Iconify = {
// Exposed internal API functions // Exposed internal API functions
_api: APIInternalFunctions, _api: APIInternalFunctions,
} as unknown) as IconifyGlobal; } as unknown as IconifyGlobal;
// Add functions // Add functions
[ [
@ -188,18 +188,14 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
coreModules.cache = storeCache; coreModules.cache = storeCache;
loadCache(); loadCache();
const _window = window; interface WindowWithIconifyStuff {
IconifyProviders?: Record<string, PartialIconifyAPIConfig>;
}
const _window = window as WindowWithIconifyStuff;
// Set API from global "IconifyProviders" // Set API from global "IconifyProviders"
interface WindowWithIconifyProviders { if (_window.IconifyProviders !== void 0) {
IconifyProviders: Record<string, PartialIconifyAPIConfig>; const providers = _window.IconifyProviders;
}
if (
((_window as unknown) as WindowWithIconifyProviders)
.IconifyProviders !== void 0
) {
const providers = ((_window as unknown) as WindowWithIconifyProviders)
.IconifyProviders;
if (typeof providers === 'object' && providers !== null) { if (typeof providers === 'object' && providers !== null) {
for (let key in providers) { for (let key in providers) {
const err = 'IconifyProviders[' + key + '] is invalid.'; const err = 'IconifyProviders[' + key + '] is invalid.';

View File

@ -233,18 +233,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
coreModules.cache = storeCache; coreModules.cache = storeCache;
loadCache(); loadCache();
const _window = window; interface WindowWithIconifyStuff {
IconifyPreload?: IconifyJSON[] | IconifyJSON;
IconifyProviders?: Record<string, PartialIconifyAPIConfig>;
}
const _window = window as WindowWithIconifyStuff;
// Load icons from global "IconifyPreload" // Load icons from global "IconifyPreload"
interface WindowWithIconifyPreload { if (_window.IconifyPreload !== void 0) {
IconifyPreload: IconifyJSON[] | IconifyJSON; const preload = _window.IconifyPreload;
}
if (
(_window as unknown as WindowWithIconifyPreload).IconifyPreload !==
void 0
) {
const preload = (_window as unknown as WindowWithIconifyPreload)
.IconifyPreload;
const err = 'Invalid IconifyPreload syntax.'; const err = 'Invalid IconifyPreload syntax.';
if (typeof preload === 'object' && preload !== null) { if (typeof preload === 'object' && preload !== null) {
(preload instanceof Array ? preload : [preload]).forEach((item) => { (preload instanceof Array ? preload : [preload]).forEach((item) => {
@ -270,15 +267,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
} }
// Set API from global "IconifyProviders" // Set API from global "IconifyProviders"
interface WindowWithIconifyProviders { if (_window.IconifyProviders !== void 0) {
IconifyProviders: Record<string, PartialIconifyAPIConfig>; const providers = _window.IconifyProviders;
}
if (
(_window as unknown as WindowWithIconifyProviders).IconifyProviders !==
void 0
) {
const providers = (_window as unknown as WindowWithIconifyProviders)
.IconifyProviders;
if (typeof providers === 'object' && providers !== null) { if (typeof providers === 'object' && providers !== null) {
for (let key in providers) { for (let key in providers) {
const err = 'IconifyProviders[' + key + '] is invalid.'; const err = 'IconifyProviders[' + key + '] is invalid.';

View File

@ -229,18 +229,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
coreModules.cache = storeCache; coreModules.cache = storeCache;
loadCache(); loadCache();
const _window = window; interface WindowWithIconifyStuff {
IconifyPreload?: IconifyJSON[] | IconifyJSON;
IconifyProviders?: Record<string, PartialIconifyAPIConfig>;
}
const _window = window as WindowWithIconifyStuff;
// Load icons from global "IconifyPreload" // Load icons from global "IconifyPreload"
interface WindowWithIconifyPreload { if (_window.IconifyPreload !== void 0) {
IconifyPreload: IconifyJSON[] | IconifyJSON; const preload = _window.IconifyPreload;
}
if (
(_window as unknown as WindowWithIconifyPreload).IconifyPreload !==
void 0
) {
const preload = (_window as unknown as WindowWithIconifyPreload)
.IconifyPreload;
const err = 'Invalid IconifyPreload syntax.'; const err = 'Invalid IconifyPreload syntax.';
if (typeof preload === 'object' && preload !== null) { if (typeof preload === 'object' && preload !== null) {
(preload instanceof Array ? preload : [preload]).forEach((item) => { (preload instanceof Array ? preload : [preload]).forEach((item) => {
@ -266,15 +263,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
} }
// Set API from global "IconifyProviders" // Set API from global "IconifyProviders"
interface WindowWithIconifyProviders { if (_window.IconifyProviders !== void 0) {
IconifyProviders: Record<string, PartialIconifyAPIConfig>; const providers = _window.IconifyProviders;
}
if (
(_window as unknown as WindowWithIconifyProviders).IconifyProviders !==
void 0
) {
const providers = (_window as unknown as WindowWithIconifyProviders)
.IconifyProviders;
if (typeof providers === 'object' && providers !== null) { if (typeof providers === 'object' && providers !== null) {
for (let key in providers) { for (let key in providers) {
const err = 'IconifyProviders[' + key + '] is invalid.'; const err = 'IconifyProviders[' + key + '] is invalid.';

View File

@ -241,18 +241,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
coreModules.cache = storeCache; coreModules.cache = storeCache;
loadCache(); loadCache();
const _window = window; interface WindowWithIconifyStuff {
IconifyPreload?: IconifyJSON[] | IconifyJSON;
IconifyProviders?: Record<string, PartialIconifyAPIConfig>;
}
const _window = window as WindowWithIconifyStuff;
// Load icons from global "IconifyPreload" // Load icons from global "IconifyPreload"
interface WindowWithIconifyPreload { if (_window.IconifyPreload !== void 0) {
IconifyPreload: IconifyJSON[] | IconifyJSON; const preload = _window.IconifyPreload;
}
if (
((_window as unknown) as WindowWithIconifyPreload).IconifyPreload !==
void 0
) {
const preload = ((_window as unknown) as WindowWithIconifyPreload)
.IconifyPreload;
const err = 'Invalid IconifyPreload syntax.'; const err = 'Invalid IconifyPreload syntax.';
if (typeof preload === 'object' && preload !== null) { if (typeof preload === 'object' && preload !== null) {
(preload instanceof Array ? preload : [preload]).forEach(item => { (preload instanceof Array ? preload : [preload]).forEach(item => {
@ -278,15 +275,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
} }
// Set API from global "IconifyProviders" // Set API from global "IconifyProviders"
interface WindowWithIconifyProviders { if (_window.IconifyProviders !== void 0) {
IconifyProviders: Record<string, PartialIconifyAPIConfig>; const providers = _window.IconifyProviders;
}
if (
((_window as unknown) as WindowWithIconifyProviders)
.IconifyProviders !== void 0
) {
const providers = ((_window as unknown) as WindowWithIconifyProviders)
.IconifyProviders;
if (typeof providers === 'object' && providers !== null) { if (typeof providers === 'object' && providers !== null) {
for (let key in providers) { for (let key in providers) {
const err = 'IconifyProviders[' + key + '] is invalid.'; const err = 'IconifyProviders[' + key + '] is invalid.';

View File

@ -233,18 +233,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
coreModules.cache = storeCache; coreModules.cache = storeCache;
loadCache(); loadCache();
const _window = window; interface WindowWithIconifyStuff {
IconifyPreload?: IconifyJSON[] | IconifyJSON;
IconifyProviders?: Record<string, PartialIconifyAPIConfig>;
}
const _window = window as WindowWithIconifyStuff;
// Load icons from global "IconifyPreload" // Load icons from global "IconifyPreload"
interface WindowWithIconifyPreload { if (_window.IconifyPreload !== void 0) {
IconifyPreload: IconifyJSON[] | IconifyJSON; const preload = _window.IconifyPreload;
}
if (
(_window as unknown as WindowWithIconifyPreload).IconifyPreload !==
void 0
) {
const preload = (_window as unknown as WindowWithIconifyPreload)
.IconifyPreload;
const err = 'Invalid IconifyPreload syntax.'; const err = 'Invalid IconifyPreload syntax.';
if (typeof preload === 'object' && preload !== null) { if (typeof preload === 'object' && preload !== null) {
(preload instanceof Array ? preload : [preload]).forEach((item) => { (preload instanceof Array ? preload : [preload]).forEach((item) => {
@ -270,15 +267,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
} }
// Set API from global "IconifyProviders" // Set API from global "IconifyProviders"
interface WindowWithIconifyProviders { if (_window.IconifyProviders !== void 0) {
IconifyProviders: Record<string, PartialIconifyAPIConfig>; const providers = _window.IconifyProviders;
}
if (
(_window as unknown as WindowWithIconifyProviders).IconifyProviders !==
void 0
) {
const providers = (_window as unknown as WindowWithIconifyProviders)
.IconifyProviders;
if (typeof providers === 'object' && providers !== null) { if (typeof providers === 'object' && providers !== null) {
for (let key in providers) { for (let key in providers) {
const err = 'IconifyProviders[' + key + '] is invalid.'; const err = 'IconifyProviders[' + key + '] is invalid.';