UNPKG

@collight/dns-sd

Version:

A DNS Service Discovery implementation in modern TypeScript

3 lines (2 loc) 790 B
class p{constructor(t,s,o){this.name=t,this.protocol=s,this.subtype=o}static fromString(t){if(!t)throw new Error("Service type string is empty");let s=t.split(".").map(i=>i.trim());s=s.map(i=>i.startsWith("_")?i.slice(1):i);let o;const e=s.indexOf("sub");let r,n;if(e!==-1){if(e===0)throw new Error('Invalid service type: "sub" cannot be first element');o=s[e-1],r=s[e+1],n=s[e+2]}else r=s[0],n=s[1];if(r===void 0||n===void 0)throw new Error("Invalid service type format: missing name or protocol");return new p(r,n,o)}toString(){const t=[];return this.subtype!==void 0&&(t.push(`_${this.subtype}`),t.push("_sub")),this.name!==void 0&&t.push(`_${this.name}`),this.protocol!==void 0&&t.push(`_${this.protocol}`),t.join(".")}}export{p as ServiceType}; //# sourceMappingURL=ServiceType.js.map