1.1.3 • Published 9 months ago

get-similar-color v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Get Similar Color

npm version npm 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,
    // min :0.01 max: 1 not required default 0.8
    similarityThreshold: 0.5,
});

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" },
    ];
// return type ISimilarColor | null 
const findColor = getSimilarColor({
    targetColor: "#e30b0b",
    colorArray: defaultColorArray,
    // min :0.01 max: 1 not required default 0.8
    similarityThreshold: 0.5,
});

Console output null or object:

{
    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.

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

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago