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

21 lines
493 B
JavaScript

'use strict';
/**
* Returns the subdomain of a hostname string
*
* @api
* @param {string} hostname
* @param {string} domain - the root domain of the hostname
* @return {string|null} a subdomain string if any, blank string if subdomain
* is empty, otherwise null.
*/
module.exports = function getSubdomain(hostname, domain) {
// No domain found? Just abort, abort!
if (domain === null) {
return null;
}
return hostname.substr(0, hostname.length - domain.length - 1);
};