Skip to content

Commit 1c9dd51

Browse files
committed
[PortsJS] Adds bridge for url parsing
1 parent 4ac9082 commit 1c9dd51

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

ports-js/url-parsing.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { suite } from './ports.js';
2+
import { URL } from 'url';
3+
4+
const urlParsingSuite = suite("suites/url-parsing-RFC.ports");
5+
6+
urlParsingSuite.placeholder("url-parse", (env, urlString) => {
7+
try {
8+
return new URL(urlString);
9+
} catch (e) {
10+
return e;
11+
}
12+
});
13+
14+
urlParsingSuite.placeholder("parse-error?", (env, parseResult) => {
15+
return parseResult instanceof Error;
16+
});
17+
18+
urlParsingSuite.placeholder("url-scheme", (env, parseResult) => {
19+
return parseResult instanceof URL ? parseResult.protocol.replace(':', '') : "";
20+
});
21+
22+
urlParsingSuite.placeholder("url-authority", (env, parseResult) => {
23+
return parseResult instanceof URL ? parseResult.host : "";
24+
});
25+
26+
// Running
27+
urlParsingSuite.run();

0 commit comments

Comments
 (0)