christian-bromann / rgb2hex

a lightweight rgb/rgba to hex parser
MIT License
14 stars 8 forks source link

ES Modules support #32

Open ramiroaisen opened 2 years ago

ramiroaisen commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch rgb2hex@0.2.5 for the project I'm working on.

With these simple steps you can add ES Modules support.

Here is the diff that solved my problem:

diff --git a/node_modules/rgb2hex/index.js b/node_modules/rgb2hex/index.js
index 3c0f6d7..b013adf 100644
--- a/node_modules/rgb2hex/index.js
+++ b/node_modules/rgb2hex/index.js
@@ -8,7 +8,7 @@
  * @return {Object}        object with hex and alpha value
  */

-var rgb2hex = module.exports = function rgb2hex(color) {
+export default function rgb2hex(color) {
     if(typeof color !== 'string') {
         // throw error of input isn't typeof string
         throw new Error('color has to be type of `string`');

This issue body was partially generated by patch-package.

bjankord commented 2 years ago

Could use an ES module version of this package as I'm planning to use it in the browser.

christian-bromann commented 2 years ago

If someone can provide a PR with necessary changes to use this package with CJS and ESM I would be happy to merge and release it. I currently don't have much time to look into this.