GitXplorerGitXplorer
K

convert-css-length

public
37 stars
0 forks
4 issues

Commits

List of commits on branch master.
Verified
588560d668aa46d5e17bb5dab741db44227a77c0

Merge pull request #8 from KyleAMathews/dependabot/npm_and_yarn/ini-1.3.7

KKyleAMathews committed 4 years ago
Verified
9d6ca9a3a99c82db57a4c8a01eda1c9441347bcf

Merge pull request #6 from KyleAMathews/dependabot/npm_and_yarn/acorn-6.4.1

KKyleAMathews committed 4 years ago
Verified
5a491778096e43776df1ec2cb40c14b5a8c48951

Merge pull request #9 from KyleAMathews/dependabot/npm_and_yarn/lodash-4.17.21

KKyleAMathews committed 4 years ago
Verified
eb2c9bcf85ee6575f90b6dfa9b08a6e4103a6948

Bump lodash from 4.17.11 to 4.17.21

ddependabot[bot] committed 4 years ago
Verified
cc02c45636ebc3d39025ecfa44bf901b1e34537d

Bump ini from 1.3.5 to 1.3.7

ddependabot[bot] committed 4 years ago
Verified
cd2ecb19c7736d977ae054a0093fa8849fcd7f4d

Bump acorn from 6.2.0 to 6.4.1

ddependabot[bot] committed 5 years ago

README

The README file for this repository.

convert-css-length

Convert between css lengths e.g. em->px or px->rem

Conversions between em, ex, rem, px are supported. PRs welcome if you need support for more esoteric length units.

[Note: algorithm was originally ported from Compass] (https://github.com/Compass/compass/blob/master/core/stylesheets/compass/typography/_units.scss)

Install

npm install convert-css-length

Usage

import convertLength from 'convert-css-length';

// Set the baseFontSize for your project. Defaults to 16px (also the
// browser default).
var convert = convertLength('21px');

// Convert rem to px.
convert('1rem', 'px');
// ---> 21px

// Convert px to em.
convert('30px', 'em');
// ---> 1.42857em

// Convert em to pixels using fromContext.
// em(s) are relative to the font-size at the same element. If you're setting an em on a element whose font-size
// is different than the base font size, you'll need to pass that font-size as the third parameter.
// Or just use rem instead which sizes everything relative to the base node.
convert('1em', 'px', '14px')
// ---> 14px