npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-rem-phi-units

v0.1.2

Published

Extra units for easy rem and phi based layouts

Downloads

9

Readme

PostCSS Rem Phi Units

PostCSS plugin to add extra units for easy rem and phi based layouts

Converting px to rem

This plugin gives you the ability to easily generate rem based layouts while being able to think in the easier to wrangle px unit. Instead of dealing with post processor functions, variables or manual conversions just write:

width: 160px/rem;

...and your output will be:

width: 10rem;

This gives you full control over exactly which values get converted into rem values, as sometimes px units are specifically needed.

Note: If you prefer not to use the / character in your units you can change your options to use any conversion character you choose.

Alternatively you can just use the px unit alone and set the plugin to automatically convert all px values to rem.

Using phi as a Unit

Additionally, the unit phi is introduced to make it easy to utilize the golden ratio in your designs. For example:

padding: 1phi;
margin: 2phi;

...will compile to:

padding: 1.618rem;
margin: 3.236rem;

You can also specify whether you want your phi unit to compile to em or rem units:

padding: 1phi/rem;
margin: 2phi/em;

...will compile to:

padding: 1.618rem;
margin: 3.236em;

Using @rules for Options

Options, including converting all px values to rem, can be set within your stylesheet via @rules:

/* set to true to convert all px values to rem automatically */
@remphiunits convert-all-px false;
/* number of decimal places in rem values */
@remphiunits precision 3;
/* base font size rem values are calculated with */
@remphiunits base-font-size 16;
/* the character used for unit conversion, don't wrap in quotes, e.g. change / to -> */
@remphiunits conversion-character ->;

Installation

$ npm install postcss-rem-phi-units

Usage

Example Gulpfile

var gulp = require('gulp');
var postcss = require('gulp-postcss');

var units = require('postcss-rem-phi-units');

gulp.task('css', function () {
  var processors = [
    units
  ];
  return gulp.src('./src/style.css')
    .pipe(postcss(processors))
    .pipe(gulp.dest('./css'));
});

Use with Stylus

Note that postcss-rem-phi-units can work with Stylus, but it must be used via poststylus for example:

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var stylus = require('gulp-stylus');
var poststylus = require('poststylus');

var units = require('postcss-rem-phi-units');

gulp.task('stylus', function () {
  var processors = [
    units
  ];
  gulp.src('style.styl')
    .pipe(stylus({
      use: [
        poststylus(processors)
      ]
    }))
    .pipe(gulp.dest('./'))
});

Options

convert-all-px

Type: Boolean
Default: false

Set to true to convert all px values to rem automatically.

precision

Type: Number
Default: 3

Number of decimal places in rem values.

base-font-size

Type: Number
Default: 16

Base font size rem values are calculated with.

conversion-character

Default: /

the character used for unit conversion, don't wrap in quotes, e.g. change / to ->