UNPKG

@collight/dns-sd

Version:

A DNS Service Discovery implementation in modern TypeScript

45 lines (44 loc) 1.83 kB
/** * Compares two strings for equality in a case-insensitive manner, * but only ASCII uppercase letters (`A-Z`) are converted to lowercase before comparison. */ export declare function nameEquals(a: string, b: string): boolean; /** * Encodes a record of key-value string pairs into an array of Buffer objects, * where each buffer contains a string in the format `"key=value"`. * * @param data - An object whose string keys and values will be encoded. * Defaults to an empty object. * @returns An array of Buffer instances, each representing one `"key=value"` pair. * * @example * ```ts * encodeTXT({ foo: "bar", baz: "qux" }) * // [Buffer.from("foo=bar"), Buffer.from("baz=qux")] * ``` */ export declare function encodeTXT(data?: Record<string, string | number | boolean | Buffer>): Buffer[]; /** * Decodes an input buffer or array of buffers (or strings) containing * `"key=value"` pairs into a single object mapping keys to values. * * Each input item is expected to be a string or Buffer representing one key-value pair. * Items that do not match the `"key=value"` pattern are ignored. * * @param buffer - A string, Buffer, or an array of these, each containing `"key=value"` format data. * @returns An object where each key is mapped to its corresponding decoded value. * * @example * ```ts * decodeTXT([Buffer.from("foo=bar"), "baz=qux"]) * // { foo: "bar", baz: "qux" } * * decodeTXT(Buffer.from("hello=world")) * // { hello: "world" } * * decodeTXT(["invalid", "key=value"]) * // { key: "value" } // "invalid" ignored * ``` */ export declare function decodeTXT(buffer: string | Buffer | (string | Buffer)[], binary: false): Record<string, string>; export declare function decodeTXT(buffer: string | Buffer | (string | Buffer)[], binary: true): Record<string, Buffer>;