tldts-icann 7.3.1 → 7.4.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/README.md CHANGED
@@ -50,6 +50,7 @@ Alternatively, you can try it _directly in your browser_ here: https://npm.runki
50
50
  - `tldts.parse(url | hostname, options)`
51
51
  - `tldts.getHostname(url | hostname, options)`
52
52
  - `tldts.getDomain(url | hostname, options)`
53
+ - `tldts.getFullDomain(url | hostname, options)`
53
54
  - `tldts.getPublicSuffix(url | hostname, options)`
54
55
  - `tldts.getSubdomain(url, | hostname, options)`
55
56
  - `tldts.getDomainWithoutSuffix(url | hostname, options)`
@@ -190,6 +191,27 @@ getDomain('fr.t.co'); // returns `t.co`
190
191
  getDomain('https://user:password@example.co.uk:8080/some/path?and&query#hash'); // returns `example.co.uk`
191
192
  ```
192
193
 
194
+ ### getFullDomain(url | hostname, options?)
195
+
196
+ Returns the full domain — the subdomain together with the registrable domain (as
197
+ returned by `getDomain(...)`), i.e. the whole hostname _including_ any subdomain —
198
+ or `null` when the input has no registrable domain (IP address, single label,
199
+ bare public suffix, …). The result is the normalized hostname (lower-cased,
200
+ trailing dot stripped); it is not a DNS-absolute name (no trailing root dot) and
201
+ no IDNA/punycode conversion is performed.
202
+
203
+ ```javascript
204
+ const { getFullDomain } = require('tldts-icann');
205
+
206
+ getFullDomain('google.com'); // returns `google.com`
207
+ getFullDomain('fr.google.com'); // returns `fr.google.com`
208
+ getFullDomain('foo.google.co.uk'); // returns `foo.google.co.uk`
209
+ getFullDomain('t.co'); // returns `t.co`
210
+ getFullDomain('fr.t.co'); // returns `fr.t.co`
211
+ getFullDomain('1.2.3.4'); // returns null (no registrable domain)
212
+ getFullDomain('localhost'); // returns null
213
+ ```
214
+
193
215
  ### getDomainWithoutSuffix(url | hostname, options?)
194
216
 
195
217
  Returns the domain (as returned by `getDomain(...)`) without the public suffix part.
package/dist/cjs/index.js CHANGED
@@ -1134,6 +1134,14 @@ function getDomain(url, options) {
1134
1134
  /*@__INLINE__*/ resetResult(RESULT);
1135
1135
  return parseImpl(url, 3 /* FLAG.DOMAIN */, suffixLookup, options, RESULT).domain;
1136
1136
  }
1137
+ function getFullDomain(url, options) {
1138
+ /*@__INLINE__*/ resetResult(RESULT);
1139
+ const result = parseImpl(url, 3 /* FLAG.DOMAIN */, suffixLookup, options, RESULT);
1140
+ // The hostname *is* the full domain (subdomain + domain) whenever a
1141
+ // registrable domain exists; gate on `domain` so non-registrable inputs
1142
+ // (IPs, suffix-less or invalid hostnames) return `null` like `getDomain`.
1143
+ return result.domain === null ? null : result.hostname;
1144
+ }
1137
1145
  function getSubdomain(url, options) {
1138
1146
  /*@__INLINE__*/ resetResult(RESULT);
1139
1147
  return parseImpl(url, 4 /* FLAG.SUB_DOMAIN */, suffixLookup, options, RESULT)
@@ -1147,6 +1155,7 @@ function getDomainWithoutSuffix(url, options) {
1147
1155
 
1148
1156
  exports.getDomain = getDomain;
1149
1157
  exports.getDomainWithoutSuffix = getDomainWithoutSuffix;
1158
+ exports.getFullDomain = getFullDomain;
1150
1159
  exports.getHostname = getHostname;
1151
1160
  exports.getPublicSuffix = getPublicSuffix;
1152
1161
  exports.getSubdomain = getSubdomain;