color-between
get a gradient color between two colors.
Installation
$ npm install color-between --save
Usage
get a middle color between two hsl
color, with default 0.5
gradient degree:
const colorBetween = require('color-between');
colorBetween('hsl(0, 100%, 100%)', 'hsl(100, 0%, 0%)');
get a color between two colors with a gradient degree:
const colorBetween = require('color-between');
colorBetween('rgb(255, 255, 255)', 'rgb(0, 0, 0)', 0.5, 'rgb');
colorBetween('rgba(255, 255, 255, .2)', 'rgba(0, 0, 0, .8)', 0.5, 'rgb');
colorBetween('#fff', '#000', 0.5, 'hex');
colorBetween('#fff', 'rgb(0, 0, 0)', 0.5, 'hsl');
output: 'hsl(0, 0%, 50%)'
API
colorBetween(startColor, endColor, gradientDegree, outputFormat)
=> color:String
startColor
:String
and endColor
:String
valid color string (eg, hsl(0, 100%, 100%)
, rgb(100, 100, 100)
, rgba(0, 0, 0, 0.5)
, #fff
).
Also, support input of color
package.
gradientDegree
:Number
valid number between 0
and 1
(eg, 0.5
).
outputFormat
:String
output string format type, support these format:
color
:String
return a color string with outputFormat
format type.
Test
npm i
npm test