editor.js/src/components/utils/resolve-aliases.ts
Tatiana Fomina 870e265af0
fix(tunes): Make label an alias for title in tunes menu item (#2198)
* Make label an alias for title in tunes item

* Cleanup

* Update version and changelog

* Update changelog

* Move resolveAlias to utils

* Add fallback for popover item title

* Lint

* Lint

* Add fallback icon and title to popover

* Update version

* Lint

* Fix changelog

* Fallback to empty string

This reverts commit ae9d643557.

* Fix changelog again

* Cleanup

* Add deprecated
2022-12-14 23:46:36 +03:00

24 lines
753 B
TypeScript

/**
* Resolves aliases in specified object according to passed aliases info
*
* @example resolveAliases(obj, { label: 'title' })
* here 'label' is alias for 'title'
* @param obj - object with aliases to be resolved
* @param aliases - object with aliases info where key is an alias property name and value is an aliased property name
*/
export function resolveAliases<ObjectType>(obj: ObjectType, aliases: { [alias: string]: string }): ObjectType {
const result = {} as ObjectType;
Object.keys(obj).forEach(property => {
const aliasedProperty = aliases[property];
if (aliasedProperty !== undefined) {
result[aliasedProperty] = obj[property];
} else {
result[property] = obj[property];
}
});
return result;
}