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

scss-color-similarity

v1.0.1

Published

Identify nearly identical color variables in SCSS files.

Downloads

13

Readme

SCSS Color Similarity

A tool to identify nearly identical color variables in SCSS files.

Installation

You can install this package globally to use it as a command-line tool or include it in your project as a dependency.

Global Installation

npm install -g scss-color-similarity

Local Installation

npm install scss-color-similarity

Usage

Command-Line Interface (CLI)

After installing globally, you can use the scss-color-similarity command.

scss-color-similarity <file> [options]

Options

  • -t, --threshold <number>: Threshold for color similarity (default is 10)

Example

scss-color-similarity colors.scss --threshold 5

This command will analyze colors.scss and report any color variables that are nearly identical within a distance of 5.

As a Library

You can also use this package in your Node.js projects.

Example Usage

const {
  parseScssColors,
  findSimilarColors,
} = require('scss-color-similarity');

const colorVars = parseScssColors('path/to/colors.scss');
const threshold = 10; // Adjust as needed
const similarPairs = findSimilarColors(colorVars, threshold);

console.log('Similar colors:', similarPairs);

How It Works

  • Parsing SCSS File: The tool reads your SCSS file and extracts all color variable declarations in the format $variable-name: #hexcode;.
  • Converting Hex to RGB: Hex color codes are converted to RGB values for numerical comparison.
  • Calculating Color Distance: Computes the Euclidean distance between all pairs of colors.
  • Identifying Similar Colors: Reports pairs of colors where the distance is less than the specified threshold.

Functions

  • parseScssColors(filename): Parses the SCSS file and returns an object of color variables and their hex codes.
  • hexToRgb(hexCode): Converts a hex color code to an RGB array.
  • colorDistance(rgb1, rgb2): Calculates the Euclidean distance between two RGB colors.
  • findSimilarColors(colorVars, threshold): Finds and returns pairs of color variables that are similar within the given threshold.

Example SCSS File

$blue: #036ad4;
$science_blue: #036ad8;
$royal_green: #1f641d;

Example Output

When running the CLI tool:

scss-color-similarity colors.scss --threshold 10

Output:

Colors that are nearly identical:
blue and science_blue (distance: 4.00)

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Author

Obie Munoz