From 7214c077b4bebe655ec70b0ed9657f86022d6a06 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 13 May 2021 22:33:33 +0300 Subject: [PATCH] Clean up code for IconifyPreload and IconifyProviders --- packages/iconify/src/common.ts | 16 ++++++---------- packages/iconify/src/iconify.ts | 20 ++++++++------------ packages/react/src/iconify.ts | 28 +++++++++------------------- packages/svelte/src/functions.ts | 28 +++++++++------------------- packages/vue/src/iconify.ts | 28 +++++++++------------------- packages/vue2/src/iconify.ts | 28 +++++++++------------------- 6 files changed, 50 insertions(+), 98 deletions(-) diff --git a/packages/iconify/src/common.ts b/packages/iconify/src/common.ts index 612f7b0..c496faa 100644 --- a/packages/iconify/src/common.ts +++ b/packages/iconify/src/common.ts @@ -211,18 +211,14 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { // addFinder(iconifyIconFinder); addFinder(iconifyFinder); - const _window = window; + interface WindowWithIconifyStuff { + IconifyPreload?: IconifyJSON[] | IconifyJSON; + } + const _window = window as WindowWithIconifyStuff; // Load icons from global "IconifyPreload" - interface WindowWithIconifyPreload { - IconifyPreload: IconifyJSON[] | IconifyJSON; - } - if ( - (_window as unknown as WindowWithIconifyPreload).IconifyPreload !== - void 0 - ) { - const preload = (_window as unknown as WindowWithIconifyPreload) - .IconifyPreload; + if (_window.IconifyPreload !== void 0) { + const preload = _window.IconifyPreload; const err = 'Invalid IconifyPreload syntax.'; if (typeof preload === 'object' && preload !== null) { (preload instanceof Array ? preload : [preload]).forEach((item) => { diff --git a/packages/iconify/src/iconify.ts b/packages/iconify/src/iconify.ts index 685bf0d..81f6f97 100644 --- a/packages/iconify/src/iconify.ts +++ b/packages/iconify/src/iconify.ts @@ -130,10 +130,10 @@ const browserCacheFunctions: IconifyBrowserCacheFunctions = { /** * Global variable */ -const Iconify = ({ +const Iconify = { // Exposed internal API functions _api: APIInternalFunctions, -} as unknown) as IconifyGlobal; +} as unknown as IconifyGlobal; // Add functions [ @@ -188,18 +188,14 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { coreModules.cache = storeCache; loadCache(); - const _window = window; + interface WindowWithIconifyStuff { + IconifyProviders?: Record; + } + const _window = window as WindowWithIconifyStuff; // Set API from global "IconifyProviders" - interface WindowWithIconifyProviders { - IconifyProviders: Record; - } - if ( - ((_window as unknown) as WindowWithIconifyProviders) - .IconifyProviders !== void 0 - ) { - const providers = ((_window as unknown) as WindowWithIconifyProviders) - .IconifyProviders; + if (_window.IconifyProviders !== void 0) { + const providers = _window.IconifyProviders; if (typeof providers === 'object' && providers !== null) { for (let key in providers) { const err = 'IconifyProviders[' + key + '] is invalid.'; diff --git a/packages/react/src/iconify.ts b/packages/react/src/iconify.ts index 5e555e6..2e28739 100644 --- a/packages/react/src/iconify.ts +++ b/packages/react/src/iconify.ts @@ -233,18 +233,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { coreModules.cache = storeCache; loadCache(); - const _window = window; + interface WindowWithIconifyStuff { + IconifyPreload?: IconifyJSON[] | IconifyJSON; + IconifyProviders?: Record; + } + const _window = window as WindowWithIconifyStuff; // Load icons from global "IconifyPreload" - interface WindowWithIconifyPreload { - IconifyPreload: IconifyJSON[] | IconifyJSON; - } - if ( - (_window as unknown as WindowWithIconifyPreload).IconifyPreload !== - void 0 - ) { - const preload = (_window as unknown as WindowWithIconifyPreload) - .IconifyPreload; + if (_window.IconifyPreload !== void 0) { + const preload = _window.IconifyPreload; const err = 'Invalid IconifyPreload syntax.'; if (typeof preload === 'object' && preload !== null) { (preload instanceof Array ? preload : [preload]).forEach((item) => { @@ -270,15 +267,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { } // Set API from global "IconifyProviders" - interface WindowWithIconifyProviders { - IconifyProviders: Record; - } - if ( - (_window as unknown as WindowWithIconifyProviders).IconifyProviders !== - void 0 - ) { - const providers = (_window as unknown as WindowWithIconifyProviders) - .IconifyProviders; + if (_window.IconifyProviders !== void 0) { + const providers = _window.IconifyProviders; if (typeof providers === 'object' && providers !== null) { for (let key in providers) { const err = 'IconifyProviders[' + key + '] is invalid.'; diff --git a/packages/svelte/src/functions.ts b/packages/svelte/src/functions.ts index 071d03d..54ec884 100644 --- a/packages/svelte/src/functions.ts +++ b/packages/svelte/src/functions.ts @@ -229,18 +229,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { coreModules.cache = storeCache; loadCache(); - const _window = window; + interface WindowWithIconifyStuff { + IconifyPreload?: IconifyJSON[] | IconifyJSON; + IconifyProviders?: Record; + } + const _window = window as WindowWithIconifyStuff; // Load icons from global "IconifyPreload" - interface WindowWithIconifyPreload { - IconifyPreload: IconifyJSON[] | IconifyJSON; - } - if ( - (_window as unknown as WindowWithIconifyPreload).IconifyPreload !== - void 0 - ) { - const preload = (_window as unknown as WindowWithIconifyPreload) - .IconifyPreload; + if (_window.IconifyPreload !== void 0) { + const preload = _window.IconifyPreload; const err = 'Invalid IconifyPreload syntax.'; if (typeof preload === 'object' && preload !== null) { (preload instanceof Array ? preload : [preload]).forEach((item) => { @@ -266,15 +263,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { } // Set API from global "IconifyProviders" - interface WindowWithIconifyProviders { - IconifyProviders: Record; - } - if ( - (_window as unknown as WindowWithIconifyProviders).IconifyProviders !== - void 0 - ) { - const providers = (_window as unknown as WindowWithIconifyProviders) - .IconifyProviders; + if (_window.IconifyProviders !== void 0) { + const providers = _window.IconifyProviders; if (typeof providers === 'object' && providers !== null) { for (let key in providers) { const err = 'IconifyProviders[' + key + '] is invalid.'; diff --git a/packages/vue/src/iconify.ts b/packages/vue/src/iconify.ts index 1cf70df..0167104 100644 --- a/packages/vue/src/iconify.ts +++ b/packages/vue/src/iconify.ts @@ -241,18 +241,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { coreModules.cache = storeCache; loadCache(); - const _window = window; + interface WindowWithIconifyStuff { + IconifyPreload?: IconifyJSON[] | IconifyJSON; + IconifyProviders?: Record; + } + const _window = window as WindowWithIconifyStuff; // Load icons from global "IconifyPreload" - interface WindowWithIconifyPreload { - IconifyPreload: IconifyJSON[] | IconifyJSON; - } - if ( - ((_window as unknown) as WindowWithIconifyPreload).IconifyPreload !== - void 0 - ) { - const preload = ((_window as unknown) as WindowWithIconifyPreload) - .IconifyPreload; + if (_window.IconifyPreload !== void 0) { + const preload = _window.IconifyPreload; const err = 'Invalid IconifyPreload syntax.'; if (typeof preload === 'object' && preload !== null) { (preload instanceof Array ? preload : [preload]).forEach(item => { @@ -278,15 +275,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { } // Set API from global "IconifyProviders" - interface WindowWithIconifyProviders { - IconifyProviders: Record; - } - if ( - ((_window as unknown) as WindowWithIconifyProviders) - .IconifyProviders !== void 0 - ) { - const providers = ((_window as unknown) as WindowWithIconifyProviders) - .IconifyProviders; + if (_window.IconifyProviders !== void 0) { + const providers = _window.IconifyProviders; if (typeof providers === 'object' && providers !== null) { for (let key in providers) { const err = 'IconifyProviders[' + key + '] is invalid.'; diff --git a/packages/vue2/src/iconify.ts b/packages/vue2/src/iconify.ts index 75a77a9..0f607c8 100644 --- a/packages/vue2/src/iconify.ts +++ b/packages/vue2/src/iconify.ts @@ -233,18 +233,15 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { coreModules.cache = storeCache; loadCache(); - const _window = window; + interface WindowWithIconifyStuff { + IconifyPreload?: IconifyJSON[] | IconifyJSON; + IconifyProviders?: Record; + } + const _window = window as WindowWithIconifyStuff; // Load icons from global "IconifyPreload" - interface WindowWithIconifyPreload { - IconifyPreload: IconifyJSON[] | IconifyJSON; - } - if ( - (_window as unknown as WindowWithIconifyPreload).IconifyPreload !== - void 0 - ) { - const preload = (_window as unknown as WindowWithIconifyPreload) - .IconifyPreload; + if (_window.IconifyPreload !== void 0) { + const preload = _window.IconifyPreload; const err = 'Invalid IconifyPreload syntax.'; if (typeof preload === 'object' && preload !== null) { (preload instanceof Array ? preload : [preload]).forEach((item) => { @@ -270,15 +267,8 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') { } // Set API from global "IconifyProviders" - interface WindowWithIconifyProviders { - IconifyProviders: Record; - } - if ( - (_window as unknown as WindowWithIconifyProviders).IconifyProviders !== - void 0 - ) { - const providers = (_window as unknown as WindowWithIconifyProviders) - .IconifyProviders; + if (_window.IconifyProviders !== void 0) { + const providers = _window.IconifyProviders; if (typeof providers === 'object' && providers !== null) { for (let key in providers) { const err = 'IconifyProviders[' + key + '] is invalid.';