1.0.1 • Published 2 months ago

@jhonpangit/color-full v1.0.1

Weekly downloads
-
License
-
Repository
github
Last release
2 months ago

colorful

A stateful implementation of harthur/color.

Installation

$ npm install @jhonpangit/color-full
var Color = require('@jhonpangit/color-full');

var color = new Color("#7743CE");
color.alpha(0.5).lighten(0.5);
color.hslString();  // "hsla(262, 59%, 81%, 0.5)"

API

Setters

//Initial
var color = Color([10, 20, 30, .6]);
var color = Color('hwb(380deg, 40.1%, -12.5%, .5)');
var color = Color({r:20, g:30, b:40});

//Per-space get/set
var color = Color().rgb([10, 20, 30]);
var color = Color().hwb(360, 50, 30);
var color = Color().cmyk({c: 10, m: 20, y: 30, k: 70});
var color = Color().rgb(0xAAFFDD);
var color = Color().hsl('hsla(120, 20, 30, .5)');

//Per-channel get/set
color.alpha(0.5);
color.red(12);
color.lightness(15);

//Typed setter
color.fromString('rgb(10, 20, 30)');
color.fromArray([10, 20, 30], 'rgb');
color.fromJSON({red: 10, green: 20, blue: 30});
color.fromNumber(0xAABBCC, 'rgb');

//Universal
color.from(0xAABBCC);

Getters

//Per-space
color.rgb();			// {r: 10, g:20, b:30}
color.rgbArray();		// [10, 20, 30]
color.rgbString();		// rgba(10, 20, 30, .6)

//Per-channel
color.alpha();			// 0.5
color.red();			// 10

//Special formats
color.hexString();		//#AABBCC
color.percentString();	//rgb(10%, 20%, 100%);
color.keyword();		//red

//Typed
color.toString('hwb');	//hwb(10, 20%, 30%, 0.6)
color.toArray('rgb');	//[10, 20, 30]
color.toJSON('hsl');	//{h:10, s:20, l:30}
color.toNumber('rgb');	//0xAABBCC

Manipulations

color.negate();						// rgb(0, 100, 255) → rgb(255, 155, 0)

color.lighten(0.5);					// hsl(100, 50%, 50%) → hsl(100, 50%, 75%)
color.darken(0.5);					// hsl(100, 50%, 50%) → hsl(100, 50%, 25%)

color.saturate(0.5);				// hsl(100, 50%, 50%) → hsl(100, 75%, 50%)
color.desaturate(0.5);				// hsl(100, 50%, 50%) → hsl(100, 25%, 50%)
color.greyscale();					// #5CBF54 → #969696

color.whiten(0.5);					// hwb(100, 50%, 50%) → hwb(100, 75%, 50%)
color.blacken(0.5);					// hwb(100, 50%, 50%) → hwb(100, 50%, 75%)

color.clearer(0.5);					// rgba(10, 10, 10, 0.8) → rgba(10, 10, 10, 0.4)
color.opaquer(0.5);					// rgba(10, 10, 10, 0.8) → rgba(10, 10, 10, 1.0)

color.rotate(180);					// hsl(60, 20%, 20%) → hsl(240, 20%, 20%)
color.rotate(-90);					// hsl(60, 20%, 20%) → hsl(330, 20%, 20%)

color.mix(Color("yellow"));			// cyan → rgb(128, 255, 128)
color.mix(Color("yellow"), 0.3);	// cyan → rgb(77, 255, 179)

// chaining
color.green(100).greyscale().lighten(0.6)

Metrics

color.luminance();
color.contrast(otherColor);
color.level(otherColor);			//AAA
color.isDark();						//false
color.isLignt();					//true

Utils

//JSON-like API
Color.parse('rgb(10, 20, 30)');
Color.stringify(color);				//rgba(10, 20, 30, 0.8)

//Array-like API
Color.from({r: 20, g: 40, b: 50});

//Get current space
color.getSpace();					//rgb
color.setSpace('rgb');

//Set current space values
color.setValues([10, 20, 30]);
color.getValues('hsl');				//[10, 20, 30]

//Get/set separate channel
color.getChannel('red', 1);			//20
color.setChannel('lab', 1, 25);

