1.0.6 • Published 4 years ago
gh-colors v1.0.6
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-colorsOr
yarn add gh-colorsUsage
import GhColors from "gh-colors";
const gh = new GhColors();
console.log(gh.get("javascript")); //#f1e05aOptions
Set an opacity
| Option | Type | Description |
|---|---|---|
| opacity | number | A number between 0 and 1 |
JavaScript:
import GhColors from "gh-colors";
const gh = new GhColors({
opacity: 0.8,
});
console.log(gh.get("javascript")); //#ccf1e05aimport GhColors, { Options } from "gh-colors";
const options: Options = {
opacity: 0.8,
};
const gh = new GhColors(options);
console.log(gh.get("javascript")); //#ccf1e05aChange the color mode
| Option | Type | Description |
|---|---|---|
| colorMode | string | "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
| Option | Type | Description |
|---|---|---|
| rgbAsArray | boolean | true 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
| Option | Type | Description |
|---|---|---|
| set | object[] | 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")); //#000000import 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")); //#000000Remove console warnings
| Option | Type | Description |
|---|---|---|
| warnings | boolean | if 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")); //#edededConsole 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 timeimport GhColors, { Options } from "gh-colors";
const options: Options = {
warnings: false,
};
const gh = new GhColors(options);
console.log(gh.get("fakescript")); //#ededed no warning this timeChange the default color
| Option | Type | Description |
|---|---|---|
| defaultRgbColor | number[] | A RGB color |
import GhColors from "gh-colors";
const gh = new GhColors({ defaultRgbColor: [235, 107, 52] });
console.log(gh.get("fakescript")); //#eb6b34import GhColors, { Options } from "gh-colors";
const options: Options = { defaultRgbColor: [235, 107, 52] };
const gh = new GhColors(options);
console.log(gh.get("fakescript")); //#eb6b34Not 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.