Skip to content

Commit

Permalink
fix: refactor replace deprecated String.prototype.substr() (#1836)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderRoot authored Apr 14, 2022
1 parent d2783a4 commit 627fa39
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/localeData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down

0 comments on commit 627fa39

Please sign in to comment.