mergeIconData()

This function is part of Iconify Utils package.

Function mergeIconData() merges data for icon and alias.

Merging logic

When combining icon and alias, properties cannot be simply merged. This is because transformations for alias are relative to parent icons's transformations.

For example, if icon has 90 degrees rotation and alias also has 90 degrees rotation, result is 180 degrees rotation. Same for horizontal and vertical flip.

Usage

Function has the following parameters:

Function returns merged icon data.

Example

usage.ts
import type { IconifyIcon } from '@iconify/types';
import { mergeIconData } from '@iconify/utils/lib/icon/merge';
import { fullIcon } from '@iconify/utils/lib/icon';

// Rotate icon
const icon1: IconifyIcon = {
   body: '<path d="M7 6v12l10-6z" fill="currentColor"/>',
   width: 24,
   height: 24,
};
const result1 = mergeIconData(icon1, {
   rotate: 1,
});
console.log(result1);

// Merge full icon
const icon2 = fullIcon({
   body: '<path d="M7 6v12l10-6z" fill="currentColor"/>',
   width: 24,
   height: 24,
   hFlip: true,
});
// Result has the same type as first parameter, so in this case Required<IconifyIcon>
const result2 = mergeIconData(icon2, {
   hFlip: true,
});
console.log(result2);
Result 1:
{
   "body": "<path d=\"M7 6v12l10-6z\" fill=\"currentColor\"/>",
   "width": 24,
   "height": 24,
   "rotate": 1
}
Result 2:
{
   "left": 0,
   "top": 0,
   "width": 24,
   "height": 24,
   "rotate": 0,
   "vFlip": false,
   "hFlip": false,
   "body": "<path d=\"M7 6v12l10-6z\" fill=\"currentColor\"/>"
}