Skip to content

Commit

Permalink
fix: Remove circular dependency
Browse files Browse the repository at this point in the history
When bundling our SDK we were warned about circular dependency errors, because:

`src/utils/type-utils` depends on `src/utils/string-utils`
`src/utils/string-utils` depends on `src/utils`
`src/utils` depends on `src/string-utils`

We can remove the dependency by making `string-utils` self-contained copying the function it was importing from the index.

Turns out that function isn't being used anywhere else anyway.
  • Loading branch information
rafaeelaudibert committed Feb 19, 2025
1 parent 8133350 commit 6572066
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
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
10 changes: 9 additions & 1 deletion src/utils/string-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { isValidRegex } from '.'
export const isValidRegex = function (str: string): boolean {
try {
new RegExp(str)
} catch {
return false
}
return true
}

export function includes<T = any>(str: T[] | string, needle: T): boolean {
return (str as any).indexOf(needle) !== -1
Expand All @@ -19,6 +26,7 @@ export function isDistinctIdStringLike(value: string): boolean {

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

try {
return new RegExp(pattern).test(value)
} catch {
Expand Down

0 comments on commit 6572066

Please sign in to comment.