From 627fa393e4daf83c92431162dbe18534b23fcbae Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Thu, 14 Apr 2022 14:53:29 +0200 Subject: [PATCH] fix: refactor replace deprecated String.prototype.substr() (#1836) --- 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 c965dd00..19c40907 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 fc3b788f..f662a4ab 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 034dbea1..763bfdb6 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]))