1.0.6 • Published 3 years ago

gh-colors v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

gh-colors

🎨 gh-colors is a JavaScript/TypeScript library for obtaining the color GitHub assigns to a language.

Highlights

  • 🧹 0 Dependencies
  • 📦 6.5kB Minified + Gzipped
  • ⚡ Blazing fast

Install

npm install gh-colors

Or

yarn add gh-colors

Usage

import GhColors from "gh-colors";

const gh = new GhColors();

console.log(gh.get("javascript")); //#f1e05a

Options

Set an opacity

OptionTypeDescription
opacitynumberA number between 0 and 1

JavaScript:

import GhColors from "gh-colors";

const gh = new GhColors({
  opacity: 0.8,
});

console.log(gh.get("javascript")); //#ccf1e05a
import GhColors, { Options } from "gh-colors";

const options: Options = {
  opacity: 0.8,
};

const gh = new GhColors(options);

console.log(gh.get("javascript")); //#ccf1e05a

Change the color mode

OptionTypeDescription
colorModestring"rgb" or "hex"

JavaScript:

import GhColors from "gh-colors";

const gh = new GhColors({
  colorMode: "rgb",
});

console.log(gh.get("haskell")); //rgb(94,80,134)
import GhColors, { Options } from "gh-colors";

const options: Options = {
  colorMode: "rgb",
};

const gh = new GhColors(options);

console.log(gh.get("haskell")); //rgb(94,80,134)

Return RGB as an Array

OptionTypeDescription
rgbAsArraybooleantrue or false

JavaScript:

import GhColors from "gh-colors";

const options = {
  colorMode: "rgb",
  rgbAsArray: true,
};

const gh = new GhColors(options);

console.log(gh.get("python")); //[ 53, 114, 165 ]
import GhColors, { Options } from "gh-colors";

const options: Options = {
  colorMode: "rgb",
  rgbAsArray: true,
};

const gh = new GhColors(options);

console.log(gh.get("python")); //[ 53, 114, 165 ]

Set custom languages or override the default ones

OptionTypeDescription
setobject[]An array of objects that contain a name and a RGB color

JavaScript:

import GhColors from "gh-colors";

const customLanguages = [
  {
    name: "fakescript",
    rgb: [255, 255, 255],
  },
  {
    name: "HTML",
    rgb: [0, 0, 0],
  },
];

const gh = new GhColors({
  set: customLanguages,
});

console.log(gh.get("fakescript")); //#ffffff
console.log(gh.get("HTML")); //#000000
import GhColors, { Options, ColorRgb } from "gh-colors";

const customLanguages: ColorRgb[] = [
  {
    name: "fakescript",
    rgb: [255, 255, 255],
  },
  {
    name: "HTML",
    rgb: [0, 0, 0],
  },
];

const options: Options = {
  set: customLanguages,
};

const gh = new GhColors(options);

console.log(gh.get("fakescript")); //#ffffff
console.log(gh.get("HTML")); //#000000

Remove console warnings

OptionTypeDescription
warningsbooleanif set to false no warnings will show up in your console

When you try to get a language that doesn't exist a warning will show up in your console and the default color #ededed will be set to that language.

import GhColors from "gh-colors";

const gh = new GhColors();

console.log(gh.get("fakescript")); //#ededed

Console warning:

"fakescript" doesn't have a default color. Please refer to https://github.com/carlos-dubon/gh-colors on how to set a default color for "fakescript"

To remove these warnings set them to false in the options

import GhColors from "gh-colors";

const gh = new GhColors({
  warnings: false,
});

console.log(gh.get("fakescript")); //#ededed no warning this time
import GhColors, { Options } from "gh-colors";

const options: Options = {
  warnings: false,
};

const gh = new GhColors(options);

console.log(gh.get("fakescript")); //#ededed no warning this time

Change the default color

OptionTypeDescription
defaultRgbColornumber[]A RGB color
import GhColors from "gh-colors";

const gh = new GhColors({ defaultRgbColor: [235, 107, 52] });

console.log(gh.get("fakescript")); //#eb6b34
import GhColors, { Options } from "gh-colors";

const options: Options = { defaultRgbColor: [235, 107, 52] };

const gh = new GhColors(options);

console.log(gh.get("fakescript")); //#eb6b34

Not sure what is the correct name for a language?

import GhColors from "gh-colors";

const gh = new GhColors();

console.log(gh.similarTo("sql")); //["PLpgSQL", "PLSQL", "SQL", "SQLPL", "TSQL"]
console.log(gh.similarTo("py")); //["Jupyter Notebook", "NumPy", "Papyrus", "Python", "Python console", "Python traceback", "Ren'Py"]

License

gh-colors is licensed under a MIT License.

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago