@videsk/tailwind-random-color
Version:
Generate random tailwind colors with a custom palette range
2 lines (1 loc) • 751 B
JavaScript
"use strict";var r=class{constructor(r){const{colors:o=["gray","red","yellow","green","blue","indigo","purple","pink"],range:s=[1,9],prefix:t="bg"}=r||{};this.colors=o,this.range={min:s[0],max:s[1]},this.prefix=t,this.tempColors=[]}pick(){const r=100*this.constructor.random(this.range.min,this.range.max),o=this.constructor.random(0,this.colors.length-1);return`${this.prefix}-${this.colors[o]}-${r}`}color(r=""){return Array.isArray(r)?r.forEach((r=>this.tempColors.push(r))):this.tempColors.push(r),this}add(){this.tempColors.forEach((r=>this.colors.push(r)))}remove(){this.tempColors.forEach((r=>{const o=this.colors.indexOf(r);o>=0&&this.colors.splice(o,1)}))}static random(r=1,o=9){return Math.floor(Math.random()*(o-r+1))+r}};module.exports=r;