whoisx-parser 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Elyess Zouaghi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # whoisx-parser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/elyess/whoisx-parser/actions/workflows/ci.yml/badge.svg)](https://github.com/elyess/whoisx-parser/actions/workflows/ci.yml)
4
+ [![Docs](https://github.com/elyess/whoisx-parser/actions/workflows/docs.yml/badge.svg)](https://elyess.github.io/whoisx-parser/)
5
+ [![npm version](https://img.shields.io/npm/v/whoisx-parser.svg)](https://www.npmjs.com/package/whoisx-parser)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
7
+
8
+ Zero-dependency TypeScript parser for raw WHOIS text and RFC 9083 RDAP JSON. Turns domain, IP network, and ASN responses into one consistent typed shape.
9
+
10
+ Part of the WhoisX project alongside [whoisx-client](https://github.com/elyess/whoisx-client) and the [whoisx](https://github.com/elyess/whoisx) umbrella package.
11
+
12
+ [Documentation](https://elyess.github.io/whoisx-parser/)
13
+
14
+ ## What it does
15
+
16
+ - Parses raw WHOIS text and RFC 9083 RDAP JSON into the same typed record union (`ParsedDomainRecord | ParsedIpRecord | ParsedAsnRecord`).
17
+ - Accepts `whoisx-client` `LookupResult` objects directly without needing it as a dependency.
18
+ - Handles ICANN / gTLD output plus ccTLD dialects: Nominet (`.uk`), DENIC (`.de`), AFNIC (`.fr`), JPRS (`.jp`), EURid (`.eu`), TCINET (`.ru`), Registro.br (`.br`), DNS Belgium (`.be`), NIC.it (`.it`), NIC.pl (`.pl`), KRNIC (`.kr`), IIS (`.se`), CNNIC (`.cn`), and auDA (`.au`).
19
+ - Parses IPv4, IPv6, CIDR, and ASN output from ARIN, RIPE NCC, APNIC, LACNIC, and AFRINIC, including `% Abuse contact` comment lines.
20
+ - Normalizes ~15+ WHOIS date formats to ISO-8601 UTC and normalizes EPP/RDAP status strings.
21
+ - Detects availability (`isAvailable`), rate limiting (`isRateLimited`), reserved domains, and GDPR/privacy redaction (`isPrivacyProtected`).
22
+ - Zero runtime dependencies and no Node-only APIs (works in Node 18+, Bun, Deno, edge workers, and browsers).
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ npm install whoisx-parser
28
+ ```
29
+
30
+ Want both the client and parser together with a combined `whois()` helper? Install the umbrella package instead:
31
+
32
+ ```bash
33
+ npm install whoisx
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### With `whoisx-client`
39
+
40
+ ```ts
41
+ import { lookup } from 'whoisx-client';
42
+ import { parse } from 'whoisx-parser';
43
+
44
+ const response = await lookup('example.com');
45
+ const record = parse(response);
46
+
47
+ if (record.kind === 'domain') {
48
+ console.log(record.domain, record.status);
49
+ console.log(record.registrar?.name, record.dates.expires);
50
+ console.log(record.nameservers.map((ns) => ns.host));
51
+ }
52
+ ```
53
+
54
+ ### Standalone (raw WHOIS text or RDAP JSON)
55
+
56
+ ```ts
57
+ import { parse, parseDomain, parseIp, parseAsn, parseRdap } from 'whoisx-parser';
58
+
59
+ const domain = parseDomain(rawWhoisText);
60
+ const ip = parseIp(arinText);
61
+ const asn = parseAsn(ripeAsnText);
62
+ const fromRdap = parseRdap(rdapJsonObject);
63
+ const auto = parse(rawWhoisOrRdapJson);
64
+ ```
65
+
66
+ ## Docs
67
+
68
+ - [Getting Started](https://elyess.github.io/whoisx-parser/guide/getting-started)
69
+ - [Examples](https://elyess.github.io/whoisx-parser/guide/examples)
70
+ - [WhoisX & whoisx-client](https://elyess.github.io/whoisx-parser/guide/ecosystem)
71
+ - [API Reference](https://elyess.github.io/whoisx-parser/api/)
72
+ - [Supported Registries & Dialects](https://elyess.github.io/whoisx-parser/reference/registries)
73
+ - [Versions](https://elyess.github.io/whoisx-parser/versions/)
74
+
75
+ ## Scripts
76
+
77
+ ```bash
78
+ npm run typecheck # tsc --noEmit
79
+ npm run lint # eslint
80
+ npm run test # vitest run
81
+ npm run test:coverage # vitest with coverage thresholds
82
+ npm run build # tsup ESM + .d.ts bundle
83
+ npm run docs:dev # local VitePress server
84
+ npm run docs:build # build GitHub Pages site
85
+ ```
86
+
87
+ ## License
88
+
89
+ [MIT](./LICENSE) © 2025-2026 Elyess Zouaghi
@@ -0,0 +1,278 @@
1
+ type RecordKind = 'domain' | 'ip' | 'asn';
2
+ type SourceProtocol = 'rdap' | 'whois';
3
+ type RegistrationStatus = 'registered' | 'available' | 'reserved' | 'redacted' | 'rate_limited' | 'error' | 'unknown';
4
+ type ContactRole = 'registrant' | 'admin' | 'tech' | 'billing' | 'abuse' | 'registrar' | 'other';
5
+ interface ParsedContact {
6
+ readonly role: ContactRole;
7
+ readonly handle?: string;
8
+ readonly name?: string;
9
+ readonly organization?: string;
10
+ readonly email?: string;
11
+ readonly phone?: string;
12
+ readonly fax?: string;
13
+ readonly street?: readonly string[];
14
+ readonly city?: string;
15
+ readonly state?: string;
16
+ readonly postalCode?: string;
17
+ readonly country?: string;
18
+ readonly isRedacted: boolean;
19
+ }
20
+ interface ParsedRegistrar {
21
+ readonly name?: string;
22
+ readonly ianaId?: string;
23
+ readonly url?: string;
24
+ readonly whoisServer?: string;
25
+ readonly abuseEmail?: string;
26
+ readonly abusePhone?: string;
27
+ }
28
+ interface ParsedNameserver {
29
+ readonly host: string;
30
+ readonly ipv4?: readonly string[];
31
+ readonly ipv6?: readonly string[];
32
+ }
33
+ interface ParsedDates {
34
+ readonly created?: string;
35
+ readonly updated?: string;
36
+ readonly expires?: string;
37
+ readonly transferred?: string;
38
+ readonly raw: Readonly<Record<string, string>>;
39
+ }
40
+ interface ParsedDnssec {
41
+ readonly signed: boolean;
42
+ readonly raw?: string;
43
+ }
44
+ interface ParsedRecordBase {
45
+ readonly kind: RecordKind;
46
+ readonly protocol: SourceProtocol;
47
+ readonly status: RegistrationStatus;
48
+ readonly isAvailable: boolean;
49
+ readonly isRateLimited: boolean;
50
+ readonly isPrivacyProtected: boolean;
51
+ readonly dates: ParsedDates;
52
+ readonly contacts: readonly ParsedContact[];
53
+ readonly notices: readonly string[];
54
+ readonly warnings: readonly string[];
55
+ /** Raw key-value fields extracted from WHOIS text (present when includeRawFields is true) */
56
+ readonly rawFields?: Readonly<Record<string, readonly string[]>>;
57
+ }
58
+ interface ParsedDomainRecord extends ParsedRecordBase {
59
+ readonly kind: 'domain';
60
+ readonly domain?: string;
61
+ readonly unicodeDomain?: string;
62
+ readonly tld?: string;
63
+ readonly registryId?: string;
64
+ readonly registrar?: ParsedRegistrar;
65
+ readonly statuses: readonly string[];
66
+ readonly rawStatuses: readonly string[];
67
+ readonly nameservers: readonly ParsedNameserver[];
68
+ readonly dnssec?: ParsedDnssec;
69
+ }
70
+ interface ParsedIpRecord extends ParsedRecordBase {
71
+ readonly kind: 'ip';
72
+ readonly range?: string;
73
+ readonly startAddress?: string;
74
+ readonly endAddress?: string;
75
+ readonly ipVersion?: 4 | 6;
76
+ readonly cidrs: readonly string[];
77
+ readonly netName?: string;
78
+ readonly handle?: string;
79
+ readonly parent?: string;
80
+ readonly netType?: string;
81
+ readonly organization?: string;
82
+ readonly orgId?: string;
83
+ readonly country?: string;
84
+ readonly originAsns: readonly string[];
85
+ readonly abuseEmails: readonly string[];
86
+ readonly description: readonly string[];
87
+ }
88
+ interface ParsedAsnRecord extends ParsedRecordBase {
89
+ readonly kind: 'asn';
90
+ readonly asn?: number;
91
+ readonly asNumber?: string;
92
+ readonly startAutnum?: number;
93
+ readonly endAutnum?: number;
94
+ readonly name?: string;
95
+ readonly handle?: string;
96
+ readonly organization?: string;
97
+ readonly orgId?: string;
98
+ readonly country?: string;
99
+ readonly abuseEmails: readonly string[];
100
+ readonly description: readonly string[];
101
+ }
102
+ type ParsedRecord = ParsedDomainRecord | ParsedIpRecord | ParsedAsnRecord;
103
+ interface ParseOptions {
104
+ /** Force record kind instead of auto-detecting */
105
+ readonly kind?: RecordKind;
106
+ /** Optional TLD hint (e.g. 'uk', 'de', 'jp') to help disambiguate registry formats */
107
+ readonly tld?: string;
108
+ /** Optional source server hostname or URL hint */
109
+ readonly source?: string;
110
+ /** Include extracted raw WHOIS key-value map on the result (default: false) */
111
+ readonly includeRawFields?: boolean;
112
+ }
113
+ /** Structural match for RFC 9083 RDAP objects (compatible with whoisx-client RdapResponse) */
114
+ interface RdapInput {
115
+ readonly objectClassName?: string;
116
+ readonly handle?: string;
117
+ readonly ldhName?: string;
118
+ readonly unicodeName?: string;
119
+ readonly status?: readonly string[];
120
+ readonly rdapConformance?: readonly string[];
121
+ readonly links?: readonly {
122
+ readonly value?: string;
123
+ readonly rel?: string;
124
+ readonly href?: string;
125
+ readonly type?: string;
126
+ readonly title?: string;
127
+ }[];
128
+ readonly events?: readonly {
129
+ readonly eventAction?: string;
130
+ readonly eventActor?: string;
131
+ readonly eventDate?: string;
132
+ }[];
133
+ readonly nameservers?: readonly {
134
+ readonly objectClassName?: string;
135
+ readonly ldhName?: string;
136
+ readonly unicodeName?: string;
137
+ readonly ipAddresses?: {
138
+ readonly v4?: readonly string[];
139
+ readonly v6?: readonly string[];
140
+ };
141
+ }[];
142
+ readonly secureDNS?: {
143
+ readonly zoneSigned?: boolean;
144
+ readonly delegationSigned?: boolean;
145
+ readonly maxSigLife?: number;
146
+ readonly dsData?: readonly Record<string, unknown>[];
147
+ readonly keyData?: readonly Record<string, unknown>[];
148
+ };
149
+ readonly entities?: readonly RdapEntityInput[];
150
+ readonly notices?: readonly RdapNoticeInput[];
151
+ readonly remarks?: readonly RdapNoticeInput[];
152
+ readonly startAddress?: string;
153
+ readonly endAddress?: string;
154
+ readonly ipVersion?: string;
155
+ readonly country?: string;
156
+ readonly name?: string;
157
+ readonly type?: string;
158
+ readonly parentHandle?: string;
159
+ readonly startAutnum?: number;
160
+ readonly endAutnum?: number;
161
+ readonly cidr0_cidrs?: readonly {
162
+ readonly v4prefix?: string;
163
+ readonly v6prefix?: string;
164
+ readonly length?: number;
165
+ }[];
166
+ readonly [key: string]: unknown;
167
+ }
168
+ interface RdapEntityInput {
169
+ readonly objectClassName?: string;
170
+ readonly handle?: string;
171
+ readonly roles?: readonly string[];
172
+ readonly vcardArray?: readonly unknown[];
173
+ readonly publicIds?: readonly {
174
+ readonly type?: string;
175
+ readonly identifier?: string;
176
+ }[];
177
+ readonly entities?: readonly RdapEntityInput[];
178
+ readonly links?: readonly {
179
+ readonly rel?: string;
180
+ readonly href?: string;
181
+ }[];
182
+ readonly status?: readonly string[];
183
+ }
184
+ interface RdapNoticeInput {
185
+ readonly title?: string;
186
+ readonly type?: string;
187
+ readonly description?: readonly string[];
188
+ }
189
+ /** Structural match for whoisx-client LookupResult */
190
+ interface ClientLookupResultLike {
191
+ readonly query?: string;
192
+ readonly normalizedQuery?: string;
193
+ readonly kind?: 'domain' | 'ipv4' | 'ipv6' | 'ip-cidr' | 'asn';
194
+ readonly protocol: 'rdap' | 'whois';
195
+ readonly tld?: string;
196
+ readonly raw: string;
197
+ readonly rdap?: RdapInput;
198
+ readonly source?: string;
199
+ }
200
+ type ParseInput = string | RdapInput | ClientLookupResultLike;
201
+
202
+ /** Parses raw WHOIS text into a normalized domain, IP, or ASN record. */
203
+ declare function parseWhois(rawText: string, options?: ParseOptions): ParsedRecord;
204
+ /**
205
+ * Parses raw WHOIS text, an RFC 9083 RDAP object/JSON string, or a LookupResult
206
+ * returned by whoisx-client into a normalized ParsedRecord.
207
+ */
208
+ declare function parse(input: ParseInput, options?: ParseOptions): ParsedRecord;
209
+ declare function parseDomain(input: ParseInput, options?: Omit<ParseOptions, 'kind'>): ParsedDomainRecord;
210
+ declare function parseIp(input: ParseInput, options?: Omit<ParseOptions, 'kind'>): ParsedIpRecord;
211
+ declare function parseAsn(input: ParseInput, options?: Omit<ParseOptions, 'kind'>): ParsedAsnRecord;
212
+
213
+ /** Parses an RFC 9083 RDAP object (or JSON string) into a normalized ParsedRecord. */
214
+ declare function parseRdap(input: RdapInput | string, options?: ParseOptions): ParsedRecord;
215
+
216
+ interface ExtractedVcard {
217
+ readonly name?: string;
218
+ readonly organization?: string;
219
+ readonly email?: string;
220
+ readonly phone?: string;
221
+ readonly fax?: string;
222
+ readonly street?: readonly string[];
223
+ readonly city?: string;
224
+ readonly state?: string;
225
+ readonly postalCode?: string;
226
+ readonly country?: string;
227
+ }
228
+ /** Extracts contact fields from an RFC 7095 jCard (RDAP vcardArray). */
229
+ declare function parseVcardArray(vcardArray: readonly unknown[] | undefined): ExtractedVcard;
230
+
231
+ interface ExtractedFields {
232
+ /** Normalized lowercased key -> ordered non-empty values */
233
+ readonly fields: Map<string, string[]>;
234
+ /** Indented multi-line sections (Nominet .uk, EURid .eu, NIC.it, DNS.be) */
235
+ readonly blocks: Map<string, string[]>;
236
+ /** Comment / banner lines (%, #, >>>) useful for abuse notices or warnings */
237
+ readonly notices: string[];
238
+ }
239
+ /**
240
+ * Tokenizes raw WHOIS text into normalized key-value pairs, indented block sections,
241
+ * and banner/comment lines. Handles ICANN "Key: Val", JPRS "[Key] Val", dot-leader
242
+ * "Key....: Val", and Nominet/EURid indented multi-line blocks.
243
+ */
244
+ declare function extractWhoisFields(rawText: string): ExtractedFields;
245
+ declare function dedupeStrings(values: readonly string[]): string[];
246
+
247
+ /** Infers whether raw WHOIS fields describe a domain, IP network, or ASN. */
248
+ declare function detectWhoisKind(extracted: ExtractedFields): RecordKind;
249
+
250
+ /** Parses raw ASN WHOIS text from ARIN, RIPE, APNIC, LACNIC, or AFRINIC. */
251
+ declare function parseWhoisAsn(rawText: string, options?: ParseOptions, preExtracted?: ExtractedFields): ParsedAsnRecord;
252
+
253
+ /** Parses raw domain WHOIS text across ICANN and major ccTLD formats. */
254
+ declare function parseWhoisDomain(rawText: string, options?: ParseOptions, preExtracted?: ExtractedFields): ParsedDomainRecord;
255
+
256
+ /** Parses raw IP network WHOIS text from ARIN, RIPE, APNIC, LACNIC, or AFRINIC. */
257
+ declare function parseWhoisIp(rawText: string, options?: ParseOptions, preExtracted?: ExtractedFields): ParsedIpRecord;
258
+
259
+ /** Parses common WHOIS and RDAP date strings into ISO-8601 UTC, or returns undefined if unparseable. */
260
+ declare function parseWhoisDate(raw: string | undefined): string | undefined;
261
+
262
+ /** Normalizes an ICANN EPP or RDAP status string (e.g. "client transfer prohibited https://..." -> "clientTransferProhibited"). */
263
+ declare function normalizeEppStatus(raw: string): string;
264
+ declare function isRedactedValue(value: string | undefined): boolean;
265
+ declare function detectAvailability(text: string): boolean;
266
+ declare function detectRateLimit(text: string): boolean;
267
+ declare function detectReserved(text: string): boolean;
268
+ declare function detectPrivacyProtected(text: string): boolean;
269
+
270
+ type ParseErrorCode = 'empty_input' | 'invalid_input' | 'invalid_rdap' | 'unsupported_kind';
271
+ declare class ParseError extends Error {
272
+ readonly code: ParseErrorCode;
273
+ constructor(code: ParseErrorCode, message: string, cause?: unknown);
274
+ toJSON(): Record<string, unknown>;
275
+ }
276
+ declare function isParseError(error: unknown): error is ParseError;
277
+
278
+ export { type ClientLookupResultLike, type ContactRole, type ExtractedFields, type ExtractedVcard, ParseError, type ParseErrorCode, type ParseInput, type ParseOptions, type ParsedAsnRecord, type ParsedContact, type ParsedDates, type ParsedDnssec, type ParsedDomainRecord, type ParsedIpRecord, type ParsedNameserver, type ParsedRecord, type ParsedRecordBase, type ParsedRegistrar, type RdapEntityInput, type RdapInput, type RdapNoticeInput, type RecordKind, type RegistrationStatus, type SourceProtocol, dedupeStrings, detectAvailability, detectPrivacyProtected, detectRateLimit, detectReserved, detectWhoisKind, extractWhoisFields, isParseError, isRedactedValue, normalizeEppStatus, parse, parseAsn, parseDomain, parseIp, parseRdap, parseVcardArray, parseWhois, parseWhoisAsn, parseWhoisDate, parseWhoisDomain, parseWhoisIp };