From ad196f4227594f2ede6e464021b741a7a01851e4 Mon Sep 17 00:00:00 2001 From: Tobias Speicher Date: Wed, 23 Mar 2022 14:06:12 +0100 Subject: [PATCH] refactor: replace deprecated String.prototype.substr() .substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher --- src/index.js | 2 +- src/plugin/customParseFormat/index.js | 4 ++-- src/plugin/localeData/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index c965dd004..19c409078 100644 --- a/src/index.js +++ b/src/index.js @@ -267,7 +267,7 @@ class Dayjs { weekdays, months, meridiem } = locale const getShort = (arr, index, full, length) => ( - (arr && (arr[index] || arr(this, str))) || full[index].substr(0, length) + (arr && (arr[index] || arr(this, str))) || full[index].slice(0, length) ) const get$H = num => ( Utils.s($H % 12 || 12, num, '0') diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index fc3b788f4..f662a4ab8 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -100,7 +100,7 @@ const expressions = { MMM: [matchWord, function (input) { const months = getLocalePart('months') const monthsShort = getLocalePart('monthsShort') - const matchIndex = (monthsShort || months.map(_ => _.substr(0, 3))).indexOf(input) + 1 + const matchIndex = (monthsShort || months.map(_ => _.slice(0, 3))).indexOf(input) + 1 if (matchIndex < 1) { throw new Error() } @@ -161,7 +161,7 @@ function makeParser(format) { start += token.length } else { const { regex, parser } = token - const part = input.substr(start) + const part = input.slice(start) const match = regex.exec(part) const value = match[0] parser.call(time, value) diff --git a/src/plugin/localeData/index.js b/src/plugin/localeData/index.js index 034dbea13..763bfdb6d 100644 --- a/src/plugin/localeData/index.js +++ b/src/plugin/localeData/index.js @@ -7,7 +7,7 @@ export default (o, c, dayjs) => { // locale needed later const locale = ins.name ? ins : ins.$locale() const targetLocale = getLocalePart(locale[target]) const fullLocale = getLocalePart(locale[full]) - const result = targetLocale || fullLocale.map(f => f.substr(0, num)) + const result = targetLocale || fullLocale.map(f => f.slice(0, num)) if (!localeOrder) return result const { weekStart } = locale return result.map((_, index) => (result[(index + (weekStart || 0)) % 7]))