Skip to content

Commit

Permalink
Expand ServerScores includePattern parameter type to allow RegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Apr 5, 2024
1 parent ae63dfc commit aeced0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/common/plugin/PluginState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface PluginState {
clearCache: () => Promise<void>
getLocalServers: (
numServersWanted: number,
includePatterns: string[]
includePatterns?: Array<string | RegExp>
) => string[]
refreshServers: () => Promise<void>
updateServers: (settings: UtxoUserSettings) => Promise<void>
Expand Down Expand Up @@ -209,7 +209,7 @@ export function makePluginState(settings: PluginStateSettings): PluginState {

getLocalServers(
numServersWanted: number,
includePatterns: string[] = []
includePatterns: Array<string | RegExp> = []
): string[] {
return serverScores.getServers(
knownServers,
Expand Down
11 changes: 9 additions & 2 deletions src/common/plugin/ServerScores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class ServerScores {
getServers(
servers: ServerList,
numServersWanted: number,
includePatterns: string[] = []
includePatterns: Array<string | RegExp> = []
): string[] {
if (servers == null || Object.keys(servers).length === 0) {
return []
Expand Down Expand Up @@ -236,7 +236,14 @@ export class ServerScores {
const filter = (server: ServerInfo): boolean => {
for (const pattern of includePatterns) {
// make sure that the server URL starts with the required pattern
if (server.serverUrl.indexOf(pattern) === 0) return true
if (
typeof pattern === 'string' &&
server.serverUrl.indexOf(pattern) === 0
)
return true
// Or make sure that the server URL matches regex
if (pattern instanceof RegExp && pattern.test(server.serverUrl))
return true
}
return false
}
Expand Down

0 comments on commit aeced0f

Please sign in to comment.