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

Optimisations in Utils

This commit is contained in:
Vjacheslav Trushkin 2022-07-03 16:45:52 +03:00
parent 696a5514e2
commit 780f93c7a0
8 changed files with 17 additions and 29 deletions

View File

@ -21,7 +21,7 @@ export function expandIconSet(data: IconifyJSON): void {
icons.forEach((name) => {
const item = data.icons[name];
if (item[prop] === void 0) {
if (!(prop in item)) {
item[prop] = value;
}
});

View File

@ -61,7 +61,7 @@ export function getIcons(
// Copy common properties
propsToCopy.forEach((attr) => {
if (data[attr] !== void 0) {
if (attr in data) {
(result as unknown as Record<string, unknown>)[attr] = data[attr];
}
});

View File

@ -120,12 +120,11 @@ export function minifyIconSet(data: IconifyJSON): void {
icons.forEach((key) => {
const item = data.icons[key];
const value =
item[prop] === void 0
? hasMinifiedDefault
? oldDefault
: defaultValue
: item[prop];
prop in item
? item[prop]
: hasMinifiedDefault
? oldDefault
: defaultValue;
if (
value === newDefault ||
(newDefault === null && value === defaultValue)
@ -136,7 +135,7 @@ export function minifyIconSet(data: IconifyJSON): void {
return;
}
if (canMinify && item[prop] === void 0) {
if (canMinify && !(prop in item)) {
// Value matches old minified value
item[prop as 'height'] = value as number;
}

View File

@ -25,7 +25,7 @@ export function getIconsTree(
return (resolved[name] = []);
}
if (resolved[name] === void 0) {
if (!(name in resolved)) {
// Mark as failed if parent alias points to this icon to avoid infinite loop
resolved[name] = null;

View File

@ -22,10 +22,7 @@ const optionalPropertyDefaults = {
*/
function checkOptionalProps(item: PropsList, defaults: PropsList): boolean {
for (const prop in defaults) {
if (
item[prop] !== void 0 &&
typeof item[prop] !== typeof defaults[prop]
) {
if (prop in item && typeof item[prop] !== typeof defaults[prop]) {
return false;
}
}

View File

@ -1,4 +1,3 @@
import type { IconifyTransformations } from '@iconify/types';
import {
defaultExtendedIconProps,
defaultIconTransformations,
@ -21,21 +20,15 @@ export function mergeIconData<T extends PartialExtendedIconifyIcon>(
// Merge icon properties that aren't transformations
for (const key in defaultExtendedIconProps) {
// Add default transformations if needed
if (
defaultIconTransformations[key as keyof IconifyTransformations] !==
void 0
) {
if (
result[key as 'rotate'] === void 0 &&
parent[key as keyof T] !== void 0
) {
if (key in defaultIconTransformations) {
if (key in parent && !(key in result)) {
result[key as 'rotate'] =
defaultIconTransformations[key as 'rotate'];
}
// Not transformation
} else if (child[key as 'width'] !== void 0) {
} else if (key in child) {
result[key as 'width'] = child[key as 'width'];
} else if (parent[key as 'width'] !== void 0) {
} else if (key in parent) {
result[key as 'width'] = parent[key as 'width'];
}
}

View File

@ -43,9 +43,8 @@ export function commonObjectProps<T extends Record<string, unknown>>(
): Partial<T> {
const result = {} as T;
for (const key in reference) {
const value = (item as T)[key];
if (value !== void 0) {
result[key] = value;
if (key in (item as T)) {
result[key] = (item as T)[key];
}
}
return result;

View File

@ -16,7 +16,7 @@ export function calculateSize(
return size;
}
precision = precision === void 0 ? 100 : precision;
precision = precision || 100;
if (typeof size === 'number') {
return Math.ceil(size * ratio * precision) / precision;
}