0.1.1 • Published 8 months ago

random-color-library v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Random Color Library

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.

Installation

Install using your preferred package manager, or download the latest version from Releases.

npm install random-color-library

Random Colors

Coming soon

Tailwind Colors

Coming soon

Material Colors

import { randomMaterialColor } from "random-color-library";

Generate a Random Color

// Returns a hex color
const color = randomMaterialColor();

Generate a Consistent Random Color from Text

// Returns a consistent hex color for the text.
const color = randomMaterialColor("text to use");

Specify Colors

// Returns a hex color from the "red" or "yellow" color group.
const color = randomMaterialColor({ colors: ["red", "yellow"] });

Specify Shades

// Returns a hex color from the "500" or "700" shade.
const color = randomMaterialColor({ shades: ["500", "700"] });

Exclude Colors

// Returns a hex color not from the "red" or "yellow" color group.
const color = randomMaterialColor({ excludeColors: ["red", "yellow"] });

Exclude Shades

// Returns a hex color not from the "500" or "700" shade.
const color = randomMaterialColor({ excludeShades: ["500", "700"] });

Combine Colors and Shades

// Returns a consistent hex color for the text and options.
const color = randomMaterialColor("string to use", {
  colors: ["red", "yellow"],
  shades: ["500", "700"],
});

Combine Exclude Colors and Exclude Shades

// Returns a consistent hex color for the text and options.
const color = randomMaterialColor("string to use", {
  excludeColors: ["red", "yellow"],
  excludeShades: ["500", "700"],
});

Development

Random Color Library uses Bun as a package manager and test runner.

Installation

bun install

Run tests once

bun run test

Run tests and watch for changes

bun run test:watch

Linting

Lint with ESLint

bun run lint

Format with Prettier

bun run format

Building

bun run build