@php-wasm/node-polyfills
Advanced tools
Comparing version 0.6.6 to 0.6.7
110
index.js
@@ -1,59 +0,69 @@ | ||
if (typeof File > "u") { | ||
class e extends Blob { | ||
constructor(r, n, i) { | ||
super(r); | ||
let o; | ||
i != null && i.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = n || ""; | ||
const u = function() { | ||
var o; | ||
return typeof process < "u" && ((o = process.release) == null ? void 0 : o.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : ( | ||
// @ts-ignore | ||
typeof WorkerGlobalScope < "u" && // @ts-ignore | ||
self instanceof WorkerGlobalScope ? "WORKER" : "NODE" | ||
); | ||
}(); | ||
if (u === "NODE") { | ||
let o = function(e) { | ||
return new Promise(function(t, n) { | ||
e.onload = e.onerror = function(i) { | ||
e.onload = e.onerror = null, i.type === "load" ? t(e.result) : n(new Error("Failed to read the blob/file")); | ||
}; | ||
}); | ||
}, a = function() { | ||
const e = new Uint8Array([1, 2, 3, 4]), n = new File([e], "test").stream(); | ||
try { | ||
return n.getReader({ mode: "byob" }), !0; | ||
} catch { | ||
return !1; | ||
} | ||
}; | ||
if (typeof File > "u") { | ||
class e extends Blob { | ||
constructor(n, i, s) { | ||
super(n); | ||
let r; | ||
s != null && s.lastModified && (r = /* @__PURE__ */ new Date()), (!r || isNaN(r.getFullYear())) && (r = /* @__PURE__ */ new Date()), this.lastModifiedDate = r, this.lastModified = r.getMilliseconds(), this.name = i || ""; | ||
} | ||
} | ||
global.File = e; | ||
} | ||
global.File = e; | ||
} | ||
function f(e) { | ||
return new Promise(function(t, r) { | ||
e.onload = e.onerror = function(n) { | ||
e.onload = e.onerror = null, n.type === "load" ? t(e.result) : r(new Error("Failed to read the blob/file")); | ||
}; | ||
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() { | ||
const t = new FileReader(); | ||
return t.readAsArrayBuffer(this), o(t); | ||
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() { | ||
const t = new FileReader(); | ||
return t.readAsText(this), o(t); | ||
}), (typeof Blob.prototype.stream > "u" || !a()) && (Blob.prototype.stream = function() { | ||
let e = 0; | ||
const t = this; | ||
return new ReadableStream({ | ||
type: "bytes", | ||
// 0.5 MB seems like a reasonable chunk size, let's adjust | ||
// this if needed. | ||
autoAllocateChunkSize: 512 * 1024, | ||
async pull(n) { | ||
const i = n.byobRequest.view, r = await t.slice( | ||
e, | ||
e + i.byteLength | ||
).arrayBuffer(), f = new Uint8Array(r); | ||
new Uint8Array(i.buffer).set(f); | ||
const l = f.byteLength; | ||
n.byobRequest.respond(l), e += l, e >= t.size && n.close(); | ||
} | ||
}); | ||
}); | ||
} | ||
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() { | ||
const t = new FileReader(); | ||
return t.readAsArrayBuffer(this), f(t); | ||
}); | ||
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() { | ||
const t = new FileReader(); | ||
return t.readAsText(this), f(t); | ||
}); | ||
function l() { | ||
const e = new Uint8Array([1, 2, 3, 4]), r = new File([e], "test").stream(); | ||
try { | ||
return r.getReader({ mode: "byob" }), !0; | ||
} catch { | ||
return !1; | ||
} | ||
} | ||
(typeof Blob.prototype.stream > "u" || !l()) && (Blob.prototype.stream = function() { | ||
let e = 0; | ||
const t = this; | ||
return new ReadableStream({ | ||
type: "bytes", | ||
// 0.5 MB seems like a reasonable chunk size, let's adjust | ||
// this if needed. | ||
autoAllocateChunkSize: 512 * 1024, | ||
async pull(r) { | ||
const n = r.byobRequest.view, o = await t.slice(e, e + n.byteLength).arrayBuffer(), s = new Uint8Array(o); | ||
new Uint8Array(n.buffer).set(s); | ||
const a = s.byteLength; | ||
r.byobRequest.respond(a), e += a, e >= t.size && r.close(); | ||
if (u === "NODE" && typeof CustomEvent > "u") { | ||
class o extends Event { | ||
constructor(e, t = {}) { | ||
super(e, t), this.detail = t.detail; | ||
} | ||
}); | ||
}); | ||
if (typeof CustomEvent > "u") { | ||
class e extends Event { | ||
constructor(r, n = {}) { | ||
super(r, n), this.detail = n.detail; | ||
} | ||
initCustomEvent() { | ||
} | ||
} | ||
globalThis.CustomEvent = e; | ||
globalThis.CustomEvent = o; | ||
} |
{ | ||
"name": "@php-wasm/node-polyfills", | ||
"version": "0.6.6", | ||
"version": "0.6.7", | ||
"description": "PHP.wasm – polyfills for Node.js", | ||
@@ -33,3 +33,3 @@ "repository": { | ||
"license": "GPL-2.0-or-later", | ||
"gitHead": "90f82ca946f8573b358c1320be0b6b8674f67cfc" | ||
"gitHead": "c4c52563eee8997b94cd4a0875e10fb5d8ccda42" | ||
} |
Sorry, the diff of this file is not supported yet
4895
7
80