service-worker-mock
Advanced tools
Comparing version 1.10.1 to 1.10.2
@@ -10,3 +10,3 @@ const Blob = require('./Blob'); | ||
this.bodyUsed = false; | ||
this.body = new Blob([body]); | ||
this.body = body instanceof Blob ? body : new Blob([body]); | ||
} | ||
@@ -18,15 +18,15 @@ arrayBuffer() { | ||
blob() { | ||
this.resolve('json', body => new Blob([body])); | ||
return this.resolve('blob', body => new Blob([body])); | ||
} | ||
json() { | ||
this.resolve('json', body => JSON.parse(body._text)); | ||
return this.resolve('json', body => JSON.parse(body.text)); | ||
} | ||
text() { | ||
this.resolve('json', body => body._text); | ||
return this.resolve('text', body => body.text); | ||
} | ||
resolve(name, resolver) { | ||
if (this.bodyUsed) throwBodyUsed('text'); | ||
if (this.bodyUsed) throwBodyUsed(name); | ||
this.bodyUsed = true; | ||
@@ -33,0 +33,0 @@ return Promise.resolve(resolver(this.body)); |
// stubs https://developer.mozilla.org/en-US/docs/Web/API/Response | ||
class Response { | ||
constructor(body, init) { | ||
this.body = body || ''; | ||
const Body = require('./Body'); | ||
const isSupportedBodyType = (body) => | ||
(body === null) || | ||
(body instanceof Blob) || | ||
(typeof body === 'string'); | ||
class Response extends Body { | ||
constructor(body = null, init) { | ||
if (!isSupportedBodyType(body)) { | ||
throw new TypeError('Response body must be one of: Blob, USVString, null'); | ||
} | ||
super(body); | ||
this.status = (init && typeof init.status === 'number') ? init.status : 200; | ||
@@ -23,12 +33,4 @@ this.ok = this.status >= 200 && this.status < 300; | ||
} | ||
text() { | ||
try { | ||
return Promise.resolve(this.body.toString()); | ||
} catch (err) { | ||
return Promise.resolve(Object.prototype.toString.apply(this.body)); | ||
} | ||
} | ||
} | ||
module.exports = Response; |
{ | ||
"name": "service-worker-mock", | ||
"version": "1.10.1", | ||
"version": "1.10.2", | ||
"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
23513
617