ends a value with a unit
Do that?
const width = 100
document.querySelector('div').style.width = `${width}px`
Please, don't. Use strunit
!
yarn add strunit
import { px } from 'strunit'
const width = 100
document.querySelector('div').style.width = px(width)
Pixels
px(42) // => '42px'
px('69') // => '69px'
Points
pt(4.20) // => '4.20pt'
pt('3.141592653') // => '3.141592653pt'
Percents
pct(7) // => '7%'
pct('13') // => '13%'
Centimeters
cm(123) // => '123cm'
cm('4815162342') // => '4815162342cm'
Millimeters
mm(2012) // => '2012mm'
mm('88005553535') // => '88005553535mm'
Font size of the parent element
em(666) // => '666em'
em('911') // => '911em'
Font size of the root element
rem(21) // => '21rem'
rem('777') // => '777rem'
1% of the viewport's width
vw(100) // => '100vw'
vw('100') // => '100vw'
1% of the viewport's height
vh(100) // => '100vh'
vh('100') // => '100vh'
1% of the viewport's smaller dimension
vmin(1) // => '1vmin'
vmin('1') // => '1vmin'
1% of the viewport's larger dimension
vmax(99) // => '99vmax'
vmax('99') // => '99vmax'
Inches
inch(9) // => '9in'
inch('3.5') // => '3.5in'
Picas
pc(1881) // => '1881pc'
pc('1973') // => '1973pc'
Quarter-millimeters
Q(3.79) // => '3.79Q'
Q('4.79') // => '4.79Q'
X-height of the element's font
ex(1) // => '1ex'
ex('s') // => 'sex'
The advance measure (width) of the glyph "0" of the element's font
ch(0) // => '0ch'
ch('not') // => 'notch'
custom(63, 'region') // => '63region'
custom(43, 'ยฐC') // => '43ยฐC'