1.0.0 • Published 2 years ago

@picaro/colorhelper v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Installation

npm i @rougefw/colorhelper

Usage

import {rfColorhelper} from '@rougefw/colorhelper' or const {rfColorHelper} = require('@rougefw/colorhelper')

Instantiation :

const colorHelper = new rfColorHelper()

Conversion methods :

Input the color as a string or as an object (see the comments for the expected values)

colorHelper.hslToRgb(color) // color = 'hsl(xdeg y% z% )' || {hue: xx, light: yy, saturation: zz}
colorHelper.hslToHex(color) // color = 'hsl(xdeg y% z% )' || {hue: xx, light: yy, saturation: zz}
colorHelper.hexToRgb(color ) // color = #XXYYZZ (hexadecimal)
colorHelper.hexToHsl(color) // color = #XXYYZZ (hexadecimal)
colorHelper.rgbToHex(color) // color = 'rgb(xxx yyy zzz)' || {red: xx, green: yy, blue: zz}
colorHelper.rgbToHsl(color) // color = 'rgb(xxx yyy zzz)' || {red: xx, green: yy, blue: zz}

Getter methods

Output the converted color as a css parameter (string) or as an object

colorHelper.xxxToYyy(color).getString() // outputs a css ready string
colorHelper.xxxToYyy(color).getValueCollection() // outputs a js object

Utility methods

takes a css color string and outputs a JS object

colorHelper.getValueCollection(color) 

Examples

const colorHelper = new rfColorHelper()

colorHelper.hslToHex('hsl(34deg 34% 45%)').getString() // #F0E5D6
colorHelper.rgbToHsl({red: 23, green: 34, blue: 27}).getValueCollection() // {"hue": 142, "light": 11, "saturation": 19}

Limitations

  • No support for Alpha channel yet
  • JS being not too great with math, the conversion might result in a couple of 1/255th variation that should be unnoticeable
acornansi-regexansi-escapesacorn-globalsanymatchargparseacorn-walkansi-stylesababagent-baseasynckitbabel-plugin-istanbulbabel-plugin-jest-hoistbabel-plugin-polyfill-corejs3babel-plugin-polyfill-corejs2babel-preset-current-node-syntaxbabel-preset-jestbracesbrace-expansionbabel-plugin-dynamic-import-nodebuffer-frombrowserslistbsercallsitesbrowser-process-hrtimebabel-plugin-polyfill-regeneratorchalkchar-regexcamelcaseci-infocobalanced-matchcjs-module-lexercombined-streamcollect-v8-coverageconcat-mapcolor-convertcolor-namecliuiconvert-source-mapcross-spawncall-bindcssomcssstylecore-js-compatdebugdedentdata-urlscaniuse-litedelayed-streamdecimal.jsdeepmergeemitterydiff-sequencesdefine-propertieselectron-to-chromiumdomexceptionescape-string-regexpdetect-newlinedeep-isescodegenescaladeesutilsestraverseesprimaexitexecafast-json-stable-stringifyexpectfast-levenshteinfb-watchmanfseventsfill-rangefind-upfs.realpathgensyncfunction-bindget-package-typeget-streamget-caller-fileemoji-regexglobhas-flaghashtml-escaperglobalsget-intrinsichttp-proxy-agenthuman-signalsform-dataiconv-litehttps-proxy-agentimurmurhashhas-symbolsimport-localis-generator-fnhtml-encoding-snifferinflightis-core-moduleinheritsis-fullwidth-code-pointis-numberis-streamis-typedarrayisexeistanbul-lib-coverageis-potential-custom-element-nameistanbul-lib-instrumentistanbul-lib-reportgraceful-fsistanbul-lib-source-mapsjest-circusjest-clijest-changed-filesjest-configjest-docblockjest-eachjest-diffjest-environment-nodejest-environment-jsdomjest-get-typejest-message-utiljest-haste-mapjest-leak-detectorjest-jasmine2jest-pnp-resolverjest-mockjest-matcher-utilsjest-regex-utiljest-runtimejest-runnerjest-resolvejest-resolve-dependenciesjest-serializerjest-validatejest-snapshotjest-utiljest-watcherjest-workerjsdomjs-yamljs-tokenslevnlevenjsesclocate-pathjson5lru-cachemake-diristanbul-reportsmerge-streammimic-fnmicromatchminimatchmime-typeslodash.debouncemakeerrorminimistlodashmsnormalize-pathnatural-comparenpm-run-pathonetimeoptionatormime-dbnode-releasesobject-keysoncep-trynode-int64nwsapip-limitpath-is-absolutekleurpath-keyp-locatepath-existsparse5path-parseprelude-lspiratespkg-dirpromptspretty-formatpicomatchpunycodeobject.assignregenerator-transformpicocolorsregenerate-unicode-propertiesreact-isregjsgenregjsparserresolveregexpu-coreresolve.exportsrequire-directoryregenerator-runtimesafe-bufferresolve-fromresolve-cwdsafer-bufferregeneratesemverrimrafshebang-regexsignal-exitslashsaxesshebang-commandsource-map-supportstack-utilssisteransisource-mapsupports-colorstring-lengthsprintf-jsstrip-ansistrip-final-newlinepslterminal-linkstring-widthsupports-hyperlinksthroatstrip-bomto-fast-propertiestest-excludesymbol-treetmpltr46type-checktype-detecttypedarray-to-bufferuniversalifyunicode-match-property-value-ecmascripttough-cookiew3c-hr-timewhatwg-encodingw3c-xmlserializerwalkerwhatwg-mimetypeunicode-canonical-property-names-ecmascriptwebidl-conversionswrap-ansiwhatwg-urlwrite-file-atomicwhichunicode-match-property-ecmascriptv8-to-istanbulxml-name-validatorunicode-property-aliases-ecmascriptto-regex-rangeword-wrapwstype-festwrappyxmlcharsy18nyargsyallistyargs-parser
1.0.0

2 years ago