Socket
Socket
Sign inDemoInstall

@bgschiller/unitconversion

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @bgschiller/unitconversion

Simple SCSS functions for unitconversion


Version published
Weekly downloads
32
increased by33.33%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

_unitconversion.scss (v.2.2.13)

This is a fork of https://github.com/jakob-e/unitconversion. The only difference is that I've applied the sass division migration.

Convert Anything (almost)

At the moment the following units are supported (please comment if something is wrong/missing):

px, pt, pc, in, mm, cm, em, rem, ex, ch, vw, vh, vmin, vmax,
deg, rad, grad, turn, dpi, dpcm, dppx, s, ms, hz, khz, number,
ratio

NPM

npm install @bgschiller/unitconversion

Simple Syntax

Rather than going with the "good" old fromUnit-to-toUnit(fromUnit) syntax this function set is based on toUnit(fromUnit) making it a lot shorter and less cumbersome to maintain – as shown below :-)

       pt-to-px(input);
       pc-to-px(input);
       in-to-px(input);
       mm-to-px(input);    ==>   px(input);
       cm-to-px(input);
       em-to-px(input);
       rem-to-px(input);
       num-to-px(input);

Note!

  • To allow conversion between relative and absolute lengths em and rem are calculated as pixel values based on $root-font-size and $base-font-size (16px browser default). If you change the base font size of your document – remember to set the $root-font-size and $base-font-size variables accordingly.

  • To ease the job of handling compounds the em function takes multiple arguments. Each argument is treated as an em compound and used to calculate the visual size. Example – how to set a visual size of 18px on a class nested in an element with a font-size of 2em:

      .class {
          font-size: em(18px, 2em);  ==>   0.5625em;
      }
  • If you use unit conversion in relation to the font shorthand syntax be aware that line-height "/" will cause division. To prevent this from happening you can either either interpolate the value or use + to add the pieces together without calculation:
      h2 {
          font:300 #{em(24px)}/3 'Lato', sans-serif;
      }
Conversion table
TypeFunctionInput units
Absolute lengthpx($input);px, pt, pc, in, mm, cm, em, rem, number
pt($input);px, pt, pc, in, mm, cm, em, rem, number
pc($input);px, pt, pc, in, mm, cm, em, rem, number
in($input);px, pt, pc, in, mm, cm, em, rem, number
mm($input);px, pt, pc, in, mm, cm, em, rem, number
cm($input);px, pt, pc, in, mm, cm, em, rem, number
Relative lengthem($input);px, pt, pc, in, mm, cm, em, rem, number
rem($input);px, pt, pc, in, mm, cm, em, rem, number
ex($input);ex, number
ch($input);ch, number
vw($input);vw, number
vh($input);vh, number
vmin($input);vmin, number
vmax($input);vmax, number
Angle deg($input);deg, rad, grad, turn, number
rad($input);deg, rad, grad, turn, number
grad($input);deg, rad, grad, turn, number
turn($input);deg, rad, grad, turn, number
Resolution dpi($input);dpi, dpcm, dppx, number
dpcm($input);dpi, dpcm, dppx, number
dppx($input);dpi, dpcm, dppx, number
Time ms($input);ms, s, number
s($input); ms, s, number
Frequency hz($input);Hz, kHz, number
khz($input);Hz, kHz, number
String str($input);
string($input);
Anything not null
Number num(input);
number($input)
px, pt, pc, in, mm, cm, em, rem, ex, ch,
vw, vh, vmin, vmax, deg, rad, grad, turn,
dpi, dpcm, dppx, s, ms, hz, khz, number
int($input);px, pt, pc, in, mm, cm, em, rem, ex, ch,
vw, vh, vmin, vmax, deg, rad, grad, turn,
dpi, dpcm, dppx, s, ms, hz, khz, number
uint($input);px, pt, pc, in, mm, cm, em, rem, ex, ch,
vw, vh, vmin, vmax, deg, rad, grad, turn,
dpi, dpcm, dppx, s, ms, hz, khz, number

Cive it a try on: Sassmeister.com


The MIT License (MIT) Copyright (c) 2016 Jakob Eriksen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 29 Sep 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc