Skip to content

Commit

Permalink
Reverse conditional expression
Browse files Browse the repository at this point in the history
Close #78
  • Loading branch information
jorgebucaran committed Sep 26, 2021
1 parent 02d2141 commit d1ff3a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const isColorSupported =
!isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI)

const raw = (open, close, searchRegex, replaceValue) => (s) =>
!s && (s === "" || s === undefined)
? ""
: open +
s || !(s === "" || s === undefined)
? open +
(~(s + "").indexOf(close, 4) // skip opening \x1b[
? s.replace(searchRegex, replaceValue)
: s) +
close
: ""

const init = (open, close) =>
raw(
Expand Down

1 comment on commit d1ff3a7

@kurtextrem
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I'm missing something, but the original s === "" || s === undefined is faster than this approach? https://esbench.com/bench/6156d11e6c89f600a57011c2

Please sign in to comment.