feat: add remove_last filter

This commit is contained in:
James Prior
2022-12-02 23:48:50 +08:00
committed by Jun Yang
parent b4d1e27420
commit 6c3f1c1e0c
2 changed files with 19 additions and 1 deletions
+8
View File
@@ -39,6 +39,14 @@ export function remove_first (v: string, l: string) {
return stringify(v).replace(String(l), '')
}
export function remove_last (v: string, l: string) {
const str = stringify(v)
const pattern = String(l)
const index = str.lastIndexOf(pattern)
if (index === -1) return str
return str.substring(0, index) + str.substring(index + pattern.length + 1)
}
export function rstrip (str: string, chars?: string) {
if (chars) {
chars = escapeRegExp(stringify(chars))