Skip to content

Commit

Permalink
fix: Remove circular dependency (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeelaudibert authored Feb 19, 2025
1 parent 74fb6b3 commit 78a6456
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/request-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getQueryParam, formDataToQuery, maskQueryParams } from '../utils/request-utils'
import { isMatchingRegex } from '../utils/string-utils'
import { isMatchingRegex } from '../utils/regex-utils'

describe('request utils', () => {
describe('_HTTPBuildQuery', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/surveys/action-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SimpleEventEmitter } from '../../utils/simple-event-emitter'
import { CaptureResult } from '../../types'
import { isUndefined } from '../../utils/type-utils'
import { window } from '../../utils/globals'
import { isMatchingRegex } from '../../utils/string-utils'
import { isMatchingRegex } from '../../utils/regex-utils'

export class ActionMatcher {
private readonly actionRegistry?: Set<SurveyActionType>
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { RemoteConfig } from './types'
import { Info } from './utils/event-utils'
import { assignableWindow, document, userAgent, window } from './utils/globals'
import { createLogger } from './utils/logger'
import { isMatchingRegex } from './utils/string-utils'
import { isMatchingRegex } from './utils/regex-utils'
import { SurveyEventReceiver } from './utils/survey-event-receiver'
import { isNullish } from './utils/type-utils'

Expand Down
9 changes: 0 additions & 9 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ export function entries<T = any>(obj: Record<string, T>): [string, T][] {
return resArray
}

export const isValidRegex = function (str: string): boolean {
try {
new RegExp(str)
} catch {
return false
}
return true
}

export const trySafe = function <T>(fn: () => T): T | undefined {
try {
return fn()
Expand Down
18 changes: 18 additions & 0 deletions src/utils/regex-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const isValidRegex = function (str: string): boolean {
try {
new RegExp(str)
} catch {
return false
}
return true
}

export const isMatchingRegex = function (value: string, pattern: string): boolean {
if (!isValidRegex(pattern)) return false

try {
return new RegExp(pattern).test(value)
} catch {
return false
}
}
11 changes: 0 additions & 11 deletions src/utils/string-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isValidRegex } from '.'

export function includes<T = any>(str: T[] | string, needle: T): boolean {
return (str as any).indexOf(needle) !== -1
}
Expand All @@ -16,12 +14,3 @@ export const stripLeadingDollar = function (s: string): string {
export function isDistinctIdStringLike(value: string): boolean {
return ['distinct_id', 'distinctid'].includes(value.toLowerCase())
}

export const isMatchingRegex = function (value: string, pattern: string): boolean {
if (!isValidRegex(pattern)) return false
try {
return new RegExp(pattern).test(value)
} catch {
return false
}
}
2 changes: 1 addition & 1 deletion src/web-experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { WEB_EXPERIMENTS } from './constants'
import { isNullish, isString } from './utils/type-utils'
import { getQueryParam } from './utils/request-utils'
import { isMatchingRegex } from './utils/string-utils'
import { isMatchingRegex } from './utils/regex-utils'
import { logger } from './utils/logger'
import { Info } from './utils/event-utils'
import { isLikelyBot } from './utils/blocked-uas'
Expand Down

0 comments on commit 78a6456

Please sign in to comment.