Neoteric Plumbing Mishap
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    rgb2hexpublic

    rgb2hex Build Status Coverage Status

    Selenium Test Status

    Parse any rgb or rgba string into a hex color. Lightweight library, no dependencies!

    Installation

    via NPM:

    $ npm install rgb2hex

    via Bower

    $ bower install rgb2hex

    Usage

    Include rgb2hex.js in your web app, by loading it as usual:

    <script src="rgb2hex.js"></script>

    Using NodeJS

    var rgb2hex = require('rgb2hex');
     
    console.log(rgb2hex('rgb(210,43,2525)'));
    /**
     * returns:
     * {
     *    hex: '#d22bff',
     *    alpha: 1
     * }
     */
     
    console.log(rgb2hex('rgba(12,173,22,.67)'));
    /**
     * returns:
     * {
     *    hex: '#d22bff',
     *    alpha: 0.67
     * }
     */

    Using RequireJS

    rgb2hex can be also loaded with AMD:

    require(['rgb2hex'], function (rgb2hex) {
        // ... 
    });

    Contributing

    Please fork, add specs, and send pull requests! In lieu of a formal styleguide, take care to maintain the existing coding style.

    Release History

    • 2013-04-22   v0.1.0   first working version

    install

    npm i rgb2hex

    Downloadslast 7 days

    142,853

    version

    0.1.0

    license

    MIT

    repository

    github.com

    last publish

    collaborators

    • avatar