Skip to content

Commit

Permalink
chore: replace includes with indexOf for older browsers (#45)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Krinkle authored Jan 22, 2021
1 parent fc9cc25 commit 86a7db8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion colors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function init(x, y) {

return function (txt) {
if (!$.enabled || txt == null) return txt;
return open + ((''+txt).includes(close) ? txt.replace(rgx, close + open) : txt) + close;
return open + (!!~(''+txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
};
}

Expand Down
4 changes: 2 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function run(arr, str) {
tmp = arr[i];
beg += tmp.open;
end += tmp.close;
if (str.includes(tmp.close)) {
if (!!~str.indexOf(tmp.close)) {
str = str.replace(tmp.rgx, tmp.close + tmp.open);
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ function init(open, close) {
};
return function (txt) {
if (this !== void 0 && this.has !== void 0) {
this.has.includes(open) || (this.has.push(open),this.keys.push(blk));
!!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk));
return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
}
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
Expand Down

0 comments on commit 86a7db8

Please sign in to comment.