mergeCustomisations()
This function is part of Iconify Utils package.
Function mergeCustomisations() merges default customisations, presented as FullIconCustomisations object and partial customisations. It also validates types, so it can be used to clean up user input.
Usage
Function has the following parameters:
- defaults, FullIconCustomisations. Full customisations.
- item, IconifyIconCustomisations. Partial customisations that need to be merged with defaults.
Function returns merged customisations with same type as passed in first parameter (which makes it possible to use function with extended types).
Example
import type { IconifyIconCustomisations } from '@iconify/utils';
import { defaultIconCustomisations, mergeCustomisations } from '@iconify/utils';
const customisations: IconifyIconCustomisations = {
hFlip: true,
};
const fullCustomisations = mergeCustomisations(
defaultIconCustomisations,
customisations
);
console.log(fullCustomisations);
Merge
Why not just merge objects, like this?
import type { IconifyIconCustomisations } from '@iconify/utils';
import { defaultIconCustomisations } from '@iconify/utils';
const customisations: IconifyIconCustomisations = {
hFlip: true,
};
const fullCustomisations = {
...defaultIconCustomisations,
...customisations,
};
console.log(fullCustomisations);
That works only with default customisations, but not if both objects have transformations.
Function mergeCustomisations() should be used when, for example, you are merging customisations from icon, which might include transformations and user's customisations. It can also be used to merge customisations when resolving icon alias.