2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-17 01:55:09 +00:00

chore: rename badly named iconExists to iconLoaded

This commit is contained in:
Vjacheslav Trushkin 2023-07-04 19:45:04 +03:00
parent 4765dc962f
commit 617f394b30
36 changed files with 251 additions and 175 deletions

View File

@ -5,7 +5,7 @@ import type { IconifyIconName } from '@iconify/utils/lib/icon/name';
import type { IconifyIconSize } from '@iconify/utils/lib/customisations/defaults';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -225,7 +225,14 @@ export { _api };
export { addAPIProvider, loadIcons, loadIcon };
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
export {
iconLoaded,
iconLoaded as iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
addCollection,
};
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };

View File

@ -9,7 +9,7 @@ import { stringToIcon } from '@iconify/utils/lib/icon/name';
import type { IconifyIconSize } from '@iconify/utils/lib/customisations/defaults';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -475,7 +475,14 @@ export { _api };
export { addAPIProvider, loadIcons, loadIcon };
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
export {
iconLoaded,
iconLoaded as iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
addCollection,
};
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };

View File

@ -31,9 +31,9 @@ describe('Rendering as span', () => {
'height': '1em',
'display': 'inline-block',
'backgroundColor': 'currentColor',
'webkitMaskImage': 'var(--svg)',
'webkitMaskRepeat': 'no-repeat',
'webkitMaskSize': '100% 100%',
// 'webkitMaskImage': 'var(--svg)',
// 'webkitMaskRepeat': 'no-repeat',
// 'webkitMaskSize': '100% 100%',
'maskImage': 'var(--svg)',
'maskRepeat': 'no-repeat',
'maskSize': '100% 100%',
@ -67,9 +67,9 @@ describe('Rendering as span', () => {
'height': '48px',
'display': 'inline-block',
'backgroundColor': 'currentColor',
'webkitMaskImage': 'var(--svg)',
'webkitMaskRepeat': 'no-repeat',
'webkitMaskSize': '100% 100%',
// 'webkitMaskImage': 'var(--svg)',
// 'webkitMaskRepeat': 'no-repeat',
// 'webkitMaskSize': '100% 100%',
'maskImage': 'var(--svg)',
'maskRepeat': 'no-repeat',
'maskSize': '100% 100%',

View File

@ -5,7 +5,8 @@
import {
enableCache,
disableCache,
iconExists,
iconLoaded,
iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
@ -22,7 +23,8 @@ import {
export {
enableCache,
disableCache,
iconExists,
iconLoaded,
iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,

View File

@ -6,7 +6,7 @@ import { stringToIcon } from '@iconify/utils/lib/icon/name';
import type { IconifyIconSize } from '@iconify/utils/lib/customisations/defaults';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -363,7 +363,14 @@ export { _api };
export { addAPIProvider, loadIcons, loadIcon };
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
export {
iconLoaded,
iconLoaded as iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
addCollection,
};
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };

View File

@ -50,7 +50,8 @@ export { IconifyIconOnLoad } from './functions';
export { enableCache, disableCache } from './functions';
export {
iconExists,
iconLoaded,
iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,

View File

@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { loadIcons, iconExists } from '../../dist';
import { loadIcons, iconLoaded } from '../../dist';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock';
import { provider, nextPrefix } from './load';
@ -26,7 +26,7 @@ describe('Testing fake API', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Load icon
loadIcons([iconName], (loaded, missing, pending) => {

View File

@ -3,7 +3,7 @@
*/
import { tick } from 'svelte';
import { render } from '@testing-library/svelte';
import Icon, { loadIcons, iconExists } from '../../dist';
import Icon, { loadIcons, iconLoaded } from '../../dist';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock';
import { provider, nextPrefix } from './load';
@ -35,7 +35,7 @@ describe('Rendering icon', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Load icon
loadIcons([iconName], (loaded, missing, pending) => {
@ -49,7 +49,7 @@ describe('Rendering icon', () => {
]);
expect(missing).toMatchObject([]);
expect(pending).toMatchObject([]);
expect(iconExists(iconName)).toBe(true);
expect(iconLoaded(iconName)).toBe(true);
// Render component
const component = render(Icon, {
@ -98,7 +98,7 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// onLoad should not have been called yet
expect(onLoadCalled).toBe(false);
@ -107,12 +107,12 @@ describe('Rendering icon', () => {
next();
// Test it again
expect(iconExists(iconName)).toBe(true);
expect(iconLoaded(iconName)).toBe(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Render component
const component = render(Icon, {
@ -167,13 +167,13 @@ describe('Rendering icon', () => {
response: 404,
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Send icon data
next();
// Test it again
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Check if state was changed on next few ticks
tick()
@ -203,7 +203,7 @@ describe('Rendering icon', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Render component
const component = render(Icon, {

View File

@ -5,7 +5,7 @@ import type { IconifyIconSize } from '@iconify/utils/lib/customisations/defaults
import type { IconifyIconBuildResult } from '@iconify/utils/lib/svg/build';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -206,7 +206,8 @@ const Iconify: IconifyGlobal = {
loadIcon,
// IconifyStorageFunctions
iconExists,
iconLoaded,
iconExists: iconLoaded, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
@ -248,7 +249,14 @@ export { _api };
export { addAPIProvider, loadIcons, loadIcon };
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
export {
iconLoaded,
iconLoaded as iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
addCollection,
};
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };

View File

@ -5,7 +5,7 @@ import type { IconifyIconSize } from '@iconify/utils/lib/customisations/defaults
import type { IconifyIconBuildResult } from '@iconify/utils/lib/svg/build';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -58,7 +58,8 @@ export interface IconifyGlobal
*/
const Iconify: IconifyGlobal = {
// IconifyStorageFunctions
iconExists,
iconLoaded,
iconExists: iconLoaded, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
@ -90,7 +91,14 @@ export default Iconify;
* Named exports
*/
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
export {
iconLoaded,
iconLoaded as iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
addCollection,
};
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };

View File

@ -1,4 +1,4 @@
import { iconExists } from '@iconify/core/lib/storage/functions';
import { iconLoaded } from '@iconify/core/lib/storage/functions';
import {
fakeAPI,
nextPrefix,
@ -27,7 +27,7 @@ describe('Changing render modes', () => {
const iconName = `@${provider}:${prefix}:home`;
// Add icon with API
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
mockAPIData({
type: 'icons',
provider,

View File

@ -7,7 +7,7 @@ import { loadIcons } from '../dist/iconify.mjs';
// Shortcut for offline module
import IconifyOffline from '@iconify/iconify/offline';
import { iconExists } from '@iconify/iconify/offline';
import { iconLoaded, iconExists } from '@iconify/iconify/offline';
// Direct link to offline module
import { addCollection } from '../dist/iconify.without-api.mjs';
@ -36,10 +36,15 @@ test(typeof Iconify.addIcon, 'function', 'Testing addIcon in default export');
* Test default export in offline module
*/
test(typeof IconifyOffline, 'object', 'Testing default offline export');
test(
typeof IconifyOffline.iconLoaded,
'function',
'Testing iconLoaded in default offline export'
);
test(
typeof IconifyOffline.iconExists,
'function',
'Testing iconExists in default offline export'
'Testing deprecated iconExists in default offline export'
);
test(
typeof IconifyOffline.loadIcons,
@ -56,5 +61,10 @@ test(typeof loadIcons, 'function', 'Testing loadIcons named export');
/**
* Test exports without API
*/
test(typeof iconExists, 'function', 'Testing iconExists named export');
test(typeof iconLoaded, 'function', 'Testing iconLoaded named export');
test(
typeof iconExists,
'function',
'Testing deprecated iconExists named export'
);
test(typeof addCollection, 'function', 'Testing addCollection named export');

View File

@ -1,4 +1,4 @@
import { iconExists } from '@iconify/core/lib/storage/functions';
import { iconLoaded } from '@iconify/core/lib/storage/functions';
import { loadIcon } from '@iconify/core/lib/api/icons';
import { defaultIconProps } from '@iconify/utils/lib/icon/defaults';
import { fakeAPI, nextPrefix, mockAPIData } from './helpers';
@ -29,7 +29,7 @@ describe('Testing mock API', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Load icon
const data = await loadIcon(iconName);

View File

@ -1,4 +1,4 @@
import { iconExists } from '@iconify/core/lib/storage/functions';
import { iconLoaded } from '@iconify/core/lib/storage/functions';
import {
fakeAPI,
nextPrefix,
@ -28,7 +28,7 @@ describe('Observing DOM changes', () => {
const iconName = `@${provider}:${prefix}:home`;
// Add icon with API
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
mockAPIData({
type: 'icons',
provider,
@ -89,8 +89,8 @@ describe('Observing DOM changes', () => {
let sendSecondIcon = null;
// Add icon with API
expect(iconExists(iconName)).toBe(false);
expect(iconExists(iconName2)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
expect(iconLoaded(iconName2)).toBe(false);
mockAPIData({
type: 'icons',
provider,
@ -185,8 +185,8 @@ describe('Observing DOM changes', () => {
let sendSecondIcon = null;
// Add icon with API
expect(iconExists(iconName)).toBe(false);
expect(iconExists(iconName2)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
expect(iconLoaded(iconName2)).toBe(false);
mockAPIData({
type: 'icons',
provider,
@ -263,7 +263,7 @@ describe('Observing DOM changes', () => {
// Send first API query
sendFirstIcon();
await awaitUntil(() => iconExists(iconName));
await awaitUntil(() => iconLoaded(iconName));
// Wait a bit more
await nextTick([0, 0, 0]);

View File

@ -1,4 +1,4 @@
import { iconExists, addIcon } from '@iconify/core/lib/storage/functions';
import { iconLoaded, addIcon } from '@iconify/core/lib/storage/functions';
import {
fakeAPI,
nextPrefix,
@ -26,11 +26,11 @@ describe('Scanning DOM', () => {
const iconName = `@${provider}:${prefix}:home`;
// Add icon
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
addIcon(iconName, {
body: '<g />',
});
expect(iconExists(iconName)).toBe(true);
expect(iconLoaded(iconName)).toBe(true);
// Setup DOM and wait for it to be ready
setupDOM(`<span class="iconify" data-icon="${iconName}"></span>`);
@ -64,7 +64,7 @@ describe('Scanning DOM', () => {
const iconName = `@${provider}:${prefix}:home`;
// Add icon with API
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
mockAPIData({
type: 'icons',
provider,
@ -123,7 +123,7 @@ describe('Scanning DOM', () => {
const iconName = `@${provider}:${prefix}:home`;
// Add icon with API
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
mockAPIData({
type: 'icons',
provider,

View File

@ -16,7 +16,7 @@ import { stringToIcon } from '@iconify/utils/lib/icon/name';
import type { IconifyIconSize } from '@iconify/utils/lib/customisations/defaults';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -408,7 +408,14 @@ export { _api };
export { addAPIProvider, loadIcons, loadIcon };
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
export {
iconLoaded,
iconLoaded as iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
addCollection,
};
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };

View File

@ -1,4 +1,4 @@
import { loadIcons, iconExists } from '../../';
import { loadIcons, iconLoaded } from '../../';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock';
import { provider, nextPrefix } from './load';
@ -23,7 +23,7 @@ describe('Testing fake API', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Load icon
loadIcons([iconName], (loaded, missing, pending) => {

View File

@ -1,6 +1,6 @@
import { nextTick } from 'vue';
import { mount } from '@vue/test-utils';
import { Icon, loadIcons, iconExists } from '../../';
import { Icon, loadIcons, iconLoaded } from '../../';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock';
import { provider, nextPrefix } from './load';
import { defaultIconResult } from '../empty';
@ -33,7 +33,7 @@ describe('Rendering icon', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Load icon
loadIcons([iconName], (loaded, missing, pending) => {
@ -47,7 +47,7 @@ describe('Rendering icon', () => {
]);
expect(missing).toMatchObject([]);
expect(pending).toMatchObject([]);
expect(iconExists(iconName)).toEqual(true);
expect(iconLoaded(iconName)).toEqual(true);
// Render component
const Wrapper = {
@ -104,7 +104,7 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// onLoad should not have been called yet
expect(onLoadCalled).toEqual(false);
@ -113,12 +113,12 @@ describe('Rendering icon', () => {
next();
// Test it again
expect(iconExists(iconName)).toEqual(true);
expect(iconLoaded(iconName)).toEqual(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Render component
const Wrapper = {
@ -176,13 +176,13 @@ describe('Rendering icon', () => {
response: 404,
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Send icon data
next();
// Test it again
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Check if state was changed on next few ticks
nextTick()
@ -203,7 +203,7 @@ describe('Rendering icon', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Render component
const Wrapper = {

View File

@ -1,6 +1,6 @@
import { nextTick } from 'vue';
import { mount } from '@vue/test-utils';
import { Icon, iconExists } from '../../';
import { Icon, iconLoaded } from '../../';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock';
import { provider, nextPrefix } from './load';
@ -92,7 +92,7 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// onLoad should not have been called yet
expect(onLoadCalled).toEqual('');
@ -101,7 +101,7 @@ describe('Rendering icon', () => {
next();
// Make sure icon data is available
expect(iconExists(iconName)).toEqual(true);
expect(iconLoaded(iconName)).toEqual(true);
},
});
@ -117,7 +117,7 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName2)).toEqual(false);
expect(iconLoaded(iconName2)).toEqual(false);
// onLoad should have been called only once for previous icon
expect(onLoadCalled).toEqual(iconName);
@ -126,12 +126,12 @@ describe('Rendering icon', () => {
next();
// Make sure icon data is available
expect(iconExists(iconName2)).toEqual(true);
expect(iconLoaded(iconName2)).toEqual(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Render component
const Wrapper = {
@ -221,18 +221,18 @@ describe('Rendering icon', () => {
expect(isSync).toEqual(false);
// Icon should not have loaded yet
expect(iconExists(iconName2)).toEqual(false);
expect(iconLoaded(iconName2)).toEqual(false);
// Send icon data
next();
// Make sure icon was loaded
expect(iconExists(iconName2)).toEqual(true);
expect(iconLoaded(iconName2)).toEqual(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Render component
const Wrapper = {
@ -313,18 +313,18 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Send icon data
next();
// Make sure icon was loaded
expect(iconExists(iconName)).toEqual(true);
expect(iconLoaded(iconName)).toEqual(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toEqual(false);
expect(iconLoaded(iconName)).toEqual(false);
// Render component with placeholder text
const Wrapper = {

View File

@ -9,7 +9,7 @@ import { stringToIcon } from '@iconify/utils/lib/icon/name';
import type { IconifyIconSize } from '@iconify/utils/lib/customisations/defaults';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -385,7 +385,14 @@ export { _api };
export { addAPIProvider, loadIcons, loadIcon };
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
export {
iconLoaded,
iconLoaded as iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
addCollection,
};
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };

View File

@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { loadIcons, iconExists } from '../../';
import { loadIcons, iconLoaded } from '../../';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock.cjs';
import { provider, nextPrefix } from './load';
@ -26,7 +26,7 @@ describe('Testing fake API', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Load icon
loadIcons([iconName], (loaded, missing, pending) => {

View File

@ -3,7 +3,7 @@
*/
import Vue from 'vue';
import { mount } from '@vue/test-utils';
import { Icon, loadIcons, iconExists } from '../../';
import { Icon, loadIcons, iconLoaded } from '../../';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock.cjs';
import { provider, nextPrefix } from './load';
import { defaultIconResult } from '../empty';
@ -36,7 +36,7 @@ describe('Rendering icon', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Load icon
loadIcons([iconName], (loaded, missing, pending) => {
@ -50,7 +50,7 @@ describe('Rendering icon', () => {
]);
expect(missing).toMatchObject([]);
expect(pending).toMatchObject([]);
expect(iconExists(iconName)).toBe(true);
expect(iconLoaded(iconName)).toBe(true);
// Render component
const Wrapper = {
@ -105,7 +105,7 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// onLoad should not have been called yet
expect(onLoadCalled).toBe(false);
@ -114,12 +114,12 @@ describe('Rendering icon', () => {
next();
// Test it again
expect(iconExists(iconName)).toBe(true);
expect(iconLoaded(iconName)).toBe(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Render component
const Wrapper = {
@ -179,13 +179,13 @@ describe('Rendering icon', () => {
response: 404,
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Send icon data
next();
// Test it again
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Check if state was changed after few ticks
Vue.nextTick(() => {
@ -201,7 +201,7 @@ describe('Rendering icon', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Render component
const Wrapper = {

View File

@ -3,7 +3,7 @@
*/
import Vue from 'vue';
import { mount } from '@vue/test-utils';
import { Icon, iconExists } from '../../';
import { Icon, iconLoaded } from '../../';
import { mockAPIData } from '@iconify/core/lib/api/modules/mock.cjs';
import { provider, nextPrefix } from './load';
import { defaultIconResult } from '../empty';
@ -96,7 +96,7 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// onLoad should not have been called yet
expect(onLoadCalled).toBe('');
@ -105,7 +105,7 @@ describe('Rendering icon', () => {
next();
// Make sure icon data is available
expect(iconExists(iconName)).toBe(true);
expect(iconLoaded(iconName)).toBe(true);
},
});
@ -121,7 +121,7 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName2)).toBe(false);
expect(iconLoaded(iconName2)).toBe(false);
// onLoad should have been called only once for previous icon
expect(onLoadCalled).toBe(iconName);
@ -130,12 +130,12 @@ describe('Rendering icon', () => {
next();
// Make sure icon data is available
expect(iconExists(iconName2)).toBe(true);
expect(iconLoaded(iconName2)).toBe(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Render component
const wrapper = mount(Icon, {
@ -224,18 +224,18 @@ describe('Rendering icon', () => {
expect(isSync).toBe(false);
// Icon should not have loaded yet
expect(iconExists(iconName2)).toBe(false);
expect(iconLoaded(iconName2)).toBe(false);
// Send icon data
next();
// Test it again
expect(iconExists(iconName2)).toBe(true);
expect(iconLoaded(iconName2)).toBe(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Render component
const wrapper = mount(Icon, {
@ -310,18 +310,18 @@ describe('Rendering icon', () => {
},
delay: (next) => {
// Icon should not have loaded yet
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Send icon data
next();
// Make sure icon was loaded
expect(iconExists(iconName)).toBe(true);
expect(iconLoaded(iconName)).toBe(true);
},
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Render component with placeholder text
const wrapper = mount(Icon, {

View File

@ -6,7 +6,7 @@ import {
IconifyStorageFunctions,
} from '@iconify/core/lib/storage/functions';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -159,7 +159,8 @@ export function exportFunctions(): IconifyExportedFunctions {
toggleBrowserCache(storage, true),
disableCache: (storage: IconifyBrowserCacheType) =>
toggleBrowserCache(storage, false),
iconExists,
iconLoaded,
iconExists: iconLoaded, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,

View File

@ -110,7 +110,8 @@ export const IconifyIconComponent = defineIconifyIcon() || exportFunctions();
const {
enableCache,
disableCache,
iconExists,
iconLoaded,
iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,
@ -126,7 +127,8 @@ const {
export {
enableCache,
disableCache,
iconExists,
iconLoaded,
iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,

View File

@ -88,8 +88,8 @@ describe('Testing icon component with API', () => {
sendQuery();
// Wait until icon exists
const iconExists = node.iconExists;
await awaitUntil(() => iconExists(iconName));
const iconLoaded = node.iconLoaded;
await awaitUntil(() => iconLoaded(iconName));
// Wait for render
await nextTick();

View File

@ -1,4 +1,4 @@
import { iconExists } from '@iconify/core/lib/storage/functions';
import { iconLoaded } from '@iconify/core/lib/storage/functions';
import { loadIcon } from '@iconify/core/lib/api/icons';
import { defaultIconProps } from '@iconify/utils/lib/icon/defaults';
import { fakeAPI, nextPrefix, mockAPIData } from '../src/tests/helpers';
@ -29,7 +29,7 @@ describe('Testing mock API', () => {
});
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
expect(iconLoaded(iconName)).toBe(false);
// Load icon
const data = await loadIcon(iconName);

View File

@ -57,7 +57,8 @@ export type {
export {
enableCache,
disableCache,
iconExists,
iconLoaded,
iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,

View File

@ -58,7 +58,8 @@ export type {
export {
enableCache,
disableCache,
iconExists,
iconLoaded,
iconExists, // deprecated, kept to avoid breaking changes
getIcon,
listIcons,
addIcon,

View File

@ -11,7 +11,14 @@ import { getStorage, addIconToStorage, addIconSet } from './storage';
*/
export interface IconifyStorageFunctions {
/**
* Check if icon exists
* Check if icon data is available
*/
iconLoaded: (name: string) => boolean;
/**
* Older, badly named, version of iconLoaded()
*
* @deprecated
*/
iconExists: (name: string) => boolean;
@ -133,9 +140,9 @@ export function addCollection(data: IconifyJSON, provider?: string): boolean {
}
/**
* Check if icon exists
* Check if icon data is available
*/
export function iconExists(name: string): boolean {
export function iconLoaded(name: string): boolean {
return !!getIconData(name);
}

View File

@ -98,9 +98,9 @@ export function addIconToStorage(
}
/**
* Check if icon exists
* Check if icon is available in storage
*/
export function iconExists(storage: IconStorage, name: string): boolean {
export function iconInStorage(storage: IconStorage, name: string): boolean {
return !!storage.icons[name];
}

View File

@ -3,7 +3,7 @@ import { setAPIModule } from '../../lib/api/modules';
import { loadIcons } from '../../lib/api/icons';
import type { IconifyMockAPIDelayDoneCallback } from '../../lib/api/modules/mock';
import { mockAPIModule, mockAPIData } from '../../lib/api/modules/mock';
import { getStorage, iconExists } from '../../lib/storage/storage';
import { getStorage, iconInStorage } from '../../lib/storage/storage';
import { sendAPIQuery } from '../../lib/api/query';
describe('Testing mock API module', () => {
@ -278,13 +278,13 @@ describe('Testing mock API module', () => {
delay: (next) => {
// Icon should not be loaded yet
const storage = getStorage(provider, prefix);
expect(iconExists(storage, name)).toBe(false);
expect(iconInStorage(storage, name)).toBe(false);
// Set data
next();
// Icon should be loaded now
expect(iconExists(storage, name)).toBe(true);
expect(iconInStorage(storage, name)).toBe(true);
fulfill(true);
},

View File

@ -10,7 +10,7 @@ import {
} from '../../lib/browser-storage/data';
import { getBrowserStorageItemsCount } from '../../lib/browser-storage/count';
import { getBrowserStorage } from '../../lib/browser-storage/global';
import { getStorage, iconExists } from '../../lib/storage/storage';
import { getStorage, iconInStorage } from '../../lib/storage/storage';
import { nextPrefix, createCache, reset } from '../../lib/browser-storage/mock';
import {
browserCacheCountKey,
@ -64,14 +64,14 @@ describe('Testing loading from localStorage', () => {
);
// Check icon storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
expect(storage.lastModifiedCached).toBeUndefined();
// Load localStorage
initBrowserStorage();
// Icon should exist now and lastModified should be set
expect(iconExists(storage, 'foo')).toBe(true);
expect(iconInStorage(storage, 'foo')).toBe(true);
expect(storage.lastModifiedCached).toBe(-1);
// Check data
@ -119,19 +119,19 @@ describe('Testing loading from localStorage', () => {
});
// Check icon storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
expect(storage.lastModifiedCached).toBeUndefined();
// Check default provider
expect(iconExists(defaultStorage, 'foo')).toBe(false);
expect(iconInStorage(defaultStorage, 'foo')).toBe(false);
expect(defaultStorage.lastModifiedCached).toBeUndefined();
// Load localStorage
initBrowserStorage();
// Icon should exist now
expect(iconExists(storage, 'foo')).toBe(true);
expect(iconExists(defaultStorage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(true);
expect(iconInStorage(defaultStorage, 'foo')).toBe(false);
// Check data
expect(browserStorageConfig).toEqual({
@ -189,13 +189,13 @@ describe('Testing loading from localStorage', () => {
);
// Check icon storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// Load localStorage
initBrowserStorage();
// Icon should not have loaded
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
expect(storage.lastModifiedCached).toBeUndefined();
// Check data
@ -253,13 +253,13 @@ describe('Testing loading from localStorage', () => {
);
// Check icon storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// Load localStorage
initBrowserStorage();
// Icon should not have loaded
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// Check data
expect(browserStorageConfig).toEqual({
@ -316,13 +316,13 @@ describe('Testing loading from localStorage', () => {
);
// Check icon storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// Load localStorage
initBrowserStorage();
// Icon should not have loaded
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// Check data
expect(browserStorageConfig).toEqual({
@ -370,13 +370,13 @@ describe('Testing loading from localStorage', () => {
);
// Check icon storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// Load localStorage
initBrowserStorage();
// Icon should exist now
expect(iconExists(storage, 'foo')).toBe(true);
expect(iconInStorage(storage, 'foo')).toBe(true);
// Check data
expect(browserStorageConfig).toEqual({
@ -445,15 +445,15 @@ describe('Testing loading from localStorage', () => {
);
// Check icon storage
expect(iconExists(storage, 'foo1')).toBe(false);
expect(iconExists(storage, 'foo4')).toBe(false);
expect(iconInStorage(storage, 'foo1')).toBe(false);
expect(iconInStorage(storage, 'foo4')).toBe(false);
// Load localStorage
initBrowserStorage();
// Icons should exist now
expect(iconExists(storage, 'foo1')).toBe(true);
expect(iconExists(storage, 'foo4')).toBe(true);
expect(iconInStorage(storage, 'foo1')).toBe(true);
expect(iconInStorage(storage, 'foo4')).toBe(true);
// Check data
expect(browserStorageConfig).toEqual({
@ -531,7 +531,7 @@ describe('Testing loading from localStorage', () => {
// Check icon storage
for (let i = 0; i < 6; i++) {
expect(iconExists(storage, 'foo' + i.toString())).toBe(false);
expect(iconInStorage(storage, 'foo' + i.toString())).toBe(false);
}
// Load localStorage
@ -539,7 +539,7 @@ describe('Testing loading from localStorage', () => {
// Icons should exist now, except for number 4
for (let i = 0; i < 6; i++) {
expect(iconExists(storage, 'foo' + i.toString())).toBe(i !== 4);
expect(iconInStorage(storage, 'foo' + i.toString())).toBe(i !== 4);
}
// Check data

View File

@ -11,7 +11,7 @@ import {
} from '../../lib/browser-storage/data';
import { getBrowserStorageItemsCount } from '../../lib/browser-storage/count';
import { getBrowserStorage } from '../../lib/browser-storage/global';
import { getStorage, iconExists } from '../../lib/storage/storage';
import { getStorage, iconInStorage } from '../../lib/storage/storage';
import { nextPrefix, createCache, reset } from '../../lib/browser-storage/mock';
import {
browserCacheCountKey,
@ -51,7 +51,7 @@ describe('Testing saving to localStorage', () => {
});
// Check icon storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
expect(storage.lastModifiedCached).toBeUndefined();
// Counter should be 0
@ -64,7 +64,7 @@ describe('Testing saving to localStorage', () => {
storeInBrowserStorage(storage, icon);
// Storing in cache should not add item to storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// lastModified is missing, so should not have updated
expect(storage.lastModifiedCached).toBeUndefined();
@ -571,7 +571,7 @@ describe('Testing saving to localStorage', () => {
});
// Check icon storage
expect(iconExists(storage, 'foo1')).toBe(false);
expect(iconInStorage(storage, 'foo1')).toBe(false);
// Load cache
initBrowserStorage();
@ -604,7 +604,7 @@ describe('Testing saving to localStorage', () => {
storeInBrowserStorage(storage, icon);
// Storing in cache should not add item to storage
expect(iconExists(storage, 'foo')).toBe(false);
expect(iconInStorage(storage, 'foo')).toBe(false);
// Check data that should have been updated because storeCache()
// should call load function before first execution
@ -708,10 +708,10 @@ describe('Testing saving to localStorage', () => {
// Check icon storage
for (let i = 0; i < 3; i++) {
expect(iconExists(storage, 'foo' + i.toString())).toBe(true);
expect(iconInStorage(storage, 'foo' + i.toString())).toBe(true);
}
for (let i = 0; i < 4; i++) {
expect(iconExists(storage, 'bar' + i.toString())).toBe(true);
expect(iconInStorage(storage, 'bar' + i.toString())).toBe(true);
}
// Add new item to localStorage
@ -833,10 +833,10 @@ describe('Testing saving to localStorage', () => {
// Check icon storage
for (let i = 0; i < 3; i++) {
expect(iconExists(storage, 'foo' + i.toString())).toBe(true);
expect(iconInStorage(storage, 'foo' + i.toString())).toBe(true);
}
for (let i = 0; i < 4; i++) {
expect(iconExists(storage, 'bar' + i.toString())).toBe(true);
expect(iconInStorage(storage, 'bar' + i.toString())).toBe(true);
}
// Set localStorage to read-only

View File

@ -1,7 +1,7 @@
import { defaultIconProps } from '@iconify/utils/lib/icon/defaults';
import { addIconSet, getStorage, listIcons } from '../../lib/storage/storage';
import {
iconExists,
iconLoaded,
getIcon,
addIcon,
addCollection,
@ -28,7 +28,7 @@ describe('Testing IconifyStorageFunctions', () => {
const testName = `@${provider}:foo:bar`;
// Empty
expect(iconExists(testName)).toBe(false);
expect(iconLoaded(testName)).toBe(false);
expect(getIconData(testName)).toBeUndefined();
expect(getIcon(testName)).toBeNull();
expect(listIcons(provider)).toEqual([]);
@ -39,7 +39,7 @@ describe('Testing IconifyStorageFunctions', () => {
body: '<g />',
})
).toBe(true);
expect(iconExists(testName)).toBe(true);
expect(iconLoaded(testName)).toBe(true);
expect(listIcons(provider)).toEqual([testName]);
let expected = {
@ -65,7 +65,7 @@ describe('Testing IconifyStorageFunctions', () => {
});
// Test 'home' icon
expect(iconExists(`${prefix}:home`)).toBe(true);
expect(iconLoaded(`${prefix}:home`)).toBe(true);
expected = {
body: '<g id="home" />',
};
@ -76,12 +76,12 @@ describe('Testing IconifyStorageFunctions', () => {
});
// Test 'missing' icon
expect(iconExists(`${prefix}:missing`)).toBe(false);
expect(iconLoaded(`${prefix}:missing`)).toBe(false);
expect(getIconData(`${prefix}:missing`)).toBeNull();
expect(getIcon(`${prefix}:missing`)).toBeNull();
// Test 'invalid' icon
expect(iconExists(`${prefix}:invalid`)).toBe(false);
expect(iconLoaded(`${prefix}:invalid`)).toBe(false);
expect(getIconData(`${prefix}:invalid`)).toBeUndefined();
expect(getIcon(`${prefix}:invalid`)).toBeNull();
});
@ -90,7 +90,7 @@ describe('Testing IconifyStorageFunctions', () => {
const testName = 'storage' + (count++).toString();
// Empty
expect(iconExists(testName)).toBe(false);
expect(iconLoaded(testName)).toBe(false);
expect(getIconData(testName)).toBeUndefined();
expect(getIcon(testName)).toBeNull();
@ -100,7 +100,7 @@ describe('Testing IconifyStorageFunctions', () => {
body: '<g />',
})
).toBe(false);
expect(iconExists(testName)).toBe(false);
expect(iconLoaded(testName)).toBe(false);
});
it('Invalid icon set', () => {
@ -124,7 +124,7 @@ describe('Testing IconifyStorageFunctions', () => {
allowSimpleNames(true);
// Empty
expect(iconExists(testName)).toBe(false);
expect(iconLoaded(testName)).toBe(false);
expect(getIcon(testName)).toBeNull();
// Add and test one icon
@ -133,7 +133,7 @@ describe('Testing IconifyStorageFunctions', () => {
body: '<g />',
})
).toBe(true);
expect(iconExists(testName)).toBe(true);
expect(iconLoaded(testName)).toBe(true);
});
it('Collection with simple icon name', () => {
@ -166,7 +166,7 @@ describe('Testing IconifyStorageFunctions', () => {
// Test 'test'
name = name1;
expect(iconExists(name)).toBe(true);
expect(iconLoaded(name)).toBe(true);
let expected = {
body: '<g data-icon="basic-icon" />',
};
@ -179,7 +179,7 @@ describe('Testing IconifyStorageFunctions', () => {
// Test prefixed icon, using ':' separator
name = `${prefix2}:${name2}`;
expect(listIcons('', prefix2)).toEqual([name]);
expect(iconExists(name)).toBe(true);
expect(iconLoaded(name)).toBe(true);
expected = {
body: '<g data-icon="prefixed-icon" />',
};
@ -191,7 +191,7 @@ describe('Testing IconifyStorageFunctions', () => {
// Test prefixed icon, using '-' separator
name = `${prefix2}-${name2}`;
expect(iconExists(name)).toBe(true);
expect(iconLoaded(name)).toBe(true);
expected = {
body: '<g data-icon="prefixed-icon" />',
};
@ -202,7 +202,7 @@ describe('Testing IconifyStorageFunctions', () => {
});
// Test missing icon: should not exist because without provider missing icon cannot be added
expect(iconExists(missing)).toBe(false);
expect(iconLoaded(missing)).toBe(false);
expect(getIconData(missing)).toBeUndefined();
expect(getIcon(missing)).toBeNull();
});

View File

@ -3,7 +3,7 @@ import type { IconifyIcon } from '@iconify/types';
import {
newStorage,
addIconToStorage,
iconExists,
iconInStorage,
addIconSet,
getStorage,
listIcons,
@ -46,12 +46,12 @@ describe('Testing storage', () => {
'constructor',
]);
// Test iconExists
expect(iconExists(storage, 'test')).toBe(true);
expect(iconExists(storage, 'constructor')).toBe(true);
expect(iconExists(storage, 'invalid')).toBe(false);
expect(iconExists(storage, 'missing')).toBe(false);
expect(iconExists(storage, 'not-really-missing')).toBe(true);
// Test iconInStorage
expect(iconInStorage(storage, 'test')).toBe(true);
expect(iconInStorage(storage, 'constructor')).toBe(true);
expect(iconInStorage(storage, 'invalid')).toBe(false);
expect(iconInStorage(storage, 'missing')).toBe(false);
expect(iconInStorage(storage, 'not-really-missing')).toBe(true);
// Test getIcon
let expected: IconifyIcon = {
@ -96,11 +96,11 @@ describe('Testing storage', () => {
expect(Object.keys(storage.icons)).toEqual(['icon1', 'icon2']);
// Test iconExists
expect(iconExists(storage, 'icon1')).toBe(true);
expect(iconExists(storage, 'icon2')).toBe(true);
expect(iconExists(storage, 'invalid')).toBe(false);
expect(iconExists(storage, 'missing')).toBe(false);
// Test iconInStorage
expect(iconInStorage(storage, 'icon1')).toBe(true);
expect(iconInStorage(storage, 'icon2')).toBe(true);
expect(iconInStorage(storage, 'invalid')).toBe(false);
expect(iconInStorage(storage, 'missing')).toBe(false);
// Test getIcon
let expected: IconifyIcon = {