@tybys/wasm-util 0.8.0 → 0.8.1

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.
Files changed (40) hide show
  1. package/README.md +193 -193
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/dist/wasm-util.esm-bundler.js +2645 -2638
  4. package/dist/wasm-util.esm.js +2645 -2638
  5. package/dist/wasm-util.esm.min.js +1 -1
  6. package/dist/wasm-util.js +2645 -2638
  7. package/dist/wasm-util.min.js +1 -1
  8. package/lib/cjs/asyncify.js +157 -157
  9. package/lib/cjs/index.js +12 -12
  10. package/lib/cjs/jspi.js +45 -45
  11. package/lib/cjs/load.js +96 -96
  12. package/lib/cjs/memory.js +34 -34
  13. package/lib/cjs/wasi/error.js +102 -102
  14. package/lib/cjs/wasi/fd.js +267 -267
  15. package/lib/cjs/wasi/fs.js +2 -2
  16. package/lib/cjs/wasi/index.js +193 -193
  17. package/lib/cjs/wasi/path.js +173 -173
  18. package/lib/cjs/wasi/preview1.js +1485 -1478
  19. package/lib/cjs/wasi/rights.js +139 -139
  20. package/lib/cjs/wasi/types.js +219 -219
  21. package/lib/cjs/wasi/util.js +121 -121
  22. package/lib/cjs/webassembly.js +12 -12
  23. package/lib/mjs/asyncify.mjs +153 -153
  24. package/lib/mjs/index.mjs +9 -9
  25. package/lib/mjs/jspi.mjs +39 -39
  26. package/lib/mjs/load.mjs +89 -89
  27. package/lib/mjs/memory.mjs +28 -28
  28. package/lib/mjs/wasi/error.mjs +97 -97
  29. package/lib/mjs/wasi/fd.mjs +256 -256
  30. package/lib/mjs/wasi/fs.mjs +1 -1
  31. package/lib/mjs/wasi/index.mjs +188 -188
  32. package/lib/mjs/wasi/path.mjs +168 -168
  33. package/lib/mjs/wasi/preview1.mjs +1481 -1474
  34. package/lib/mjs/wasi/rights.mjs +134 -134
  35. package/lib/mjs/wasi/types.mjs +216 -216
  36. package/lib/mjs/wasi/util.mjs +108 -108
  37. package/lib/mjs/webassembly.mjs +9 -9
  38. package/package.json +58 -58
  39. package/lib/cjs/memfs.js +0 -2689
  40. package/lib/mjs/memfs.mjs +0 -2688
