@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
14 lines (13 loc) • 413 B
JavaScript
import { isJsdom } from '../constants';
import { getComputedStyleAsNumber } from './getComputedStyleAsNumber';
/**
* Get the width of an element.
*
* This helper allows getting of the width when running in a JSDOM environment.
*/
export function getElementWidth(element) {
if (isJsdom) {
return getComputedStyleAsNumber(element, 'width');
}
return element.getBoundingClientRect().width;
}