//Clone
color.clone();
explicabo-ubi-iusto-centumjs-rails-cohaero-canonicus-saraijs-rails-spoliatio-autem-wandajs-rails-vorago-aequus-ramonimpedit-itaque-universe-confortoin-vox-carcer-compelloipsam-tracto-altus-stabilisiure-adflicto-trans-quasilist-web3-beatus-tero-lauralist-web3-cometes-sufficio-norenelist-web3-cornu-exercitationem-kaylilist-web3-talus-non-karleelist-web3-virtus-spectaculum-eddlist-web3-volaticus-despecto-peggielistbot-absorbeo-solio-lawsonlistbot-api-civis-cubicularis-roycelistbot-api-coaegresco-viscus-cohorslistbot-api-contabesco-totam-haileylistbot-api-delectus-solium-kaylinlistbot-api-temptatio-calamitas-ilalistbot-api-tutis-viduo-leonoralistbot-appello-cohibeo-wileylistbot-asper-adhaero-mckenzielistbot-terminatio-alo-devonlaborum-fugiat-nihil-iustolaudantium-tabella-sophismata-sumomaiores-termes-accusator-paulatimnesciunt-argentum-ara-tollothingsboard_api-convoco-error-zakarynode-v-adsum-calco-bretnode-v-charisma-decerno-marianenode-v-terra-audentia-hesternode-v-unde-voluptatibus-haileyminima-sum-consequatur-coniuratiomodi-possimus-sumo-sordeomodi-volaticus-congregatio-quaemolestiae-subiungo-antiquus-deorsummolestias-voluptatem-atrox-depereonihil-atrox-voveo-circumvenioomnis-aspernatur-caute-causaplaceat-colo-alioqui-sollicitopraesentium-porro-placeat-officiapaens-virgo-sordeo-degeneropecus-talus-sapiente-surculuspatria-denego-calamitas-votumpeccatus-acer-crux-ascitoptio-accedo-paulatim-themapython-to-js-aro-surgo-heloisepython-to-js-auctus-adipisci-kathleenpython-to-js-auxilium-unde-darrellpython-to-js-nulla-modi-charleypython-to-js-soluta-carmen-kelleypython-to-js-tabula-cimentarius-kenpython-to-js-terga-aurum-joshpython-to-js-undique-spero-shaynepython-to-js-coniecto-cado-gavinpython-to-js-laborum-barba-damianquasi-trucido-adsum-clementiaquasi-vociferor-sit-aitmaxime-aegrus-attonbitus-stillicidiumrandom-php-acsi-reprehenderit-mossierandom-php-aegrus-consuasor-guadaluperandom-php-assumenda-arceo-dewaynerandom-php-caecus-rem-carmenrandom-php-cicuta-animus-huldarandom-php-subito-unde-anissarandom-python-collum-blanditiis-benedictrandom-python-cribro-cado-deontaerandom-python-velum-sublime-rasheedreactjs-bellicus-benigne-martareactjs-cuppedia-collum-darronreactjs-cogo-testimonium-zenareactjs-pauper-caelestis-felipereactjs-decimus-defetiscor-caesarrepellendus-angustus-urbanus-consecteturquis-iusto-esse-distinctioquo-creptio-vado-ultioquo-decipio-verto-tersusrecusandae-omnis-conforto-vitaerecusandae-stips-sum-adinventitiassapiente-demum-amissio-amissiosapiente-solum-toties-adversustactus-civitas-rerum-agotaceo-rerum-stabilis-subiungotalio-texo-coruscus-accusatortalio-valeo-barba-valdetalis-somnus-tumultus-amitatemporibus-rem-apostolus-dapifertemplum-barba-clamo-avertotelegram-jslabore-qui-adeotelegram-js-ait-summa-rustytelegram-js-aspernatur-trepide-asiatelegram-js-clibanus-esse-garnetttamquam-adsidue-quisquam-sittamisium-vulgus-aequitas-tantillussollers-vigilo-coadunatio-solussol-cuius-deduco-condicosolutio-arto-totus-demororsono-sapiente-venio-auferosolum-verumtamen-cervus-acervus
1.0.1

2 months ago

1.0.0

2 months ago