From ba81258b5b6a1a7ae02033c056d82198c6d92ec9 Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Thu, 24 Mar 2022 19:01:10 +0100 Subject: [PATCH] chore: replace deprecated String.prototype.substr() (#4918) String.prototype.substr() is deprecated so we replace it with functions which work similarily but aren't deprecated Signed-off-by: Tobias Speicher --- lib/plugins/helper/number_format.js | 6 +++--- lib/plugins/tag/code.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/plugins/helper/number_format.js b/lib/plugins/helper/number_format.js index 0db807eb76..7a1495f67f 100644 --- a/lib/plugins/helper/number_format.js +++ b/lib/plugins/helper/number_format.js @@ -13,10 +13,10 @@ function numberFormatHelper(num, options = {}) { const beforeLength = before.length; const beforeFirst = beforeLength % 3; - if (beforeFirst) beforeArr.push(before.substr(0, beforeFirst)); + if (beforeFirst) beforeArr.push(before.slice(0, beforeFirst)); for (let i = beforeFirst; i < beforeLength; i += 3) { - beforeArr.push(before.substr(i, 3)); + beforeArr.push(before.slice(i, i + 3)); } before = beforeArr.join(delimiter); @@ -30,7 +30,7 @@ function numberFormatHelper(num, options = {}) { const afterLast = after[precision]; const last = parseInt(after[precision - 1], 10); - afterResult = after.substr(0, precision - 1) + (afterLast < 5 ? last : last + 1); + afterResult = after.substring(0, precision - 1) + (afterLast < 5 ? last : last + 1); } else { afterResult = after; for (let i = 0, len = precision - afterLength; i < len; i++) { diff --git a/lib/plugins/tag/code.js b/lib/plugins/tag/code.js index 8bcecdd629..4b2fdd07f0 100644 --- a/lib/plugins/tag/code.js +++ b/lib/plugins/tag/code.js @@ -68,8 +68,8 @@ function parseArgs(args) { for (const cur of value.split(',')) { const hyphen = cur.indexOf('-'); if (hyphen !== -1) { - let a = +cur.substr(0, hyphen); - let b = +cur.substr(hyphen + 1); + let a = +cur.slice(0, hyphen); + let b = +cur.slice(hyphen + 1); if (Number.isNaN(a) || Number.isNaN(b)) continue; if (b < a) { // switch a & b const temp = a;