@php-wasm/node-polyfills 0.4.0

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 ADDED
@@ -0,0 +1 @@
1
+ "use strict";if(typeof File>"u"){class e extends Blob{constructor(r,n,i){super(r);let o;i!=null&&i.lastModified&&(o=new Date),(!o||isNaN(o.getFullYear()))&&(o=new Date),this.lastModifiedDate=o,this.lastModified=o.getMilliseconds(),this.name=n||""}}global.File=e}function u(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),u(t)});typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const t=new FileReader;return t.readAsText(this),u(t)});function f(){const e=new Uint8Array([1,2,3,4]),r=new File([e],"test").stream();try{return r.getReader({mode:"byob"}),r.getReader({mode:"byob"}),!0}catch{return!1}}(typeof Blob.prototype.stream>"u"||!f())&&(Blob.prototype.stream=function(){let e=0;const t=this;return new ReadableStream({type:"bytes",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(typeof CustomEvent>"u"){class e extends Event{constructor(r,n={}){super(r,n),this.detail=n.detail}initCustomEvent(){}}globalThis.CustomEvent=e}
package/index.d.ts ADDED
File without changes
package/index.js ADDED
@@ -0,0 +1,59 @@
1
+ if (typeof File > "u") {
2
+ class e extends Blob {
3
+ constructor(r, n, i) {
4
+ super(r);
5
+ let o;
6
+ 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 || "";
7
+ }
8
+ }
9
+ global.File = e;
10
+ }
11
+ function f(e) {
12
+ return new Promise(function(t, r) {
13
+ e.onload = e.onerror = function(n) {
14
+ e.onload = e.onerror = null, n.type === "load" ? t(e.result) : r(new Error("Failed to read the blob/file"));
15
+ };
16
+ });
17
+ }
18
+ typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
19
+ const t = new FileReader();
20
+ return t.readAsArrayBuffer(this), f(t);
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" }), 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;
54
+ }
55
+ initCustomEvent() {
56
+ }
57
+ }
58
+ globalThis.CustomEvent = e;
59
+ }
package/lib/blob.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
File without changes
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@php-wasm/node-polyfills",
3
+ "version": "0.4.0",
4
+ "description": "PHP.wasm – polyfills for Node.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/WordPress/wordpress-playground"
8
+ },
9
+ "homepage": "https://developer.wordpress.org/playground",
10
+ "author": "The WordPress contributors",
11
+ "contributors": [
12
+ {
13
+ "name": "Adam Zielinski",
14
+ "email": "adam@adamziel.com",
15
+ "url": "https://github.com/adamziel"
16
+ }
17
+ ],
18
+ "type": "module",
19
+ "main": "./index.cjs",
20
+ "module": "./index.js",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./index.js",
24
+ "require": "./index.cjs"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "directory": "../../../dist/packages/php-wasm/node-polyfills"
31
+ },
32
+ "license": "GPL-2.0-or-later",
33
+ "gitHead": "0851e71512709843af0539f747caded8ea904fe6"
34
+ }