UNPKG

@qntm-code/utils

Version:

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

16 lines (15 loc) 655 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getComputedStyleAsNumber = void 0; const isNullOrUndefined_js_1 = require("../type-predicates/isNullOrUndefined.js"); /** * Gets the computed style of an element as a number. */ function getComputedStyleAsNumber(element, style) { const value = window.getComputedStyle(element)[style]; if ((0, isNullOrUndefined_js_1.isNullOrUndefined)(value)) { throw new Error(`Element does not have a computed "${style}`); } return parseFloat(getComputedStyle(element)[style].replace('px', '')); } exports.getComputedStyleAsNumber = getComputedStyleAsNumber;