(text: string, className = "", containerElement = document.body)
| 19 | * Should only be used if measuring can't be done with existing DOM elements. |
| 20 | */ |
| 21 | export function measureTextWidth(text: string, className = "", containerElement = document.body) { |
| 22 | if (containerElement == null) { |
| 23 | return 0; |
| 24 | } |
| 25 | const span = document.createElement("span"); |
| 26 | span.classList.add(className); |
| 27 | span.textContent = text; |
| 28 | |
| 29 | containerElement.appendChild(span); |
| 30 | const spanWidth = span.offsetWidth; |
| 31 | span.remove(); |
| 32 | |
| 33 | return spanWidth; |
| 34 | } |
| 35 | |
| 36 | export function padWithZeroes(str: string, minLength: number) { |
| 37 | if (str.length < minLength) { |
no test coverage detected