GithubHelp home page GithubHelp logo

eltonjuan / hex-to-rgba Goto Github PK

View Code? Open in Web Editor NEW

This project forked from misund/hex-to-rgba

0.0 2.0 0.0 36 KB

Converts CSS hexadecimal color codes to rgb()/rgba().

Home Page: https://www.npmjs.com/package/hex-to-rgba

License: GNU General Public License v3.0

JavaScript 100.00%

hex-to-rgba's Introduction

Build Status

hex-to-rgba turns an old-fashioned css hex color value string into an rgba() string.

Optionally pass in an alpha value. The passed alpha value will override any alpha value from 4- or 8-digit hexes. If you don't pass in an alpha value at all, we will default to an alpha value of 1 (completely opaque).

Supports 3-, 4-, 6- and 8-digit hex values with or without a leading hash.

Installation

$ npm install --save hex-to-rgba

Usage

var hexToRgba = require("hex-to-rgba");

hexToRgba('112233'); // "rgba(17, 34, 51, 1)"
hexToRgba('#112233'); // "rgba(17, 34, 51, 1)"
hexToRgba('112233', '0.5'); // "rgba(17, 34, 51, 0.5)"
hexToRgba('#112233', 0.75); // "rgba(17, 34, 51, 0.75)"

hexToRgba('11223344') // "rgba(17, 34, 51, 0.27)"
hexToRgba('#11223344') // "rgba(17, 34, 51, 0.27)"
hexToRgba('11223344', '0.5') // "rgba(17, 34, 51, 0.5)"
hexToRgba('#11223344', 0.75) // "rgba(17, 34, 51, 0.75)"

hexToRgba('123'); // "rgba(17, 34, 51, 1)"
hexToRgba('#123'); // "rgba(17, 34, 51, 1)"
hexToRgba('123', 0.2) // "rgba(17, 34, 51, 0.2)"
hexToRgba('#123', 0.2) // "rgba(17, 34, 51, 0.2)"

hexToRgba('1234'); // "rgba(17, 34, 51, 0.27)"
hexToRgba('#1234'); // "rgba(17, 34, 51, 0.27)"
hexToRgba('1234', 0.5) // "rgba(17, 34, 51, 0.5)"
hexToRgba('#1234', 0.75) // "rgba(17, 34, 51, 0.75)"

Testing

npm run build && npm test

Signature

hexToRgba(hex, a=1)

Parameters

  • hex: The hex color value to convert to rgba. (examples: '123456', '#123456', '123', '#123')
  • a: An alpha value to apply. (optional, default: 1) (examples: '0.5', 0.25)

Returns

An rgba() string. (examples: 'rgba(11, 22, 33, 1)', 'rgba(11, 22, 33, 0.5)')

Changelog

1.0.0

  • BREAKING CHANGE: Always return rgba(); even if the color is completely opaque
  • Support 4-digit hexes
  • Add typescript type declaration (props @gillchristian)

0.2.0

  • Support 8-digit hexes

0.1.0

  • Initial release
  • Support 6-digit hexes
  • Support 3-digit hexes

hex-to-rgba's People

Contributors

misund avatar gillchristian avatar

Watchers

James Cloos avatar Michael Amos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.