@php-wasm/node-polyfills 1.0.11 → 1.0.13
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 +31 -24
- package/lib/url.d.ts +1 -0
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const f=function(){var n;return typeof process<"u"&&((n=process.release)==null?void 0:n.name)==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(f==="NODE"){let n=function(e){return new Promise(function(t,r){e.onload=e.onerror=function(i){e.onload=e.onerror=null,i.type==="load"?t(e.result):r(new Error("Failed to read the blob/file"))}})},a=function(){const e=new Uint8Array([1,2,3,4]),r=new File([e],"test").stream();try{return r.getReader({mode:"byob"}),!0}catch{return!1}};if(typeof File>"u"){class e extends Blob{constructor(r,i,s){super(r);let o;s!=null&&s.lastModified&&(o=new Date),(!o||isNaN(o.getFullYear()))&&(o=new Date),this.lastModifiedDate=o,this.lastModified=o.getMilliseconds(),this.name=i||""}}global.File=e}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const t=new FileReader;return t.readAsArrayBuffer(this),n(t)}),typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const t=new FileReader;return t.readAsText(this),n(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(r){const i=r.byobRequest.view,o=await t.slice(e,e+i.byteLength).arrayBuffer(),u=new Uint8Array(o);new Uint8Array(i.buffer).set(u);const l=u.byteLength;r.byobRequest.respond(l),e+=l,e>=t.size&&r.close()}})})}if(f==="NODE"&&typeof CustomEvent>"u"){class n extends Event{constructor(e,t={}){super(e,t),this.detail=t.detail}initCustomEvent(){}}globalThis.CustomEvent=n}f==="NODE"&&typeof URL.canParse!="function"&&(globalThis.URL.canParse=function(n){try{return!!new URL(n)}catch{return!1}});
|
package/index.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
const
|
|
2
|
-
var
|
|
3
|
-
return typeof process < "u" && ((
|
|
1
|
+
const f = function() {
|
|
2
|
+
var n;
|
|
3
|
+
return typeof process < "u" && ((n = process.release) == null ? void 0 : n.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
6
6
|
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
7
7
|
);
|
|
8
8
|
}();
|
|
9
|
-
if (
|
|
10
|
-
let
|
|
11
|
-
return new Promise(function(t,
|
|
9
|
+
if (f === "NODE") {
|
|
10
|
+
let n = function(e) {
|
|
11
|
+
return new Promise(function(t, r) {
|
|
12
12
|
e.onload = e.onerror = function(i) {
|
|
13
|
-
e.onload = e.onerror = null, i.type === "load" ? t(e.result) :
|
|
13
|
+
e.onload = e.onerror = null, i.type === "load" ? t(e.result) : r(new Error("Failed to read the blob/file"));
|
|
14
14
|
};
|
|
15
15
|
});
|
|
16
16
|
}, a = function() {
|
|
17
|
-
const e = new Uint8Array([1, 2, 3, 4]),
|
|
17
|
+
const e = new Uint8Array([1, 2, 3, 4]), r = new File([e], "test").stream();
|
|
18
18
|
try {
|
|
19
|
-
return
|
|
19
|
+
return r.getReader({ mode: "byob" }), !0;
|
|
20
20
|
} catch {
|
|
21
21
|
return !1;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
if (typeof File > "u") {
|
|
25
25
|
class e extends Blob {
|
|
26
|
-
constructor(
|
|
27
|
-
super(
|
|
28
|
-
let
|
|
29
|
-
s != null && s.lastModified && (
|
|
26
|
+
constructor(r, i, s) {
|
|
27
|
+
super(r);
|
|
28
|
+
let o;
|
|
29
|
+
s != null && s.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = i || "";
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
global.File = e;
|
|
33
33
|
}
|
|
34
34
|
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
35
35
|
const t = new FileReader();
|
|
36
|
-
return t.readAsArrayBuffer(this),
|
|
36
|
+
return t.readAsArrayBuffer(this), n(t);
|
|
37
37
|
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
38
38
|
const t = new FileReader();
|
|
39
|
-
return t.readAsText(this),
|
|
39
|
+
return t.readAsText(this), n(t);
|
|
40
40
|
}), (typeof Blob.prototype.stream > "u" || !a()) && (Blob.prototype.stream = function() {
|
|
41
41
|
let e = 0;
|
|
42
42
|
const t = this;
|
|
@@ -45,25 +45,32 @@ if (u === "NODE") {
|
|
|
45
45
|
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
46
46
|
// this if needed.
|
|
47
47
|
autoAllocateChunkSize: 512 * 1024,
|
|
48
|
-
async pull(
|
|
49
|
-
const i =
|
|
48
|
+
async pull(r) {
|
|
49
|
+
const i = r.byobRequest.view, o = await t.slice(
|
|
50
50
|
e,
|
|
51
51
|
e + i.byteLength
|
|
52
|
-
).arrayBuffer(),
|
|
53
|
-
new Uint8Array(i.buffer).set(
|
|
54
|
-
const l =
|
|
55
|
-
|
|
52
|
+
).arrayBuffer(), u = new Uint8Array(o);
|
|
53
|
+
new Uint8Array(i.buffer).set(u);
|
|
54
|
+
const l = u.byteLength;
|
|
55
|
+
r.byobRequest.respond(l), e += l, e >= t.size && r.close();
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
if (
|
|
61
|
-
class
|
|
60
|
+
if (f === "NODE" && typeof CustomEvent > "u") {
|
|
61
|
+
class n extends Event {
|
|
62
62
|
constructor(e, t = {}) {
|
|
63
63
|
super(e, t), this.detail = t.detail;
|
|
64
64
|
}
|
|
65
65
|
initCustomEvent() {
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
globalThis.CustomEvent =
|
|
68
|
+
globalThis.CustomEvent = n;
|
|
69
69
|
}
|
|
70
|
+
f === "NODE" && typeof URL.canParse != "function" && (globalThis.URL.canParse = function(n) {
|
|
71
|
+
try {
|
|
72
|
+
return !!new URL(n);
|
|
73
|
+
} catch {
|
|
74
|
+
return !1;
|
|
75
|
+
}
|
|
76
|
+
});
|
package/lib/url.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node-polyfills",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "PHP.wasm – polyfills for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"directory": "../../../dist/packages/php-wasm/node-polyfills"
|
|
32
32
|
},
|
|
33
33
|
"license": "GPL-2.0-or-later",
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "22888c009b54e0b1e5a5c9961b9d97c08b39f672",
|
|
35
35
|
"dependencies": {}
|
|
36
36
|
}
|