2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-09 23:00:56 +00:00

fix: create empty objects from null in utils

This commit is contained in:
Vjacheslav Trushkin 2022-10-15 12:24:16 +03:00
parent 1f32c18768
commit 425905b7be
6 changed files with 15 additions and 9 deletions

View File

@ -1,4 +1,8 @@
import type { ExtendedIconifyIcon, IconifyJSON } from '@iconify/types';
import type {
ExtendedIconifyIcon,
IconifyAliases,
IconifyJSON,
} from '@iconify/types';
import { mergeIconData } from '../icon/merge';
import { getIconsTree } from './tree';
@ -11,7 +15,7 @@ export function internalGetIconData(
tree: string[]
): ExtendedIconifyIcon {
const icons = data.icons;
const aliases = data.aliases || {};
const aliases = data.aliases || (Object.create(null) as IconifyAliases);
let currentProps = {} as ExtendedIconifyIcon;

View File

@ -25,7 +25,8 @@ export function getIcons(
};
const sourceIcons = data.icons;
const sourceAliases = data.aliases || {};
const sourceAliases =
data.aliases || (Object.create(null) as IconifyAliases);
// Add lastModified
if (data.lastModified) {

View File

@ -1,4 +1,4 @@
import type { IconifyJSON } from '@iconify/types';
import type { IconifyAliases, IconifyJSON } from '@iconify/types';
// Parent icons, first is direct parent, last is icon. Does not include self
export type ParentIconsList = string[];
@ -16,7 +16,7 @@ export function getIconsTree(
names?: string[]
): ParentIconsTree {
const icons = data.icons;
const aliases = data.aliases || {};
const aliases = data.aliases || (Object.create(null) as IconifyAliases);
const resolved = Object.create(null) as ParentIconsTree;

View File

@ -1,4 +1,4 @@
import type { IconifyJSON } from '@iconify/types';
import type { IconifyAliases, IconifyJSON } from '@iconify/types';
import { matchIconName } from '../icon/name';
import {
defaultIconDimensions,
@ -75,7 +75,7 @@ export function quicklyValidateIconSet(obj: unknown): IconifyJSON | null {
}
// Check all aliases
const aliases = data.aliases || {};
const aliases = data.aliases || (Object.create(null) as IconifyAliases);
for (const name in aliases) {
const icon = aliases[name];
const parent = icon.parent;

View File

@ -1,5 +1,6 @@
import type {
ExtendedIconifyIcon,
IconifyAliases,
IconifyJSON,
IconifyOptional,
} from '@iconify/types';
@ -135,7 +136,7 @@ export function validateIconSet(
// Validate all icons and aliases
const tree = getIconsTree(data);
const icons = data.icons;
const aliases = data.aliases || {};
const aliases = data.aliases || (Object.create(null) as IconifyAliases);
for (const name in tree) {
const treeItem = tree[name];
const isAlias = !icons[name];

View File

@ -41,7 +41,7 @@ export function commonObjectProps<T extends Record<string, unknown>>(
item: unknown,
reference: T
): Partial<T> {
const result = {} as T;
const result = Object.create(null) as T;
for (const key in reference) {
if (key in (item as T)) {
result[key] = (item as T)[key];