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

high-pxtorem

v1.0.10

Published

一个超级好用的pxtorem

Downloads

9

Readme

在开发页面的时候我们经常需要把px转成rem,比如:

width:100px;

// 如果 html 的front-size设置成为37.5px;
width:100/37.5rem;// 或者
width:2.666665rem;

这样我们不写注释,可能都不知道原来的px是多少。非常麻烦。 postcss-pxtorem 可以解决这个问题, 基本用法:

var px2rem = require('postcss-plugin-px2rem')

px2rem({
  // base on 750px standard.
  rootValue: 75,
  // to leave 1px alone.
  minPixelValue: 1.01
})

这个插件有一些问题;不能满足我们现在公司的需求,我们公司的页面,既有640的,也有750的。还有可能有些不想转rem;这样的情况上面的插件就无法满足了,于是自己写了一个插件。

Install

$ cnpm install --save-dev high-pxtorem

Usage

/*
---
rootSize:37.5,
noTransformFlag:-no-,
toFixed:6
---
*/

body {
  width: 100px;
  border: 1px solid red;

  a {
    border: 37.5px solid wheat;
  }
}

body{
  width:2.666667rem;
  border:.026667rem solid red
  }
body a{
  border:1rem solid wheat
}

Example

// postcss.config.js
module.exports = {
    syntax: require('postcss-less'),//此处可以换
    plugins: [
        require('postcss-import')(),
        require('postcss-url')(),
        require('autoprefixer')({
            'overrideBrowserslist': [
                '> 0.1%',
                'Android >= 4.1',
                'ios >= 8',
                'not ie < 12'
            ]
        }),
        require('high-pxtorem')({})

    ]
};

options

 var defaultObj = {
        rootSize: '37.5',// 与html font-size相同
        noTransformFlag: '-no-',// 此注释前面不进行rem转义
        toFixed: 6,//精度
        whiteTagList: ['width'],//不转rem的属性,
        whiteSelectorList: ['.a','#app']// 不转rem的选择器
    };