service-worker-mock
Advanced tools
Comparing version 1.7.0 to 1.7.1
// stubs https://developer.mozilla.org/en-US/docs/Web/API/Headers | ||
class Headers extends Map {} | ||
class Headers { | ||
constructor(meta) { | ||
if (meta && meta instanceof Headers) { | ||
this._map = new Map(meta._map); | ||
} else if (meta && typeof meta === 'object') { | ||
this._map = new Map(Object.entries(meta)); | ||
} else { | ||
this._map = new Map(); | ||
} | ||
} | ||
append(name, value) { | ||
if (this._map.has(name)) { | ||
value = `${this._map.get(name)},${value}`; | ||
} | ||
this._map.set(name, value); | ||
} | ||
delete(name) { | ||
this._map.delete(name); | ||
} | ||
entries() { | ||
return this._map.entries(); | ||
} | ||
get(name) { | ||
return this._map.get(name) || ''; | ||
} | ||
has(name) { | ||
return this._map.has(name); | ||
} | ||
keys() { | ||
return this._map.keys(); | ||
} | ||
set(name, value) { | ||
this._map.set(name, value); | ||
} | ||
values() { | ||
return this._map.values(); | ||
} | ||
[Symbol.iterator]() { | ||
return this._map.values(); | ||
} | ||
} | ||
Headers.Headers = (meta) => new Headers(meta); | ||
module.exports = Headers; |
@@ -7,5 +7,5 @@ // stubs https://developer.mozilla.org/en-US/docs/Web/API/Request | ||
const DEFAULT_HEADERS = [ | ||
['accept', '*/*'] | ||
]; | ||
const DEFAULT_HEADERS = { | ||
accept: '*/*' | ||
}; | ||
@@ -22,3 +22,15 @@ const throwBodyUsed = () => { | ||
this.mode = (options && options.mode) || 'same-origin'; // FF defaults to cors | ||
this.headers = (options && options.headers) || new Headers(DEFAULT_HEADERS); | ||
// Transform options.headers to Headers object | ||
if (options && options.headers) { | ||
if (options.headers instanceof Headers) { | ||
this.headers = options.headers; | ||
} else if (typeof options.headers === 'object') { | ||
this.headers = new Headers(options.headers); | ||
} else { | ||
throw new TypeError('Cannot construct request.headers: invalid data'); | ||
} | ||
} else { | ||
this.headers = new Headers(DEFAULT_HEADERS); | ||
} | ||
} | ||
@@ -25,0 +37,0 @@ |
{ | ||
"name": "service-worker-mock", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21968
590