npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tiger-ui/contrast-color

v1.0.3

Published

Install the package in your project directory with: ### npm: ``` npm install @tiger-ui/contrast-color ``` ### yarn: ``` yarn add @tiger-ui/contrast-color ```

Downloads

46

Readme

Contrast Color gives you the best color that can be used on a background color you specify.

Installation

Install the package in your project directory with:

npm:

npm install @tiger-ui/contrast-color

yarn:

yarn add @tiger-ui/contrast-color

Examples

Basic Usage:

import { contrastColor } from '@tiger-ui/contrast-color';

const myColor = '#226be0';

const contrast = contrastColor(myColor);

console.log('contrast color: ', contrast);

output:

'#FFFFFF'

Class Usage:

import ContrastColor from '@tiger-ui/contrast-color';

const myColor = '#226be0';

  const contrast = new ContrastColor(myColor);

  console.log('contrast color: ', contrast.get());

output:

'#FFFFFF'

Customizable Usage:

import { contrastColor } from '@tiger-ui/contrast-color';

const myColor1 = '#226be0';
const myColor2 = '#ff9696';

const contrast1 = contrastColor(
  myColor1,
  {
    lightColor: '#eeeeee',
    darkColor: '#0a0202',
  },
);

const contrast2 = contrastColor(
  myColor2,
  {
    lightColor: '#eeeeee',
    darkColor: '#0a0202',
  },
);

console.log('contrast1: ', contrast1);
console.log('contrast2: ', contrast2);

output:

'contrast1: #eeeeee'
'contrast2: #0a0202'

Class Usage:

import ContrastColor from '@tiger-ui/contrast-color';

const myColor1 = '#226be0';
const myColor2 = '#ff9696';

const contrast1 = new ContrastColor(
  myColor1,
  {
    lightColor: '#eeeeee',
    darkColor: '#0a0202',
  },
);

const contrast2 = new ContrastColor(
  myColor2,
  {
    lightColor: '#eeeeee',
    darkColor: '#0a0202',
  },
);

console.log('contrast1: ', contrast1.get());
console.log('contrast2: ', contrast2.get());

output:

'contrast1: #eeeeee'
'contrast2: #0a0202'

Practical

Let's make an example on React about Contrast Color:

import { contrastColor } from '@tiger-ui/contrast-color';

import Box from '../../components/Box';
import Paragraph from '../../components/Paragraph';

// --- COLORS --- //
const red = ['#FF0000', contrastColor('#FF0000')];
const lime = ['#00FF00', contrastColor('#00FF00')];
const blue = ['#0000FF', contrastColor('#0000FF')];
const yellow = ['#FFFF00', contrastColor('#FFFF00')];
const cyan = ['#00FFFF', contrastColor('#00FFFF')];
const magenta = ['#FF00FF', contrastColor('#FF00FF')];

export default function MyComponent() {
  return (
    <Box display="flex" justifyContent="center" my={10}>
      <Box
        width="200px"
        height="200px"
        display="flex"
        alignItems="center"
        justifyContent="center"
        bgColor={red[0]}
      >
        <Paragraph color={red[1]}>red</Paragraph>
      </Box>
      <Box
        width="200px"
        height="200px"
        display="flex"
        alignItems="center"
        justifyContent="center"
        bgColor={lime[0]}
      >
        <Paragraph color={lime[1]}>lime</Paragraph>
      </Box>
      <Box
        width="200px"
        height="200px"
        display="flex"
        alignItems="center"
        justifyContent="center"
        bgColor={blue[0]}
      >
        <Paragraph color={blue[1]}>blue</Paragraph>
      </Box>
      <Box
        width="200px"
        height="200px"
        display="flex"
        alignItems="center"
        justifyContent="center"
        bgColor={yellow[0]}
      >
        <Paragraph color={yellow[1]}>yellow</Paragraph>
      </Box>
      <Box
        width="200px"
        height="200px"
        display="flex"
        alignItems="center"
        justifyContent="center"
        bgColor={cyan[0]}
      >
        <Paragraph color={cyan[1]}>cyan</Paragraph>
      </Box>
      <Box
        width="200px"
        height="200px"
        display="flex"
        alignItems="center"
        justifyContent="center"
        bgColor={magenta[0]}
      >
        <Paragraph color={magenta[1]}>magenta</Paragraph>
      </Box>
    </Box>
  );
}

output:

image

As you can see, the text inside each box has adjusted itself to match the background color.

Special Thanks

This library is adapted from @busterc's contrast-color library and customized to our needs. We would like to thank @busterc for providing us with the library for the development of this library. We would like to express our special thanks to the resources we have used in the development of this library, which have been of great help to us:

  • https://github.com/busterc/contrast-color
  • https://www.npmjs.com/package/contrast-color?activeTab=readme