Pankaj Patel
Pankaj Patel

Pankaj Patel

Today's npm package: color-alpha

Today's npm package: color-alpha

Pankaj Patel's photo
Pankaj Patel
·Jun 24, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Today's npm package is color-alpha

Color Alpha will let you customize the Alpha i.e. opacity of the colour in JS

Very useful in cases when → Adjusting minimal inline styles → Working with CSS-in-JS → Maintaining a Design System → Creating and Maintaining Style Guides → PostProcssing CSS Files

Here is how you can use it:

const A = require('color-alpha');

console.log(A('red', .35)) // "rgba(255,0,0,0.35)"
console.log(A('#f00', .35)) // "rgba(255,0,0,0.35)"
console.log(A('#ff0000', .35)) // "rgba(255,0,0,0.35)"
console.log(A('rgb(255, 0, 0)', .35)) // "rgba(255,0,0,0.35)"
console.log(A('rgba(255, 0, 0, 1)', .35)) // "rgba(255,0,0,0.35)"

See it in action here: runkit.com/pankaj/color-alpha

Stay tuned for tomorrow's package of the Day.

 
Share this