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

unit-styl

v0.1.2

Published

Unit conversion in Stylus made easy

Downloads

4

Readme

unit.styl npm version

...makes it easy to convert relative and absolute units. Use the unit of your choice and don't worry about it.

See docs.

install

Just clone this project, or download it via npm.

$ npm install unit-styl

--save or --save-dev flags are recommended.


JavaScript API

var stylus = require('stylus'),
    unit   = require('unit-styl');

function compile(str) {
  return stylus(str)
    .use(unit());
}

Stylus API

@import 'unit'

You can also import individual parts:

@import 'unit/_angle'
@import 'unit/_length'
@import 'unit/_resolution'
@import 'unit/_time'

The just-use-it way

@import 'node_modules/unit-styl/unit'

Check whether the node_modules path is correct.

documentation

→ relative ⇔ absolute

Relative units can be absolute and absolute units can be relative! :-)

A context is required for relative units (rem, %). Only conversions between pxpt don't require context.

EXAMPLE 1 (no context needed)
.foo {
  width:     pt(500px);       /*  width: 375pt; */
  height:    px(12pt);        /*  height: 16px;  */
}  
EXAMPLE 2
context = 100%;

.foo {
  width:     rem(960px);      /*  height: 60rem;   */
  height:    pct(3pt);        /*  height: 25%;     */
  font-size: px(1rem);        /*  font-size: 16px; */
}  
EXAMPLE 3
context = 62.5%;

.foo {
   width:     px(8rem)        /*  width: 80px;  */
   height:    rem(10px)       /*  height: 1rem;  */
   font-size: pct(5px)        /*  font-size: 50%; */
}

Tip: You can do fallbacks for IE to rem unit printing the results in pixels too, e.g. px(1.5rem)

--

→ angles: degradturngrad

EXAMPLE 1
transform: rotateY(deg(0.5turn));         /* transform: rotateY(180deg) */
EXAMPLE 2
transform: rotateX(rad(200grad));         /* transform: rotateX(3.14rad); */

--

→ time: mss

EXAMPLE 1
transition-duration: millisec(1s);         /* transition-duration: 500ms */
EXAMPLE 2
transition-duration: sec(5000ms);          /* transition-duration: 0.5s; */

sec() takes a second parameter: leadingzero, an optional boolean - true by default. If false, leading zero is omitted.

transition-duration: sec(5000ms, false);   /* transition-duration: .5s; */

LICENSE

MIT © Diéssica Gurskas