Add domainMatchPredicate helper, add TLD & proper domain matching pattern, TargetType refactor

This commit is contained in:
Xevion
2023-02-19 23:28:01 -06:00
parent bc57e119ce
commit bf6f942b39

View File

@@ -1,10 +1,4 @@
import type {RegistryType, ObjectType} from "@/types"; import type {TargetType} from "@/types";
// keeps track of how many registries we've loaded
const loadedRegistries = 0;
// registry data is stored in this
const registryData = {};
// keeps track of the elements we've created so we can assign a unique ID // keeps track of the elements we've created so we can assign a unique ID
// let elementCounter = 123456; // let elementCounter = 123456;
@@ -17,6 +11,10 @@ const cardTitles = {
"autnum": "AS Number", "autnum": "AS Number",
}; };
export function domainMatchPredicate(domain: string): (tld: string) => boolean {
return (tld) => domainMatch(tld, domain);
}
export function domainMatch(tld: string, domain: string): boolean { export function domainMatch(tld: string, domain: string): boolean {
return domain.toUpperCase().endsWith(`.${tld.toUpperCase()}`); return domain.toUpperCase().endsWith(`.${tld.toUpperCase()}`);
} }
@@ -762,16 +760,18 @@ export function createRDAPLink(url, title) {
} }
*/ */
const URIPatterns: [RegExp, RegistryType][] = [ // TODO: Provide full domain, TLD, Ipv4 & Ipv6 validators
const URIPatterns: [RegExp, TargetType][] = [
[/^\d+$/, "autnum"], [/^\d+$/, "autnum"],
[/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/?\d*$/, "ip4"], [/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/?\d*$/, "ip4"],
[/^[0-9a-f:]{2,}\/?\d*$/, "ip6"], [/^[0-9a-f:]{2,}\/?\d*$/, "ip6"],
[/^https?:/, "url"], [/^https?:/, "url"],
[/^{/, "json"], [/^{/, "json"],
[/./, "domain"], [/^\.\w+$/, "tld"],
[/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?/, "domain"],
]; ];
export function getType(value: string): RegistryType | null { export function getType(value: string): TargetType | null {
for (const [pattern, type] of URIPatterns) { for (const [pattern, type] of URIPatterns) {
if (pattern.test(value)) if (pattern.test(value))
return type; return type;