New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

unit-styl

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unit-styl

Unit conversion in Stylus made easy

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

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

Keywords

stylus

FAQs

Package last updated on 19 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts