UNPKG

@collight/dns-sd

Version:

A DNS Service Discovery implementation in modern TypeScript

43 lines (42 loc) 1.56 kB
/** * Represents a network service type with optional protocol and subtype. */ export declare class ServiceType { readonly name?: string; readonly protocol?: string; readonly subtype?: string; constructor(name?: string, protocol?: string, subtype?: string); /** * Parses a service type string into a ServiceType instance. * * Expected formats include: * - "_http._tcp" * - "_printer._sub._http._tcp" (a subtype "printer" of "_http._tcp") * * @param {string} input - The service type string to parse. * @returns {ServiceType} The parsed ServiceType instance. * * @example * ServiceType.fromString('_http._tcp'); * // { name: "http", protocol: "tcp", subtype: undefined } * * ServiceType.fromString('_printer._sub._http._tcp'); * // { name: "http", protocol: "tcp", subtype: "printer" } * * @see {@link https://datatracker.ietf.org/doc/html/rfc6763#section-7.1 | RFC 6763 §7.1 Selective Instance Enumeration (Subtypes)} */ static fromString(input: string): ServiceType; /** * Serializes the ServiceType instance into a string following DNS-SD format. * * @returns {string} The serialized service type string. * * @example * const svc = new ServiceType('http', 'tcp'); * console.log(svc.toString()); // _http._tcp * * const svcWithSubtype = new ServiceType('http', 'tcp', 'printer'); * console.log(svcWithSubtype.toString()); // _printer._sub._http._tcp */ toString(): string; }