Random Color Library can be used to generate random colors. For the initial release only the Material Color palette can be used to generate a color, but Tailwind will soon be added as well as a more generic option.
A consistent color can be generated from text. When text is provided, the same random color will always be returned for the given text.
Install using your preferred package manager, or download the latest version from Releases.
npm install random-color-library
Coming soon
Coming soon
import { randomMaterialColor } from "random-color-library";
const color = randomMaterialColor();
// Returns a hex color
const color = randomMaterialColor("text to use");
// Returns a consistent hex color for the text
const color = randomMaterialColor({ colors: ["red", "yellow"] });
// Returns a hex color from the "red" or "yellow" color group
const color = randomMaterialColor({ shades: ["500", "700"] });
// Returns a hex color from the "500" or "700" shade
const color = randomMaterialColor({ excludeColors: ["red", "yellow"] });
// Returns a hex color not from the "red" or "yellow" color group
const color = randomMaterialColor({ excludeShades: ["500", "700"] });
// Returns a hex color not from the "500" or "700" shade
const color = randomMaterialColor("string to use", {
colors: ["red", "yellow"],
shades: ["500", "700"],
});
// Returns a consistent hex color for the text and options
const color = randomMaterialColor("string to use", {
excludeColors: ["red", "yellow"],
excludeShades: ["500", "700"],
});
// Returns a consistent hex color for the text and options
Random Color Library uses Bun as a package manager and test runner.
bun install
bun run test
bun run test:watch
bun run lint
bun run format
bun run build