1.0.9 โข Published 3 years ago
@carlos-dubon/chroma v1.0.9
Chroma
๐จ Chroma is a JavaScript/TypeScript library for obtaining the GitHub color of any language.
Getting started
Installation
npm install @carlos-dubon/chroma
- ๐งน 0 Dependencies
- ๐ฆ 6.5kB Minified + Gzipped
- โก Blazing fast
API
It's easy to use Chroma to get the GitHub color of any language
import Chroma from "@carlos-dubon/chroma";
const c: Chroma = new Chroma();
c.get("JavaScript") //"#f1e05a"
c.get("Haskell"); //"#5e5086"
c.get("javascript") //"#f1e05a" ๐ Notice that Chroma is NOT case-sensitive
A powerfull options object
import Chroma from "@carlos-dubon/chroma";
import { Mode } from "@carlos-dubon/chroma/lib/models/mode.enum";
import { InstanceOptions } from "@carlos-dubon/chroma/lib/models/options.interface"; //๐
const options: InstanceOptions = {
colorMode: Mode.rgb,
opacity: 0.8,
rgbAsArray: false,
};
const c: Chroma = new Chroma(options);
c.get("Java"); //"rgba(176,114,25,0.8)"
c.get("PHP"); //"rgba(79,93,149,0.8)"
Overwrite global options
import Chroma from "@carlos-dubon/chroma";
import { Mode } from "@carlos-dubon/chroma/lib/models/mode.enum";
import { InstanceOptions } from "@carlos-dubon/chroma/lib/models/options.interface";
const options: InstanceOptions = {
colorMode: Mode.rgb,
opacity: 0.2,
};
const c: Chroma = new Chroma(options);
c.get("C"); //"rgba(85,85,85,0.2)"
c.get("Python", { opacity: 0.5, rgbAsArray: true }); //[ 53, 114, 165, 0.5 ] ๐
Set your own custom languages or overwrite default ones
import Chroma from "@carlos-dubon/chroma";
import { ColorRgb } from "@carlos-dubon/chroma/lib/models/color.interface"; //๐
import { InstanceOptions } from "@carlos-dubon/chroma/lib/models/options.interface";
const customLanguages: ColorRgb[] = [
{ language: "My cool lang", rgb: [36, 32, 1] },
{ language: "This is awesome", rgb: [23, 44, 51] },
{ language: "HTML", rgb: [255, 255, 255] },
];
const options: InstanceOptions = {
set: customLanguages, //๐
opacity: 0.5,
};
const c: Chroma = new Chroma(options);
c.get("my cool lang"); //"#80242001"
c.get("this is awesome"); //"#80172c33"
c.get("HTML", { opacity: 1 }); //"#ffffff"
โ ๏ธ 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 Chroma from "@carlos-dubon/chroma";
const c: Chroma = new Chroma();
c.get("FakeScript"); //"#ededed" ๐
Console output:
"FakeScript" doesn't have a default color. Please refer to https://github.com/carlos-dubon/chroma on how to set a default color for "FakeScript"
To remove this warnings set them to false
in the options object
import Chroma from "@carlos-dubon/chroma";
const c: Chroma = new Chroma({ warnings: false });
c.get("FakeScript"); //"#ededed" ๐ no console warning this time
๐ To change the default color set it in the options object as follows:
import Chroma from "@carlos-dubon/chroma";
const c: Chroma = new Chroma({ defaultRgbColor: [235, 107, 52], warnings: false });
c.get("FakeScript"); //"#eb6b34" ๐
๐ค Not sure what is the correct name for a language?
Use the similarTo
method to get a list with similar languages that exist in Chroma
import Chroma from "@carlos-dubon/chroma";
const c: Chroma = new Chroma();
c.similarTo("sql"); //["PLpgSQL", "PLSQL", "SQL", "SQLPL", "TSQL"] ๐
c.similarTo("py"); //["Jupyter Notebook", "NumPy", "Papyrus", "Python", "Python console", "Python traceback", "Ren'Py"] ๐
.similarTo("")
will get you a list of all the languages in Chroma ๐
License
Chroma is licensed under a MIT License.