jsdomain-parser 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/test.html ADDED
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Test Suite</title>
7
+
8
+ <style>
9
+ #result {
10
+ white-space: pre-wrap;
11
+ font-size: 26px;
12
+ background-color: lightgray;
13
+ padding: 25px;
14
+ margin-top: 25px;
15
+ font-family: monospace;
16
+ }
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <input type="text" placeholder="Enter URL" />
21
+ <button id="parse">Parse</button>
22
+ <div id="result"></div>
23
+ <script type="module">
24
+ import { parse } from "../dist/jsdomain-parser.esm.js";
25
+
26
+ document.querySelector("#parse").addEventListener("click", () => {
27
+ const input = document.querySelector("input").value;
28
+
29
+ let parsed;
30
+
31
+ try {
32
+ parsed = parse(input, {
33
+ allowPrivate: true, // allow private TLDs
34
+ allowUnknown: false, // restrict to known TLDs only
35
+ extendedTlds: ["my.tld", "tld"], // add custom TLDs to extend the list
36
+ });
37
+ } catch (e) {
38
+ parsed = {
39
+ error: e.message,
40
+ };
41
+ }
42
+
43
+ document.querySelector("#result").innerHTML = JSON.stringify(
44
+ parsed,
45
+ null,
46
+ 2
47
+ );
48
+ });
49
+ </script>
50
+ </body>
51
+ </html>