@wojtekmaj/color-utils

    2.1.0 • Public • Published

    npm downloads CI dependencies dev dependencies tested with jest

    Color-Utils

    A collection of color-related utilities.

    tl;dr

    • Install by executing npm install @wojtekmaj/color-utils or yarn add @wojtekmaj/color-utils.
    • Import by adding import * as colorUtils from '@wojtekmaj/color-utils'.
    • Do stuff with it!
      toRgb('#ff0000'); // "rgb(255, 0, 0)"

    User guide

    alpha()

    Adds/changes alpha channel in a given color.

    Sample usage

    import { alpha } from '@wojtekmaj/color-utils';
    
    alpha('#f00', 0.5); // "rgba(255, 0, 0, 0.5)"
    alpha('#00ff00', 0.1); // "rgba(0, 255, 0, 0.1)"
    alpha('#0000ff80', 0.1); // "rgba(0, 0, 255, 0.1)"
    alpha('rgb(255, 0, 0)', 0.5); // "rgba(255, 0, 0, 0.5)"
    alpha('rgba(0, 0, 255, 0.5)', 0.1); // "rgba(0, 0, 255, 0.1)"

    mix()

    Mixes colors together. If ratio is not given, colors are blended evenly (ratio = 0.5).

    Sample usage

    import { mix } from '@wojtekmaj/color-utils';
    
    mix('#ff0000', '#000', 0.5); // "#800000"
    mix('rgb(255, 0, 0)', '#fff', 0.5); // "#ff8080"

    mixBlack()

    Mixes color with black.

    Sample usage

    import { mixBlack } from '@wojtekmaj/color-utils';
    
    mixBlack('#ff0000', 0.5); // "#800000"
    mixBlack('rgb(255, 0, 0)', 0.5); // "#800000"

    mixWhite()

    Mixes color with white.

    Sample usage

    import { mixWhite } from '@wojtekmaj/color-utils';
    
    mixWhite('#ff0000', 0.5); // "#ff8080"
    mixWhite('rgb(255, 0, 0)', 0.5); // "#ff8080"

    toHex()

    Converts color to hex format.

    Sample usage

    import { toHex } from '@wojtekmaj/color-utils';
    
    toHex('rgb(255, 0, 0)'); // "#ff0000"
    toHex('rgb(0, 255, 0)'); // "#00ff00"
    toHex('rgba(0, 0, 255, 0.5)'); // "#0000ff80"

    toObject()

    Converts color to { r, g, b, a? } object.

    Sample usage

    import { toObject } from '@wojtekmaj/color-utils';
    
    toObject('#f00'); // { r: 255, g: 0, b: 0 }
    toObject('#00ff00'); // { r: 0, g: 255, b: 0 }
    toObject('#0000ff80'); // { r: 0, g: 0, b: 255, a: 0.5 }
    toObject('rgb(255, 0, 0)'); // { r: 255, g: 0, b: 0 }
    toObject('rgb(0, 255, 0)'); // { r: 0, g: 255, b: 0 }
    toObject('rgba(0, 0, 255, 0.5)'); // { r: 0, g: 0, b: 255, a: 0.5 }

    toRgb()

    Converts color to rgb(…) or rgba(…) format, whichever is applicable.

    Sample usage

    import { toRgb } from '@wojtekmaj/color-utils';
    
    toRgb('#f00'); // "rgb(255, 0, 0)"
    toRgb('#00ff00'); // "rgb(0, 255, 0)"
    toRgb('#0000ff80'); // "rgba(0, 0, 255, 0.5)"

    License

    The MIT License.

    Author

    Wojciech Maj
    kontakt@wojtekmaj.pl
    http://wojtekmaj.pl

    Keywords

    Install

    npm i @wojtekmaj/color-utils

    DownloadsWeekly Downloads

    5

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    35.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • wojtekmaj