Skip to content

Commit 69e7e60

Browse files
author
TW-IT-Jerry Liu
committed
feat: add removeTrailingSlash function
1 parent 8750dad commit 69e7e60

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

js/src/utils/functions/common.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,15 @@ export const filterObjKeys = (
6969

7070
export const isUsingBlockEditor =
7171
typeof window?.wp !== 'undefined' && typeof window?.wp?.blocks !== 'undefined'
72+
73+
export const removeTrailingSlash = (str: string) => {
74+
if (str.endsWith('/')) {
75+
// 如果字符串以斜杠结尾,使用 slice 方法去除最后一个字符
76+
77+
return str.slice(0, -1)
78+
}
79+
80+
// 否则,返回原字符串
81+
82+
return str
83+
}

0 commit comments

Comments
 (0)