12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- "use strict";
- const pubsuffix = require("./pubsuffix-psl");
- const SPECIAL_USE_DOMAINS = ["local"];
- function permuteDomain(domain, allowSpecialUseDomain) {
- let pubSuf = null;
- if (allowSpecialUseDomain) {
- const domainParts = domain.split(".");
- if (SPECIAL_USE_DOMAINS.includes(domainParts[domainParts.length - 1])) {
- pubSuf = `${domainParts[domainParts.length - 2]}.${
- domainParts[domainParts.length - 1]
- }`;
- } else {
- pubSuf = pubsuffix.getPublicSuffix(domain);
- }
- } else {
- pubSuf = pubsuffix.getPublicSuffix(domain);
- }
- if (!pubSuf) {
- return null;
- }
- if (pubSuf == domain) {
- return [domain];
- }
- const prefix = domain.slice(0, -(pubSuf.length + 1));
- const parts = prefix.split(".").reverse();
- let cur = pubSuf;
- const permutations = [cur];
- while (parts.length) {
- cur = `${parts.shift()}.${cur}`;
- permutations.push(cur);
- }
- return permutations;
- }
- exports.permuteDomain = permuteDomain;
|