MCPcopy
hub / github.com/palantir/blueprint / measureTextWidth

Function measureTextWidth

packages/datetime/src/common/utils.ts:21–34  ·  view source on GitHub ↗
(text: string, className = "", containerElement = document.body)

Source from the content-addressed store, hash-verified

19 * Should only be used if measuring can't be done with existing DOM elements.
20 */
21export 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
36export function padWithZeroes(str: string, minLength: number) {
37 if (str.length < minLength) {

Callers 1

positionArrowsMethod · 0.90

Calls 2

addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected