@advdominion/css-var

This commit is contained in:
2026-02-12 14:52:31 +04:00
parent a0074442ae
commit 8f2cae3401
4 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
export const cssVar = (name, element = document.documentElement) => {
const value = window.getComputedStyle(element).getPropertyValue(name);
const durationRegExp = /(^[\d.]+)(ms|s)$/;
if (durationRegExp.test(value)) {
const [, numericValue, unit] = durationRegExp.exec(value);
return unit === 's' ? numericValue * 1000 : Number(numericValue);
}
return value;
};