Skip to content
helps shorten units for cssbattle.dev
Branch: master
Clone or download
Latest commit a4eb396 Apr 10, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src More robust cli Apr 10, 2019
.gitignore Use puppeteer to generate unit ratios (#5) Apr 10, 2019
LICENSE Initial commit Apr 8, 2019
README.md readme nits Apr 10, 2019
package.json
yarn.lock More robust cli Apr 10, 2019

README.md

Helps shorten units for cssbattle.dev

Installation

yarn global add unit-golf || npm install --global unit-golf

Usage

$ unit-golf [VALUE_TO_CONVERT]

Where VALUE_TO_CONVERT is any whole or fractional number of the following units:

px, vw, vh, in, cm, mm, pt, pc, em, ex, q, ch

If the unit is ommitted (eg, unit-golf 325) it will default to pixels.

Options

--tolerance

Maximum difference in pixels that will be considered a match for a value. Defaults to 0.5. Decreasing will yield more exact but less concise results and vice versa.

--width

Viewport width for the purpose of calculating vw units. Defaults to 400, which is what cssbattle currently uses.

--height

Viewport height for the purpose of calculating vh units. Defaults to 300, which is what cssbattle currently uses.

Examples

$ unit-golf 57.3vw

⛳  32ex (-0.19px)

172pt (+0.14px)
229px (-0.19px)
57.3vw (+0.01px)
76.4vh (+0.01px)
242.6q (+0.03px)
6.06cm (-0.15px)
60.6mm (-0.15px)
28.65ch (+0.01px)
14.32pc (-0.07px)
14.32em (-0.07px)
2.39in (+0.25px)
$ unit-golf 57.3vw --tolerance 0

⛳  242.57q

60.64mm
171.89pt
...

Parens indicate how many pixels off each suggestion is from the target.

You can’t perform that action at this time.