diff --git a/packages/core/src/api/callbacks.ts b/packages/core/src/api/callbacks.ts index c771373..3d71115 100644 --- a/packages/core/src/api/callbacks.ts +++ b/packages/core/src/api/callbacks.ts @@ -49,7 +49,7 @@ export function updateCallbacks(storage: IconStorageWithAPI): void { } const name = icon.name; - if (storage.icons[name] !== void 0) { + if (storage.icons[name]) { // Loaded icons.loaded.push({ provider, diff --git a/packages/core/src/api/modules/mock.ts b/packages/core/src/api/modules/mock.ts index 9c75da8..0ec8e3c 100644 --- a/packages/core/src/api/modules/mock.ts +++ b/packages/core/src/api/modules/mock.ts @@ -109,35 +109,45 @@ export function mockAPIData(data: IconifyMockAPI): void { switch (data.type) { case 'icons': { const provider = data.provider; - if (iconsStorage[provider] === void 0) { - iconsStorage[provider] = {}; - } - const providerStorage = iconsStorage[provider]; - const prefix = data.prefix; - if (providerStorage[prefix] === void 0) { - providerStorage[prefix] = []; - } - iconsStorage[provider][prefix].push(data); + const providerStorage = + iconsStorage[provider] || + (iconsStorage[provider] = Object.create(null) as Record< + string, + IconifyMockIconsAPI[] + >); + + (providerStorage[prefix] || (providerStorage[prefix] = [])).push( + data + ); break; } case 'custom': { const provider = data.provider; - if (customProviderStorage[provider] === void 0) { - customProviderStorage[provider] = {}; - } - customProviderStorage[provider][data.uri] = data; + + const providerStorage = + customProviderStorage[provider] || + (customProviderStorage[provider] = Object.create( + null + ) as Record); + + providerStorage[data.uri] = data; break; } case 'host': { const host = data.host; - if (customHostStorage[host] === void 0) { - customHostStorage[host] = {}; - } - customHostStorage[host][data.uri] = data; + + const hostStorage = + customHostStorage[host] || + (customHostStorage[host] = Object.create(null) as Record< + string, + IconifyMockCustomHostAPI + >); + + hostStorage[data.uri] = data; break; } } diff --git a/packages/core/src/api/query.ts b/packages/core/src/api/query.ts index d00fd72..a834904 100644 --- a/packages/core/src/api/query.ts +++ b/packages/core/src/api/query.ts @@ -38,7 +38,7 @@ const redundancyCache = Object.create(null) as Record< function getRedundancyCache( provider: string ): IconifyAPIInternalStorage | undefined { - if (redundancyCache[provider] === void 0) { + if (!redundancyCache[provider]) { const config = getAPIConfig(provider); if (!config) { // Configuration is not set! diff --git a/packages/core/src/browser-storage/mock.ts b/packages/core/src/browser-storage/mock.ts index 014b1d9..420f980 100644 --- a/packages/core/src/browser-storage/mock.ts +++ b/packages/core/src/browser-storage/mock.ts @@ -41,7 +41,7 @@ export class Storage { if (!this.canRead) { throw new Error('Restricted storage'); } - return this.items[name] === void 0 ? null : this.items[name]; + return name in this.items ? this.items[name] : null; } /** diff --git a/packages/core/src/icon/sort.ts b/packages/core/src/icon/sort.ts index f042bdf..01e7aae 100644 --- a/packages/core/src/icon/sort.ts +++ b/packages/core/src/icon/sort.ts @@ -56,21 +56,19 @@ export function sortIcons(icons: IconifyIconName[]): SortedIcons { const prefix = icon.prefix; const name = icon.name; - if (storage[provider] === void 0) { - storage[provider] = Object.create(null) as Record< + const providerStorage = + storage[provider] || + (storage[provider] = Object.create(null) as Record< string, IconStorage - >; - } - const providerStorage = storage[provider]; + >); - if (providerStorage[prefix] === void 0) { - providerStorage[prefix] = getStorage(provider, prefix); - } - const localStorage = providerStorage[prefix]; + const localStorage = + providerStorage[prefix] || + (providerStorage[prefix] = getStorage(provider, prefix)); let list; - if (localStorage.icons[name] !== void 0) { + if (name in localStorage.icons) { list = result.loaded; } else if (prefix === '' || localStorage.missing.has(name)) { // Mark icons without prefix as missing because they cannot be loaded from API