kopia lustrzana https://github.com/badgen/badgen
Optimize performance
rodzic
a8cb2f32af
commit
b7c0ad38c0
|
@ -10,9 +10,15 @@ function calcWidth (charWidthTable) {
|
||||||
if (typeof text !== 'string') {
|
if (typeof text !== 'string') {
|
||||||
return 0
|
return 0
|
||||||
} else {
|
} else {
|
||||||
return Array.from(text).reduce((total, curr) => {
|
let total = 0
|
||||||
return total + (widthTable[curr.charCodeAt()] || widthTable[64]) // "@"
|
let i = text.length
|
||||||
}, 0)
|
let charCode = 0
|
||||||
|
while (i--) {
|
||||||
|
charCode = text[i].charCodeAt()
|
||||||
|
total += widthTable[charCode < 127 ? charCode : 64] // "@" for overflows
|
||||||
|
}
|
||||||
|
console.log(total)
|
||||||
|
return total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue