Skip to content

Commit

Permalink
fix: add function replace string with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
adyfk committed Sep 11, 2024
1 parent bed95d1 commit 561db61
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/createParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export function createParser(props: ExpressionParserConstructor = {}) {
upper: (_, value: string) => value.toUpperCase(),
lower: (_, value: string) => value.toLowerCase(),
regex: (_, value: any, regex: string, flags?: string) => new RegExp(regex, flags).test(value),
replace: (_, value: string, replaceValue: string, searchValue: string) => {
return (value || '')?.replace?.(searchValue, replaceValue) || ''
},
replace_regex: (_, value: string, replaceValue: string, regex: string, flags?: string) => {
return (value || '')?.replace?.(new RegExp(regex, flags), replaceValue) || ''
},
// DATE ==================================================================================
date: (_, date: string) => date ? moment(date).toISOString() : moment().toISOString(),
date_day: (_, date: string) => date ? moment(date).date() : moment().date(),
Expand Down

0 comments on commit 561db61

Please sign in to comment.