Comparing version 0.3.2 to 0.3.3
import "./chunk-JUWXSDKJ.js"; | ||
function normalizeName(name) { | ||
if (typeof name !== "string") { | ||
name = String(name); | ||
} | ||
if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === "") { | ||
throw new TypeError('Invalid character in header field name: "' + name + '"'); | ||
} | ||
return name.toLowerCase(); | ||
} | ||
class HeadersMock { | ||
@@ -8,27 +17,27 @@ headers = /* @__PURE__ */ new Map(); | ||
if (Array.isArray(init)) { | ||
init.forEach(([key, name]) => this.headers.set(key, name)); | ||
init.forEach(([key, name]) => this.headers.set(normalizeName(key), String(name))); | ||
return; | ||
} | ||
if (init instanceof HeadersMock || typeof Headers !== "undefined" && init instanceof Headers) { | ||
init.forEach((key, name) => this.headers.set(key, name)); | ||
init.forEach((value, key) => this.headers.set(normalizeName(key), String(value))); | ||
return; | ||
} | ||
for (const key in init) { | ||
this.headers.set(key, String(init[key])); | ||
this.headers.set(normalizeName(key), String(init[key])); | ||
} | ||
} | ||
append(name, value) { | ||
this.headers.set(name, value); | ||
this.headers.set(normalizeName(name), String(value)); | ||
} | ||
delete(name) { | ||
this.headers.delete(name); | ||
this.headers.delete(normalizeName(name)); | ||
} | ||
get(name) { | ||
return this.headers.get(name) ?? null; | ||
return this.headers.get(normalizeName(name)) ?? null; | ||
} | ||
has(name) { | ||
return this.headers.has(name); | ||
return this.headers.has(normalizeName(name)); | ||
} | ||
set(name, value) { | ||
this.headers.set(name, value); | ||
this.headers.set(normalizeName(name), String(value)); | ||
} | ||
@@ -35,0 +44,0 @@ forEach(callbackfn, thisArg) { |
{ | ||
"name": "vi-fetch", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Easiest way to mock fetch", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
36553
1104