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

get-similar-color

v1.1.4

Published

Get Similar Color is a TypeScript/JavaScript library that provides utility functions for finding a similar color within a color palette. You can easily use it in either a frontend project or a backend project. This library can assist you in quickly locati

Downloads

49

Readme

Get Similar Color

npm versionnpm downloads install size

Get Similar Color is a TypeScript/JavaScript library that provides utility functions for finding a similar color within a color palette. You can easily use it in either a frontend project or a backend project. This library can assist you in quickly locating colors that closely match a target color.

Installation

You can install the package using npm or yarn:

$ npm install get-similar-color
$ yarn add get-similar-color

Usage

Here's how you can use the Get Similar Color library in your TypeScript/JavaScript project:

JavaScript Example

const getSimilarColor = require("get-similar-color").default;

const defaultColorArray = [
  { name: "red", hex: "#ff0000" },
  { name: "green", hex: "#00ff00" },
  { name: "blue", rgb: { r: 0, g: 0, b: 255 } },
  { name: "yellow", hex: "#ffff00" },
  { name: "purple", rgb: { r: 128, g: 0, b: 128 } },
  { name: "orange", hex: "#ffa500" },
];

const findColor = getSimilarColor({
  targetColor: "#e30b0b",
  colorArray: defaultColorArray,
  similarityThreshold: 0.5,
});

console.log(findColor);

TypeScript Example

import getSimilarColor, { IDefaultColor } from "get-similar-color";

const defaultColorArray: IDefaultColor[] = [
  { name: "red", hex: "#ff0000" },
  { name: "green", hex: "#00ff00" },
  { name: "blue", rgb: { r: 0, g: 0, b: 255 } },
  { name: "yellow", hex: "#ffff00" },
  { name: "purple", rgb: { r: 128, g: 0, b: 128 } },
  { name: "orange", hex: "#ffa500" },
];

const findColor = getSimilarColor({
  targetColor: "#e30b0b",
  colorArray: defaultColorArray,
  similarityThreshold: 0.5,
});

console.log(findColor);

Console Output

The output will be either null or an object representing the most similar color:

{
  name: "red",
  hex: "#ff0000",
  rgb: {
    r: 255,
    g: 0,
    b: 0
  },
  similarity: 0.93
}

Features

  • getSimilarColor: Find a similar color from an array based on a target color and a similarity threshold.
  • IDefaultColor: Interface for default color array.
  • Support for Multiple Color Formats: HEX, RGB, HSL, and HSV formats.
  • Advanced Similarity Calculation: Uses the CIEDE2000 algorithm for more accurate color similarity calculations.

Advanced Features

The latest version of the Get Similar Color library includes several advanced features:

Support for Multiple Color Formats

In addition to HEX and RGB, the library now supports HSL (Hue, Saturation, Lightness) and HSV (Hue, Saturation, Value) color formats. This allows you to input and compare colors in a variety of formats.

HSL Example

const findColor = getSimilarColor({
  targetColor: { h: 240, s: 100, l: 50 },
  colorArray: defaultColorArray,
  similarityThreshold: 0.5,
});

console.log(findColor);

HSV Example

const findColor = getSimilarColor({
  targetColor: { h: 0, s: 100, v: 100 },
  colorArray: defaultColorArray,
  similarityThreshold: 0.5,
});

console.log(findColor);

Advanced Similarity Calculation

The library now includes an implementation of the CIEDE2000 algorithm for calculating color differences. This algorithm provides a more accurate measurement of color similarity compared to simple RGB or HEX comparisons.

Contributing

Contributions are welcome! If you have any bug reports, feature requests, or would like to contribute code, please open an issue or submit a pull request.

License

MIT License

Npm

NPM