amis-rpc-design/node_modules/tldjs/lib/public-suffix.js
2023-10-07 19:42:30 +08:00

30 lines
681 B
JavaScript

'use strict';
var extractTldFromHost = require('./from-host.js');
/**
* Returns the public suffix (including exact matches)
*
* @api
* @since 1.5
* @param {string} hostname
* @return {string}
*/
module.exports = function getPublicSuffix(rules, hostname) {
// First check if `hostname` is already a valid top-level Domain.
if (rules.hasTld(hostname)) {
return hostname;
}
var candidate = rules.suffixLookup(hostname);
if (candidate === null) {
// Prevailing rule is '*' so we consider the top-level domain to be the
// public suffix of `hostname` (e.g.: 'example.org' => 'org').
return extractTldFromHost(hostname);
}
return candidate;
};