UNPKG

mhtml-stream

Version:
56 lines (55 loc) 1.27 kB
export class Headers { #raw = new Map(); [Symbol.iterator]() { return this.entries(); } append(key, value) { const list = this.#raw.get(key); if (list === undefined) { this.#raw.set(key, [value]); } else { list.push(value); } } *entries(delim = ", ") { for (const [key, values] of this.#raw.entries()) { yield [key, values.join(delim)]; } } *entriesAll() { for (const [key, values] of this.#raw.entries()) { for (const val of values) { yield [key, val]; } } } get(key, delim = ", ") { const vals = this.#raw.get(key); if (vals === undefined) { return null; } else { return vals.join(delim); } } getAll(key) { return this.#raw.get(key) ?? []; } has(key) { return this.#raw.has(key); } keys() { return this.#raw.keys(); } *values(delim = ", ") { for (const vals of this.#raw.values()) { yield vals.join(delim); } } *valuesAll() { for (const vals of this.#raw.values()) { yield* vals; } } }