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

css-recolor

v1.0.7

Published

Replace CSS colors base on SCSS file or a JSON file.

Downloads

4

Readme

css-recolor

基于SCSS文件的变量定义或JSON配置文件来替换CSS文件中的颜色值。

特性

  • 可根据已存在的SCSS文件的变量定义(或其他类似$variable: #rrggbb语法的文件)和JSON配置文件替换颜色
  • 可批量替换,支持文件夹整体或多文件传参
  • 支持识别简单颜色格式,如$purple: #f0a;,同时也会将CSS中的 #ff00aa 替换为 $purple,反之,如果是变量本身长格式也会查找短格式

注意

  • 如果没有指定-s和-c而且同时在默认位置存在SCSS文件和JSON文件,或者同时指定了-s和-c,将只使用SCSS
  • SCSS文件中的变量声明应单独占一行。(太懒了,不想多做检测,后续可能会改)
  • 如果需要注释掉SCSS中的变量声明,请使用单行注释 // $red: #ff0000;,这样不会输出到CSS文件中,而且替换时也不会替换这个注释的声明的变量 (使用多行注释的时候,这个声明还是会被加入到CSS替换中)

安装

推荐使用 -g 安装:

npm install -g css-recolor

用法

进入相应需要替换的目录,打开命令行,执行recolor并带上选项和需要转换的文件:

recolor -vr -o ./scss2 -n qwd.{name}.scss ./css some.css another.css

通过-s或者默认SCSS文件(./scss/common/_colors.scss)来替换时,直接是根据颜色声明来识别的变量, 同时在替换后的CSS文件中,会加上 @import scss/relative/path 。如果SCSS文件名是以_开头,增加import语句时会自动去掉_

通过-c或者默认JSON配置文件(./_colors.json)来替换时,key和value分别对应查找的颜色和替换的颜色。 scssImport 值可以用来添加 @import scss/relative/path 这个语句,没有时则不添加。 与使用SCSS不同,如果scssImport属性的文件名有开头的_,不会去除。如果不需要_,在增加scssImport时请不要加_即可。

{
    "scssImport": "path/to/scss/file",
    "#ff0000": "#ee0000",
    "#ff00ff": "$purple"
}

可以通过 -o 参数指定导出的文件夹,默认导出文件夹为 ./scss/

可以通过 -n 参数指定替换后生成的文件名,其中 {name} 表示原有文件名(不含.css后缀)。默认的替换后的文件名为 {name}-converted.scss

更多参考,请运行recolor -h