refactor: use reduce generic type instead of type cast

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2023-11-30 20:39:35 +01:00
parent e46b987201
commit 20f0a497ce
5 changed files with 29 additions and 33 deletions

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -17,8 +17,9 @@ export function convertInlineStyleToMap(
return {}
}
return inlineStyle.split(';').reduce(
(styleObject, stylePropertyValue) => {
return inlineStyle
.split(';')
.reduce<Record<string, string>>((styleObject, stylePropertyValue) => {
// extract the style property name and value
const [property, value] = stylePropertyValue
.split(/^([^:]+):/)
@ -44,7 +45,5 @@ export function convertInlineStyleToMap(
styleObject[replacedProperty] = value
return styleObject
},
{} as Record<string, string>
)
}, {})
}

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -48,22 +48,19 @@ export function mapHtmlAttributesToReactElementAttributes(
!isEventHandlerAttribute(attribute) &&
isValidTagOrAttributeName(attribute)
)
.reduce(
(mappedAttributes, attribute) => {
// lowercase the attribute name and find it in the react attribute map
const lowerCaseAttribute = attribute.toLowerCase()
.reduce<Record<string, string>>((mappedAttributes, attribute) => {
// lowercase the attribute name and find it in the react attribute map
const lowerCaseAttribute = attribute.toLowerCase()
// format the attribute name
const name = reactAttributes[lowerCaseAttribute] || attribute
// format the attribute name
const name = reactAttributes[lowerCaseAttribute] || attribute
// add the parsed attribute value to the mapped attributes
mappedAttributes[name] = getParsedAttributeValue(
name,
attributes[attribute]
)
// add the parsed attribute value to the mapped attributes
mappedAttributes[name] = getParsedAttributeValue(
name,
attributes[attribute]
)
return mappedAttributes
},
{} as Record<string, string>
)
return mappedAttributes
}, {})
}