[web] Remove ternary statements

This commit is contained in:
Alain Nussbaumer
2025-05-25 10:12:59 +02:00
parent 78ffba97d8
commit b251a4e418
9 changed files with 37 additions and 29 deletions

View File

@@ -5,8 +5,16 @@ const NO_INDEX = 'NO_INDEX'
const numberComparator = (a, b) => a - b
const stringComparator = (a, b) => a.localeCompare(b, locale.value)
const dateComparator = (a, b) =>
new Date(a) - new Date(b) || (a ? (b ? 0 : 1) : -1)
const dateComparator = (a, b) => {
const timeA = Date.parse(a)
const timeB = Date.parse(b)
const isInvalidA = isNaN(timeA)
const isInvalidB = isNaN(timeB)
if (isInvalidA && isInvalidB) {
return 0
}
return (isInvalidA && 1) || (isInvalidB && -1) || timeA - timeB
}
const createComparators = (criteria) =>
criteria.map(({ field, type, order = 1 }) => {

View File

@@ -14,14 +14,18 @@ const luminance = (color) =>
) / 255
export const renderSVG = (data) => {
const color = toColor(data.alternate),
svg = `<svg xmlns="http://www.w3.org/2000/svg"
const background = toColor(data.alternate)
let text = '#FFFFFF'
if (luminance(background) > 0.5) {
text = '#000000'
}
const svg = `<svg xmlns="http://www.w3.org/2000/svg"
width="${data.size}" height="${data.size}"
viewBox="0 0 ${data.size} ${data.size}">
<rect width="100%" height="100%" fill="#${color}"/>
<rect width="100%" height="100%" fill="#${background}"/>
<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle"
font-weight="${data.font.weight}" font-family="${data.font.family}"
font-size="${data.size / 3}" fill="${luminance(color) > 0.5 ? '#000000' : '#FFFFFF'}">
font-size="${data.size / 3}" fill="${text}">
${data.caption}
</text>
</svg>`