1.0.9 โ€ข Published 3 years ago

@carlos-dubon/chroma v1.0.9

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

Chroma

banner

๐ŸŽจ 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.

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago