Skip to content
A JavaScript class that accepts a string and tries to figure out a valid color out of it.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
test
tools
.editorconfig
.gitattributes
.gitignore
.nvmrc
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.txt
README.md
package-lock.json
package.json

README.md

rgb-color

Greenkeeper badge NPM version NPM downloads Build Status Coverage Status Dependency Status Dev Dependency Status Online Chat

A JavaScript class that accepts a string and tries to figure out a valid color out of it. Thanks to Stoyan Stefanov: http://www.phpied.com/rgb-color-parser-in-javascript/

Installation

$ npm install rgb-color

How to use

General

var color = rgbcolor('darkblue');
if (color.isValid()) { // 'isValid()' is true when the parsing was a success
    // channels
    var obj = color.channels();
    console.log(obj.r + ', ' + obj.g + ', ' + obj.b);
    // log: { r: 0, g: 0, b: 139 }
    // HEX
    console.log(color.hex());
    // log: #00008b
    // RGB
    console.log(color.rgb());
    // log: rgb(0, 0, 139)
}

Nodejs

var rgbcolor = require('rgb-color');
var color = rgbcolor('darkblue');

if (color.isValid()) { // 'isValid()' is true when the parsing was a success
    // channels
    var obj = color.channels();
    console.log(obj.r + ', ' + obj.g + ', ' + obj.b);
    // log: { r: 0, g: 0, b: 139 }
    // HEX
    console.log(color.hex());
    // log: #00008b
    // RGB
    console.log(color.rgb());
    // log: rgb(0, 0, 139)
}

Demo

    Demo at Codepen: Demo

Features

    ✓ Cross-platform, no dependencies
    ✓ Exported in UMD (Universal Module Definition)

License

This source code is licensed under the MIT license found in the LICENSE.txt file.

You can’t perform that action at this time.