Skip to content

Commit ca4eda3

Browse files
authored
perf: precompile RegExp (#1806)
1 parent 3cd355f commit ca4eda3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/core/postgrest-js/src/PostgrestFilterBuilder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export type IsStringOperator<Path extends string> = Path extends `${string}->>${
3030
? true
3131
: false
3232

33+
const PostgrestReservedCharsRegexp = new RegExp('[,()]')
34+
3335
// Match relationship filters with `table.column` syntax and resolve underlying
3436
// column value. If not matched, fallback to generic type.
3537
// TODO: Validate the relationship itself ala select-query-parser. Currently we
@@ -316,7 +318,7 @@ export default class PostgrestFilterBuilder<
316318
.map((s) => {
317319
// handle postgrest reserved characters
318320
// https://postgrest.org/en/v7.0.0/api.html#reserved-characters
319-
if (typeof s === 'string' && new RegExp('[,()]').test(s)) return `"${s}"`
321+
if (typeof s === 'string' && PostgrestReservedCharsRegexp.test(s)) return `"${s}"`
320322
else return `${s}`
321323
})
322324
.join(',')

0 commit comments

Comments
 (0)