Skip to content

Commit a47953a

Browse files
msopacualukeocodes
authored andcommitted
chore: simplify regex
- We already do toLowerCase(), so don't need i flag. - We're not using the http bit, so no need to capture it. - If there's an s, append it, if not don't. This is the same as just replacing http with ws: [http]:// -> [ws]:// [http]s:// -> [ws]s:// [http]x:// -> [ws]x:// -> error. Is ok. [http]sx:// -> [ws]sx:// -> error in both. Is ok. - We don't want to replace protocols that do not start with http, such as git+https, so we can anchor at string start and leave out the g flag. Much simpler -:)
1 parent 119b53d commit a47953a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/packages/LiveClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class LiveClient extends AbstractWsClient {
2727
super(key, options);
2828

2929
const url = new URL(endpoint, this.baseUrl);
30-
url.protocol = url.protocol.toLowerCase().replace(/(http)(s)?/gi, "ws$2");
30+
url.protocol = url.protocol.toLowerCase().replace(/^http/, "ws");
3131
appendSearchParams(url.searchParams, this.transcriptionOptions);
3232

3333
this._socket = new w3cwebsocket(url.toString(), ["token", this.key]);

0 commit comments

Comments
 (0)