add tests for mergeAttributes

This commit is contained in:
Philipp Kühn
2020-11-02 22:17:39 +01:00
parent d3319bea4e
commit 727442c3a5
2 changed files with 66 additions and 5 deletions

View File

@@ -5,18 +5,19 @@ export default function mergeAttributes(...object: AnyObject[]) {
const mergedAttributes = { ...items }
Object.entries(item).forEach(([key, value]) => {
if (!mergedAttributes[key]) {
const exists = mergedAttributes[key]
if (!exists) {
mergedAttributes[key] = value
return
}
if (key === 'class') {
mergedAttributes[key] = [mergedAttributes[key], value].join(' ')
return
}
if (key === 'style') {
} else if (key === 'style') {
mergedAttributes[key] = [mergedAttributes[key], value].join('; ')
} else {
mergedAttributes[key] = value
}
})