UNPKG

@collight/dns-sd

Version:

A DNS Service Discovery implementation in modern TypeScript

3 lines (2 loc) 868 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class p{constructor(t,e,o){this.name=t,this.protocol=e,this.subtype=o}static fromString(t){if(!t)throw new Error("Service type string is empty");let e=t.split(".").map(s=>s.trim());e=e.map(s=>s.startsWith("_")?s.slice(1):s);let o;const i=e.indexOf("sub");let r,n;if(i!==-1){if(i===0)throw new Error('Invalid service type: "sub" cannot be first element');o=e[i-1],r=e[i+1],n=e[i+2]}else r=e[0],n=e[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(".")}}exports.ServiceType=p; //# sourceMappingURL=ServiceType.cjs.map