2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-06 07:20:40 +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(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) => {

View File

@ -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<string, PartialIconifyAPIConfig>;
}
const _window = window as WindowWithIconifyStuff;
// Set API from global "IconifyProviders"
interface WindowWithIconifyProviders {
IconifyProviders: Record<string, PartialIconifyAPIConfig>;
}
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.';

View File

@ -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<string, PartialIconifyAPIConfig>;
}
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<string, PartialIconifyAPIConfig>;
}
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.';

View File

@ -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<string, PartialIconifyAPIConfig>;
}
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<string, PartialIconifyAPIConfig>;
}
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.';

View File

@ -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<string, PartialIconifyAPIConfig>;
}
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<string, PartialIconifyAPIConfig>;
}
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.';

View File

@ -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<string, PartialIconifyAPIConfig>;
}
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<string, PartialIconifyAPIConfig>;
}
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.';