2
0
mirror of https://github.com/iconify/iconify.git synced 2024-10-24 17:41:58 +00:00
iconify/packages/utils/src/customisations/compare.ts

33 lines
858 B
TypeScript
Raw Normal View History

2020-12-25 19:03:15 +00:00
import type { FullIconCustomisations } from '../customisations';
import { defaults } from '../customisations';
2020-04-28 09:47:35 +00:00
// Get all keys
const allKeys: (keyof FullIconCustomisations)[] = Object.keys(
defaults
) as (keyof FullIconCustomisations)[];
// All keys without width/height
2020-12-25 19:03:15 +00:00
const filteredKeys = allKeys.filter(
(key) => key !== 'width' && key !== 'height'
);
2020-04-28 09:47:35 +00:00
/**
* Compare sets of cusotmisations, return false if they are different, true if the same
*
* If dimensions are derived from props1 or props2, do not compare them.
*/
export function compare(
item1: FullIconCustomisations,
item2: FullIconCustomisations,
compareDimensions = true
): boolean {
const keys = compareDimensions ? allKeys : filteredKeys;
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (item1[key] !== item2[key]) {
return false;
}
}
return true;
}