mirror of
https://github.com/codex-team/editor.js
synced 2024-06-07 00:12:35 +02:00
870e265af0
* 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
24 lines
753 B
TypeScript
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;
|
|
}
|