UNPKG

@qntm-code/utils

Version:

A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.

12 lines (11 loc) 447 B
import { isNullOrUndefined } from '../type-predicates/isNullOrUndefined.js'; /** * Gets the computed style of an element as a number. */ export function getComputedStyleAsNumber(element, style) { const value = window.getComputedStyle(element)[style]; if (isNullOrUndefined(value)) { throw new Error(`Element does not have a computed "${style}`); } return parseFloat(getComputedStyle(element)[style].replace('px', '')); }