UNPKG

edge-mock

Version:

types for testing an developer edge applications

75 lines 1.93 kB
"use strict"; // stubs https://developer.mozilla.org/en-US/docs/Web/API/Headers Object.defineProperty(exports, "__esModule", { value: true }); exports.asHeaders = exports.EdgeHeaders = void 0; class EdgeHeaders { map; constructor(init = {}) { if (init instanceof EdgeHeaders) { this.map = new Map(init); } else { let a; if (init instanceof Map) { a = [...init]; } else if (Array.isArray(init)) { a = init; } else { a = Object.entries(init); } this.map = new Map(a.map(([k, v]) => [k.toLowerCase(), v])); } } entries() { return this.map.entries(); } keys() { return this.map.keys(); } values() { return this.map.values(); } append(name, value) { const k = name.toLowerCase(); if (this.map.has(k)) { value = `${this.map.get(k)},${value}`; } this.map.set(k, value); } delete(name) { this.map.delete(name.toLowerCase()); } forEach(callback, thisArg) { const cb = (value, key) => callback(value, key, this); this.map.forEach(cb, thisArg); } get(name) { const k = name.toLowerCase(); return this.map.get(k) || null; } has(name) { return this.map.has(name.toLowerCase()); } set(name, value) { this.map.set(name.toLowerCase(), value); } [Symbol.iterator]() { return this.entries(); } } exports.EdgeHeaders = EdgeHeaders; function asHeaders(h, default_headers = {}) { if (!h) { return new EdgeHeaders(default_headers); } else if (h instanceof EdgeHeaders) { return h; } else { return new EdgeHeaders(h); } } exports.asHeaders = asHeaders; //# sourceMappingURL=Headers.js.map