-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use indexOf
instead of includes
to support ES5 browsers
#45
Conversation
Codecov Report
@@ Coverage Diff @@
## master #45 +/- ##
=======================================
Coverage 98.77% 98.77%
=======================================
Files 2 2
Lines 163 163
Branches 28 27 -1
=======================================
Hits 161 161
Misses 1 1
Partials 1 1
Continue to review full report at Codecov.
|
Hey, thanks~! Can you please "allow edits from maintainers" so I can make a minor adjustment? |
Aye, I didn't turn this off intentionally and don't see it here. Thus I can't turn it on. I think this is a bug on GitHub when the PR comes from an org rather than my personal account (even though I'm owner of that org). Feel free to modify it as part of the squashed/cherry'ed land commit, though. I know maintainers sometimes prefer to run a change by the original author before landing it (with their name on it), but I trust your judgement. |
Oh, I didn't notice the org. Can you update all changes from |
Also, you probably already knew this, but if you had something like this, kleur is a no-op in browsers: if (typeof window !== 'undefined') {
kleur.enabled = false;
} And if using |
I'd like to use kleur inside the isomorphic js-reporters library, as used inside @qunitjs, which still supports a number of plain ES5 browsers, such as IE11.
I vaguely recall trying this, but I don't remember why I abandoned it. I might give it another go. Long-term I'd prefer to leave it because in my case the code wouldn't be used solely in a browser but only when either 1) running unit test and I'd prefer to keep the tests simple and strict with exactly asserted outcomes, and 2) there is one case where the code will intentionally run in a browser, which is when it runs headless and then console output gets reported via something like Karma Runner or Puppeteer back to Node.js standard out. I'm guessing, but I don't know, that this might be the reason kleur is enabled by, when run outside of Node? |
It looks like you were trying to use the main While slightly more verbose, if you used the Kleur tries to be enabled by default, because it'd be weird for something to try and do nothing by default 😁 So it tries to do something unless the environment (or the user) says otherwise. By default, kleur is harmless in the browser. Only the plain ANSI colors will have an effect in the console (except firefox I think) . Everything else is ignored & does not affect the string, which is nice & makes it easy to reroute the output into a terminal window as you mentioned |
Thanks for this, will merge and publish tomorrow. Am away from my computer for the night |
I'd like to use
kleur
inside the isomorphicjs-reporters
library, as used inside the QUnit application. We still support a number of plain ES5 browsers, such as IE11, and this one function call inside kleur is currently requiring a polyfill to ship with our standard distribution.The code is very unlikely to be needed inside a browser, but I'm not sure how else to avoid it, also since the colors are enabled by default when Node/
process
is undefined. This is fine for us, but it'd help us a lot to avoid these two function calls for now.