mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 23:00:56 +00:00
chore: remove Object.create
+ fix vitest cjs tests
This commit is contained in:
parent
1736308a64
commit
20596bef1d
@ -20,8 +20,8 @@ let rootVarName: string | null = null;
|
||||
/**
|
||||
* Cache: provider:prefix = value
|
||||
*/
|
||||
const maxLengthCache: Record<string, number> = Object.create(null);
|
||||
const pathCache: Record<string, string> = Object.create(null);
|
||||
const maxLengthCache: Record<string, number> = {};
|
||||
const pathCache: Record<string, string> = {};
|
||||
|
||||
/**
|
||||
* Get hash for query
|
||||
@ -58,14 +58,14 @@ function getGlobal(): JSONPRoot {
|
||||
prefix = 'IconifyJSONP';
|
||||
extraPrefix = '';
|
||||
if (globalRoot[prefix] === void 0) {
|
||||
globalRoot[prefix] = Object.create(null);
|
||||
globalRoot[prefix] = {};
|
||||
}
|
||||
rootVar = globalRoot[prefix] as JSONPRoot;
|
||||
} else {
|
||||
// Use 'Iconify.cb'
|
||||
const iconifyRoot = globalRoot[prefix] as Record<string, JSONPRoot>;
|
||||
if (iconifyRoot.cb === void 0) {
|
||||
iconifyRoot.cb = Object.create(null);
|
||||
iconifyRoot.cb = {};
|
||||
}
|
||||
rootVar = iconifyRoot.cb;
|
||||
}
|
||||
@ -94,7 +94,7 @@ function calculateMaxLength(provider: string, prefix: string): number {
|
||||
} else {
|
||||
let maxHostLength = 0;
|
||||
config.resources.forEach((item) => {
|
||||
const host = item as string;
|
||||
const host = item;
|
||||
maxHostLength = Math.max(maxHostLength, host.length);
|
||||
});
|
||||
|
||||
@ -195,10 +195,10 @@ const send: IconifyAPISendQuery = (
|
||||
let cbCounter = hash(
|
||||
provider + ':' + host + ':' + prefix + ':' + iconsList
|
||||
);
|
||||
while (global[cbPrefix + cbCounter] !== void 0) {
|
||||
while (global[`${cbPrefix}${cbCounter}`] !== void 0) {
|
||||
cbCounter++;
|
||||
}
|
||||
const callbackName = cbPrefix + cbCounter;
|
||||
const callbackName = `${cbPrefix}${cbCounter}`;
|
||||
|
||||
const url = mergeParams(prefix + '.js', {
|
||||
icons: iconsList,
|
||||
|
@ -12,8 +12,8 @@ import { mergeParams } from '../params';
|
||||
/**
|
||||
* Cache
|
||||
*/
|
||||
const maxLengthCache: Record<string, number> = Object.create(null);
|
||||
const pathCache: Record<string, string> = Object.create(null);
|
||||
const maxLengthCache: Record<string, number> = {};
|
||||
const pathCache: Record<string, string> = {};
|
||||
|
||||
/**
|
||||
* Get fetch function
|
||||
@ -71,7 +71,7 @@ function calculateMaxLength(provider: string, prefix: string): number {
|
||||
} else {
|
||||
let maxHostLength = 0;
|
||||
config.resources.forEach((item) => {
|
||||
const host = item as string;
|
||||
const host = item;
|
||||
maxHostLength = Math.max(maxHostLength, host.length);
|
||||
});
|
||||
|
||||
|
@ -80,7 +80,7 @@ export type IconifyMockAPI =
|
||||
export const iconsStorage: Record<
|
||||
string,
|
||||
Record<string, IconifyMockIconsAPI[]>
|
||||
> = Object.create(null);
|
||||
> = {};
|
||||
|
||||
/**
|
||||
* Fake API storage for custom queries
|
||||
@ -90,7 +90,7 @@ export const iconsStorage: Record<
|
||||
export const customProviderStorage: Record<
|
||||
string,
|
||||
Record<string, IconifyMockCustomAPI>
|
||||
> = Object.create(null);
|
||||
> = {};
|
||||
|
||||
/**
|
||||
* Fake API storage for custom queries
|
||||
@ -100,7 +100,7 @@ export const customProviderStorage: Record<
|
||||
export const customHostStorage: Record<
|
||||
string,
|
||||
Record<string, IconifyMockCustomHostAPI>
|
||||
> = Object.create(null);
|
||||
> = {};
|
||||
|
||||
/**
|
||||
* Set data for mocking API
|
||||
@ -110,7 +110,7 @@ export function mockAPIData(data: IconifyMockAPI): void {
|
||||
case 'icons': {
|
||||
const provider = data.provider;
|
||||
if (iconsStorage[provider] === void 0) {
|
||||
iconsStorage[provider] = Object.create(null);
|
||||
iconsStorage[provider] = {};
|
||||
}
|
||||
const providerStorage = iconsStorage[provider];
|
||||
|
||||
@ -126,7 +126,7 @@ export function mockAPIData(data: IconifyMockAPI): void {
|
||||
case 'custom': {
|
||||
const provider = data.provider;
|
||||
if (customProviderStorage[provider] === void 0) {
|
||||
customProviderStorage[provider] = Object.create(null);
|
||||
customProviderStorage[provider] = {};
|
||||
}
|
||||
customProviderStorage[provider][data.uri] = data;
|
||||
break;
|
||||
@ -135,7 +135,7 @@ export function mockAPIData(data: IconifyMockAPI): void {
|
||||
case 'host': {
|
||||
const host = data.host;
|
||||
if (customHostStorage[host] === void 0) {
|
||||
customHostStorage[host] = Object.create(null);
|
||||
customHostStorage[host] = {};
|
||||
}
|
||||
customHostStorage[host][data.uri] = data;
|
||||
break;
|
||||
@ -180,7 +180,7 @@ export const mockAPIModule: IconifyAPIModule = {
|
||||
);
|
||||
|
||||
// Find all icons
|
||||
const matches: Record<number, string[]> = Object.create(null);
|
||||
const matches: Record<number, string[]> = {};
|
||||
const noMatch: string[] = [];
|
||||
icons.forEach((name) => {
|
||||
let index = mockData.findIndex((item) => {
|
||||
|
@ -7,6 +7,7 @@ module.exports = defineConfig({
|
||||
},
|
||||
test: {
|
||||
globals: true,
|
||||
isolate: false,
|
||||
watch: false,
|
||||
include: ['**/tests/**/*-test.ts'],
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user