jsdomain-parser 1.0.8 → 1.0.9
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/dist/jsdomain-parser.cjs.js +9813 -9813
- package/dist/jsdomain-parser.cjs.min.js +1 -1
- package/dist/jsdomain-parser.esm.js +9807 -9807
- package/dist/jsdomain-parser.esm.min.js +1 -1
- package/dist/jsdomain-parser.umd.js +9819 -9819
- package/dist/jsdomain-parser.umd.min.js +1 -1
- package/index.js +8 -1
- package/package.json +43 -34
- package/types/index.d.ts +78 -0
package/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./index').ParseResult} ParseResult
|
|
3
|
+
* @typedef {import('./index').ParseOptions} ParseOptions
|
|
4
|
+
* @typedef {import('./index').TldInfo} TldInfo
|
|
5
|
+
* @typedef {import('./index').ParsedUrl} ParsedUrl
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
const parseTld = require("./src/parseTld.js");
|
|
2
9
|
const parse = require("./src/parse.js");
|
|
3
10
|
|
|
4
|
-
module.exports = { parse, parseTld };
|
|
11
|
+
module.exports = { parse, parseTld };
|
package/package.json
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "jsdomain-parser",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Parse URLs to extract TLDs, domain, protocols and more",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "jsdomain-parser",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Parse URLs to extract TLDs, domain, protocols and more",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
|
+
"require": "./index.js",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rollup -c",
|
|
17
|
+
"test": "jest"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/ToolsOverflow/jsdomain-parser"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"url",
|
|
25
|
+
"parser",
|
|
26
|
+
"domain",
|
|
27
|
+
"parser",
|
|
28
|
+
"tld",
|
|
29
|
+
"extractor",
|
|
30
|
+
"extract",
|
|
31
|
+
"tld"
|
|
32
|
+
],
|
|
33
|
+
"author": "ToolsOverflow",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
37
|
+
"jest": "^29.7.0",
|
|
38
|
+
"rollup": "^2.79.2",
|
|
39
|
+
"rollup-plugin-commonjs": "^10.1.0",
|
|
40
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
41
|
+
"rollup-plugin-terser": "^7.0.2"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsed TLD information
|
|
3
|
+
*/
|
|
4
|
+
export interface TldInfo {
|
|
5
|
+
/** The full public suffix / effective TLD (e.g. "co.uk", "com") */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Number of labels/parts in the TLD (e.g. 2 for co.uk) */
|
|
8
|
+
length: number;
|
|
9
|
+
/** Individual labels of the TLD */
|
|
10
|
+
parts: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parsed URL components (similar to WHATWG URL but with query as object)
|
|
15
|
+
*/
|
|
16
|
+
export interface ParsedUrl {
|
|
17
|
+
/** Second-level domain + TLD (e.g. "example.com") */
|
|
18
|
+
domain: string;
|
|
19
|
+
/** Full origin including protocol (e.g. "https://www.example.com") */
|
|
20
|
+
origin: string;
|
|
21
|
+
/** Protocol with colon (e.g. "https:") */
|
|
22
|
+
protocol: string;
|
|
23
|
+
/** Host including subdomains and port if present (e.g. "www.example.com:8080") */
|
|
24
|
+
host: string;
|
|
25
|
+
/** Hostname without port (e.g. "www.example.com") */
|
|
26
|
+
hostname: string;
|
|
27
|
+
/** Port number as string (empty string if none) */
|
|
28
|
+
port: string;
|
|
29
|
+
/** Path including leading slash (e.g. "/blog/post") */
|
|
30
|
+
pathname: string;
|
|
31
|
+
/** Query string including ? (empty string if none) */
|
|
32
|
+
search: string;
|
|
33
|
+
/** Fragment including # (empty string if none) */
|
|
34
|
+
hash: string;
|
|
35
|
+
/** Parsed query parameters as key-value object */
|
|
36
|
+
query: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Result returned by parse()
|
|
41
|
+
*/
|
|
42
|
+
export interface ParseResult {
|
|
43
|
+
/** Information about the detected top-level domain / public suffix */
|
|
44
|
+
tld: TldInfo;
|
|
45
|
+
/** Parsed components of the URL */
|
|
46
|
+
url: ParsedUrl;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Parsing options
|
|
51
|
+
*/
|
|
52
|
+
export interface ParseOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Whether to consider private (non-ICANN) TLDs
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
allowPrivate?: boolean;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether to allow parsing when no known TLD is found
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
allowUnknown?: boolean;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Additional custom TLDs to recognize (each item can be "tld" or "sub.tld")
|
|
67
|
+
*/
|
|
68
|
+
extendedTlds?: string[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Parses a URL string and extracts domain/TLD information using the public suffix list.
|
|
73
|
+
*
|
|
74
|
+
* @param url - The URL or hostname to parse (string)
|
|
75
|
+
* @param options - Optional configuration
|
|
76
|
+
* @throws Error when URL is invalid or TLD cannot be determined (unless allowUnknown=true)
|
|
77
|
+
*/
|
|
78
|
+
export function parse(url: string, options?: ParseOptions): ParseResult;
|