Skip to content

Commit

Permalink
refactor(utils): optimize code of padStart function (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed May 19, 2024
1 parent 72174a7 commit 34673c1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/varlet-ui/src/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ export const cubic = (value: number): number => value ** 3
export const easeInOutCubic = (value: number): number =>
value < 0.5 ? cubic(value * 2) / 2 : 1 - cubic((1 - value) * 2) / 2

// eslint-disable-next-line default-param-last
export const padStart = (str = '', maxLength: number, fillString = ''): string => {
if (str.length >= maxLength) return str
export const padStart = (str: string | undefined, maxLength: number, fillString = ''): string => {
if (str === undefined) {
str = ''
}
if (str.length >= maxLength) {
return str
}

const len = maxLength - str.length
const repeatCount = Math.floor(len / fillString.length)
Expand Down

0 comments on commit 34673c1

Please sign in to comment.