Socket
Socket
Sign inDemoInstall

to-px

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    to-px

Convert any CSS unit to logical pixels ("px")


Version published
Weekly downloads
275K
decreased by-2.65%
Maintainers
1
Install size
12.1 kB
Created
Weekly downloads
 

Readme

Source

to-px

Get the scale factor to convert any CSS unit to px (logical pixel units).

testling badge

Example

var toPX = require('to-px')

console.log(toPX('1em'))
console.log(toPX('.23vh'))
console.log(toPX('in'))

Install

Note that this module only works within the DOM.

npm i to-px

API

var scaleFactor = require('to-px')(unit[, element])

Computes the number of pixels in the unit string.

  • unit is a CSS unit type or a number followed by CSS unit, eg vh or 2in
  • element is an optional element in which the unit is computed (default is document.body)

Returns The number of pixels in the unit

Note Conversions for % are not supported since they are context dependent.

License

(c) 2015 Mikola Lysenko. MIT License

Keywords

FAQs

Last updated on 19 Nov 2018

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