@@ -1,108 +1,108 @@
1
- /* eslint-disable spaced-comment */
2
- export function validateObject(value, name) {
3
- if (value === null || typeof value !== 'object') {
4
- throw new TypeError(`${name} must be an object. Received ${value === null ? 'null' : typeof value}`);
5
- }
6
- }
7
- export function validateArray(value, name) {
8
- if (!Array.isArray(value)) {
9
- throw new TypeError(`${name} must be an array. Received ${value === null ? 'null' : typeof value}`);
10
- }
11
- }
12
- export function validateBoolean(value, name) {
13
- if (typeof value !== 'boolean') {
14
- throw new TypeError(`${name} must be a boolean. Received ${value === null ? 'null' : typeof value}`);
15
- }
16
- }
17
- export function validateString(value, name) {
18
- if (typeof value !== 'string') {
19
- throw new TypeError(`${name} must be a string. Received ${value === null ? 'null' : typeof value}`);
20
- }
21
- }
22
- export function validateFunction(value, name) {
23
- if (typeof value !== 'function') {
24
- throw new TypeError(`${name} must be a function. Received ${value === null ? 'null' : typeof value}`);
25
- }
26
- }
27
- export function validateUndefined(value, name) {
28
- if (value !== undefined) {
29
- throw new TypeError(`${name} must be undefined. Received ${value === null ? 'null' : typeof value}`);
30
- }
31
- }
32
- export function validateInt32(value, name, min = -2147483648, max = 2147483647) {
33
- if (typeof value !== 'number') {
34
- throw new TypeError(`${name} must be a number. Received ${value === null ? 'null' : typeof value}`);
35
- }
36
- if (!Number.isInteger(value)) {
37
- throw new RangeError(`${name} must be a integer.`);
38
- }
39
- if (value < min || value > max) {
40
- throw new RangeError(`${name} must be >= ${min} && <= ${max}. Received ${value}`);
41
- }
42
- }
43
- export function isPromiseLike(obj) {
44
- return !!(obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function');
45
- }
46
- export function wrapInstanceExports(exports, mapFn) {
47
- const newExports = Object.create(null);
48
- Object.keys(exports).forEach(name => {
49
- const exportValue = exports[name];
50
- Object.defineProperty(newExports, name, {
51
- enumerable: true,
52
- value: mapFn(exportValue, name)
53
- });
54
- });
55
- return newExports;
56
- }
57
- const _require = /*#__PURE__*/ (function () {
58
- let nativeRequire;
59
- if (typeof __webpack_public_path__ !== 'undefined') {
60
- nativeRequire = (function () {
61
- return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined;
62
- })();
63
- }
64
- else {
65
- nativeRequire = (function () {
66
- return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined);
67
- })();
68
- }
69
- return nativeRequire;
70
- })();
71
- export const isMainThread = /*#__PURE__*/ (function () {
72
- let worker_threads;
73
- try {
74
- worker_threads = _require('worker_threads');
75
- }
76
- catch (_) { }
77
- if (!worker_threads) {
78
- return typeof importScripts === 'undefined';
79
- }
80
- return worker_threads.isMainThread;
81
- })();
82
- export const postMsg = isMainThread
83
- ? () => { }
84
- : /*#__PURE__*/ (function () {
85
- let worker_threads;
86
- try {
87
- worker_threads = _require('worker_threads');
88
- }
89
- catch (_) { }
90
- if (!worker_threads) {
91
- return postMessage;
92
- }
93
- return function postMessage(data) {
94
- worker_threads.parentPort.postMessage({ data });
95
- };
96
- })();
97
- export function sleepBreakIf(delay, breakIf) {
98
- const start = Date.now();
99
- const end = start + delay;
100
- let ret = false;
101
- while (Date.now() < end) {
102
- if (breakIf()) {
103
- ret = true;
104
- break;
105
- }
106
- }
107
- return ret;
108
- }
1
+ /* eslint-disable spaced-comment */
2
+ export function validateObject(value, name) {
3
+ if (value === null || typeof value !== 'object') {
4
+ throw new TypeError(`${name} must be an object. Received ${value === null ? 'null' : typeof value}`);
5
+ }
6
+ }
7
+ export function validateArray(value, name) {
8
+ if (!Array.isArray(value)) {
9
+ throw new TypeError(`${name} must be an array. Received ${value === null ? 'null' : typeof value}`);
10
+ }
11
+ }
12
+ export function validateBoolean(value, name) {
13
+ if (typeof value !== 'boolean') {
14
+ throw new TypeError(`${name} must be a boolean. Received ${value === null ? 'null' : typeof value}`);
15
+ }
16
+ }
17
+ export function validateString(value, name) {
18
+ if (typeof value !== 'string') {
19
+ throw new TypeError(`${name} must be a string. Received ${value === null ? 'null' : typeof value}`);
20
+ }
21
+ }
22
+ export function validateFunction(value, name) {
23
+ if (typeof value !== 'function') {
24
+ throw new TypeError(`${name} must be a function. Received ${value === null ? 'null' : typeof value}`);
25
+ }
26
+ }
27
+ export function validateUndefined(value, name) {
28
+ if (value !== undefined) {
29
+ throw new TypeError(`${name} must be undefined. Received ${value === null ? 'null' : typeof value}`);
30
+ }
31
+ }
32
+ export function validateInt32(value, name, min = -2147483648, max = 2147483647) {
33
+ if (typeof value !== 'number') {
34
+ throw new TypeError(`${name} must be a number. Received ${value === null ? 'null' : typeof value}`);
35
+ }
36
+ if (!Number.isInteger(value)) {
37
+ throw new RangeError(`${name} must be a integer.`);
38
+ }
39
+ if (value < min || value > max) {
40
+ throw new RangeError(`${name} must be >= ${min} && <= ${max}. Received ${value}`);
41
+ }
42
+ }
43
+ export function isPromiseLike(obj) {
44
+ return !!(obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function');
45
+ }
46
+ export function wrapInstanceExports(exports, mapFn) {
47
+ const newExports = Object.create(null);
48
+ Object.keys(exports).forEach(name => {
49
+ const exportValue = exports[name];
50
+ Object.defineProperty(newExports, name, {
51
+ enumerable: true,
52
+ value: mapFn(exportValue, name)
53
+ });
54
+ });
55
+ return newExports;
56
+ }
57
+ const _require = /*#__PURE__*/ (function () {
58
+ let nativeRequire;
59
+ if (typeof __webpack_public_path__ !== 'undefined') {
60
+ nativeRequire = (function () {
61
+ return typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined;
62
+ })();
63
+ }
64
+ else {
65
+ nativeRequire = (function () {
66
+ return typeof __webpack_public_path__ !== 'undefined' ? (typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : undefined) : (typeof require !== 'undefined' ? require : undefined);
67
+ })();
68
+ }
69
+ return nativeRequire;
70
+ })();
71
+ export const isMainThread = /*#__PURE__*/ (function () {
72
+ let worker_threads;
73
+ try {
74
+ worker_threads = _require('worker_threads');
75
+ }
76
+ catch (_) { }
77
+ if (!worker_threads) {
78
+ return typeof importScripts === 'undefined';
79
+ }
80
+ return worker_threads.isMainThread;
81
+ })();
82
+ export const postMsg = isMainThread
83
+ ? () => { }
84
+ : /*#__PURE__*/ (function () {
85
+ let worker_threads;
86
+ try {
87
+ worker_threads = _require('worker_threads');
88
+ }
89
+ catch (_) { }
90
+ if (!worker_threads) {
91
+ return postMessage;
92
+ }
93
+ return function postMessage(data) {
94
+ worker_threads.parentPort.postMessage({ data });
95
+ };
96
+ })();
97
+ export function sleepBreakIf(delay, breakIf) {
98
+ const start = Date.now();
99
+ const end = start + delay;
100
+ let ret = false;
101
+ while (Date.now() < end) {
102
+ if (breakIf()) {
103
+ ret = true;
104
+ break;
105
+ }
106
+ }
107
+ return ret;
108
+ }
@@ -1,9 +1,9 @@
1
- const _WebAssembly = typeof WebAssembly !== 'undefined'
2
- ? WebAssembly
3
- : typeof WXWebAssembly !== 'undefined'
4
- ? WXWebAssembly
5
- : undefined;
6
- if (!_WebAssembly) {
7
- throw new Error('WebAssembly is not supported in this environment');
8
- }
9
- export { _WebAssembly };
1
+ const _WebAssembly = typeof WebAssembly !== 'undefined'
2
+ ? WebAssembly
3
+ : typeof WXWebAssembly !== 'undefined'
4
+ ? WXWebAssembly
5
+ : undefined;
6
+ if (!_WebAssembly) {
7
+ throw new Error('WebAssembly is not supported in this environment');
8
+ }
9
+ export { _WebAssembly };
package/package.json CHANGED
@@ -1,58 +1,58 @@
1
- {
2
- "name": "@tybys/wasm-util",
3
- "version": "0.8.0",
4
- "description": "WASI polyfill for browser and some wasm util",
5
- "main": "./lib/cjs/index.js",
6
- "module": "./dist/wasm-util.esm-bundler.js",
7
- "types": "./dist/wasm-util.d.ts",
8
- "exports": {
9
- ".": {
10
- "module": "./dist/wasm-util.esm-bundler.js",
11
- "import": "./lib/mjs/index.mjs",
12
- "require": "./lib/cjs/index.js",
13
- "types": "./dist/wasm-util.d.ts"
14
- }
15
- },
16
- "scripts": {
17
- "build": "tsgo build",
18
- "watch": "tsgo watch",
19
- "test": "jest",
20
- "lint": "eslint ./src/**/*.{ts,js} --fix",
21
- "prepare": "npm run build"
22
- },
23
- "publishConfig": {
24
- "access": "public"
25
- },
26
- "keywords": [
27
- "wasm",
28
- "webassembly",
29
- "wasi",
30
- "polyfill"
31
- ],
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/toyobayashi/wasm-util.git"
35
- },
36
- "author": "toyobayashi",
37
- "license": "MIT",
38
- "dependencies": {
39
- "tslib": "^2.4.0"
40
- },
41
- "devDependencies": {
42
- "@tybys/ts-transform-module-specifier": "^0.0.2",
43
- "@tybys/ts-transform-pure-class": "^0.1.1",
44
- "@tybys/tsgo": "^1.1.0",
45
- "@types/node": "^14.14.31",
46
- "@typescript-eslint/eslint-plugin": "^5.40.1",
47
- "@typescript-eslint/parser": "^5.40.1",
48
- "eslint": "^8.25.0",
49
- "eslint-config-standard-with-typescript": "^23.0.0",
50
- "eslint-plugin-import": "^2.26.0",
51
- "eslint-plugin-n": "^15.3.0",
52
- "eslint-plugin-promise": "^6.1.0",
53
- "memfs-browser": "^3.4.13000",
54
- "mocha": "^10.1.0",
55
- "ts-node": "^10.9.1",
56
- "typescript": "~4.8.3"
57
- }
58
- }
1
+ {
2
+ "name": "@tybys/wasm-util",
3
+ "version": "0.8.1",
4
+ "description": "WASI polyfill for browser and some wasm util",
5
+ "main": "./lib/cjs/index.js",
6
+ "module": "./dist/wasm-util.esm-bundler.js",
7
+ "types": "./dist/wasm-util.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "module": "./dist/wasm-util.esm-bundler.js",
11
+ "import": "./lib/mjs/index.mjs",
12
+ "require": "./lib/cjs/index.js",
13
+ "types": "./dist/wasm-util.d.ts"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "tsgo build",
18
+ "watch": "tsgo watch",
19
+ "test": "jest",
20
+ "lint": "eslint ./src/**/*.{ts,js} --fix",
21
+ "prepare": "npm run build"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "keywords": [
27
+ "wasm",
28
+ "webassembly",
29
+ "wasi",
30
+ "polyfill"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/toyobayashi/wasm-util.git"
35
+ },
36
+ "author": "toyobayashi",
37
+ "license": "MIT",
38
+ "dependencies": {
39
+ "tslib": "^2.4.0"
40
+ },
41
+ "devDependencies": {
42
+ "@tybys/ts-transform-module-specifier": "^0.0.2",
43
+ "@tybys/ts-transform-pure-class": "^0.1.1",
44
+ "@tybys/tsgo": "^1.1.0",
45
+ "@types/node": "^14.14.31",
46
+ "@typescript-eslint/eslint-plugin": "^5.40.1",
47
+ "@typescript-eslint/parser": "^5.40.1",
48
+ "eslint": "^8.25.0",
49
+ "eslint-config-standard-with-typescript": "^23.0.0",
50
+ "eslint-plugin-import": "^2.26.0",
51
+ "eslint-plugin-n": "^15.3.0",
52
+ "eslint-plugin-promise": "^6.1.0",
53
+ "memfs-browser": "^3.4.13000",
54
+ "mocha": "^10.1.0",
55
+ "ts-node": "^10.9.1",
56
+ "typescript": "~4.8.3"
57
+ }
58
+ }