From 86a7db8502ead70fd0b6ba060b89d64189c5f894 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 22 Jan 2021 20:12:51 +0000 Subject: [PATCH] chore: replace `includes` with `indexOf` for older browsers (#45) 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. --- colors.mjs | 2 +- index.mjs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/colors.mjs b/colors.mjs index 2ebc29f..401843c 100644 --- a/colors.mjs +++ b/colors.mjs @@ -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; }; } diff --git a/index.mjs b/index.mjs index 6343543..32e7fa1 100644 --- a/index.mjs +++ b/index.mjs @@ -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); } } @@ -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+'';