@php-wasm/node-polyfills 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +1 -1
- package/index.js +60 -50
- package/lib/current-js-runtime.d.ts +1 -0
- package/lib/custom-event.d.ts +1 -0
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";const l=function(){var o;return typeof process<"u"&&((o=process.release)==null?void 0:o.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(l==="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=new Date),(!r||isNaN(r.getFullYear()))&&(r=new Date),this.lastModifiedDate=r,this.lastModified=r.getMilliseconds(),this.name=i||""}}global.File=e}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",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 u=f.byteLength;n.byobRequest.respond(u),e+=u,e>=t.size&&n.close()}})})}if(l==="NODE"&&typeof CustomEvent>"u"){class o extends Event{constructor(e,t={}){super(e,t),this.detail=t.detail}initCustomEvent(){}}globalThis.CustomEvent=o}
|
package/index.js
CHANGED
|
@@ -1,59 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const u = function() {
|
|
2
|
+
var o;
|
|
3
|
+
return typeof process < "u" && ((o = process.release) == null ? void 0 : o.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
6
|
+
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
7
|
+
);
|
|
8
|
+
}();
|
|
9
|
+
if (u === "NODE") {
|
|
10
|
+
let o = function(e) {
|
|
11
|
+
return new Promise(function(t, n) {
|
|
12
|
+
e.onload = e.onerror = function(i) {
|
|
13
|
+
e.onload = e.onerror = null, i.type === "load" ? t(e.result) : n(new Error("Failed to read the blob/file"));
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
}, a = function() {
|
|
17
|
+
const e = new Uint8Array([1, 2, 3, 4]), n = new File([e], "test").stream();
|
|
18
|
+
try {
|
|
19
|
+
return n.getReader({ mode: "byob" }), !0;
|
|
20
|
+
} catch {
|
|
21
|
+
return !1;
|
|
7
22
|
}
|
|
23
|
+
};
|
|
24
|
+
if (typeof File > "u") {
|
|
25
|
+
class e extends Blob {
|
|
26
|
+
constructor(n, i, s) {
|
|
27
|
+
super(n);
|
|
28
|
+
let r;
|
|
29
|
+
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 || "";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
global.File = e;
|
|
8
33
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
34
|
+
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
35
|
+
const t = new FileReader();
|
|
36
|
+
return t.readAsArrayBuffer(this), o(t);
|
|
37
|
+
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
38
|
+
const t = new FileReader();
|
|
39
|
+
return t.readAsText(this), o(t);
|
|
40
|
+
}), (typeof Blob.prototype.stream > "u" || !a()) && (Blob.prototype.stream = function() {
|
|
41
|
+
let e = 0;
|
|
42
|
+
const t = this;
|
|
43
|
+
return new ReadableStream({
|
|
44
|
+
type: "bytes",
|
|
45
|
+
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
46
|
+
// this if needed.
|
|
47
|
+
autoAllocateChunkSize: 512 * 1024,
|
|
48
|
+
async pull(n) {
|
|
49
|
+
const i = n.byobRequest.view, r = await t.slice(
|
|
50
|
+
e,
|
|
51
|
+
e + i.byteLength
|
|
52
|
+
).arrayBuffer(), f = new Uint8Array(r);
|
|
53
|
+
new Uint8Array(i.buffer).set(f);
|
|
54
|
+
const l = f.byteLength;
|
|
55
|
+
n.byobRequest.respond(l), e += l, e >= t.size && n.close();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
16
58
|
});
|
|
17
59
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
23
|
-
const t = new FileReader();
|
|
24
|
-
return t.readAsText(this), f(t);
|
|
25
|
-
});
|
|
26
|
-
function l() {
|
|
27
|
-
const e = new Uint8Array([1, 2, 3, 4]), r = new File([e], "test").stream();
|
|
28
|
-
try {
|
|
29
|
-
return r.getReader({ mode: "byob" }), !0;
|
|
30
|
-
} catch {
|
|
31
|
-
return !1;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
(typeof Blob.prototype.stream > "u" || !l()) && (Blob.prototype.stream = function() {
|
|
35
|
-
let e = 0;
|
|
36
|
-
const t = this;
|
|
37
|
-
return new ReadableStream({
|
|
38
|
-
type: "bytes",
|
|
39
|
-
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
40
|
-
// this if needed.
|
|
41
|
-
autoAllocateChunkSize: 512 * 1024,
|
|
42
|
-
async pull(r) {
|
|
43
|
-
const n = r.byobRequest.view, o = await t.slice(e, e + n.byteLength).arrayBuffer(), s = new Uint8Array(o);
|
|
44
|
-
new Uint8Array(n.buffer).set(s);
|
|
45
|
-
const a = s.byteLength;
|
|
46
|
-
r.byobRequest.respond(a), e += a, e >= t.size && r.close();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
if (typeof CustomEvent > "u") {
|
|
51
|
-
class e extends Event {
|
|
52
|
-
constructor(r, n = {}) {
|
|
53
|
-
super(r, n), this.detail = n.detail;
|
|
60
|
+
if (u === "NODE" && typeof CustomEvent > "u") {
|
|
61
|
+
class o extends Event {
|
|
62
|
+
constructor(e, t = {}) {
|
|
63
|
+
super(e, t), this.detail = t.detail;
|
|
54
64
|
}
|
|
55
65
|
initCustomEvent() {
|
|
56
66
|
}
|
|
57
67
|
}
|
|
58
|
-
globalThis.CustomEvent =
|
|
68
|
+
globalThis.CustomEvent = o;
|
|
59
69
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const currentJsRuntime: string;
|
package/lib/custom-event.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node-polyfills",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "PHP.wasm – polyfills for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"directory": "../../../dist/packages/php-wasm/node-polyfills"
|
|
31
31
|
},
|
|
32
32
|
"license": "GPL-2.0-or-later",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "c4c52563eee8997b94cd4a0875e10fb5d8ccda42"
|
|
34
34
|
}
|