via npm
npm install gist:0f2e28342bfcf5c39567b1f210c82d58 --save
via git
git clone https://gist.github.com/burdiuz/0f2e28342bfcf5c39567b1f210c82d58 CSSValue
class CSSValue { | |
static toPx(value) { | |
CSSValue._element.style.fontSize = value; | |
return window.getComputedStyle(CSSValue._element).fontSize; | |
} | |
static toInt(value) { | |
return parseInt(CSSValue.toPx(value)); | |
} | |
static toNumber(value) { | |
return parseFloat(CSSValue.toPx(value)); | |
} | |
} | |
CSSValue._element = (() => { | |
const el = document.createElement('span'); | |
el.style.display = 'none'; | |
document.body.appendChild(el); | |
return el; | |
})(); |
{ | |
"name": "CSSValue", | |
"version": "0.0.1", | |
"main": "CSSValue.js" | |
} |