@gjsify/util 0.0.4 → 0.1.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.
@@ -1,6 +1,300 @@
1
- export * from "@gjsify/deno_std/node/util/types";
2
- import types from "@gjsify/deno_std/node/util/types";
1
+ const _toString = Object.prototype.toString;
2
+ const _bigIntValueOf = BigInt.prototype.valueOf;
3
+ const _booleanValueOf = Boolean.prototype.valueOf;
4
+ const _dateValueOf = Date.prototype.valueOf;
5
+ const _numberValueOf = Number.prototype.valueOf;
6
+ const _stringValueOf = String.prototype.valueOf;
7
+ const _symbolValueOf = Symbol.prototype.valueOf;
8
+ const _weakMapHas = WeakMap.prototype.has;
9
+ const _weakSetHas = WeakSet.prototype.has;
10
+ const _getArrayBufferByteLength = Object.getOwnPropertyDescriptor(
11
+ ArrayBuffer.prototype,
12
+ "byteLength"
13
+ ).get;
14
+ const _getSharedArrayBufferByteLength = typeof SharedArrayBuffer !== "undefined" ? Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get : void 0;
15
+ const _getTypedArrayToStringTag = Object.getOwnPropertyDescriptor(
16
+ Object.getPrototypeOf(Uint8Array).prototype,
17
+ Symbol.toStringTag
18
+ ).get;
19
+ const _getSetSize = Object.getOwnPropertyDescriptor(Set.prototype, "size").get;
20
+ const _getMapSize = Object.getOwnPropertyDescriptor(Map.prototype, "size").get;
21
+ function isObjectLike(value) {
22
+ return value !== null && typeof value === "object";
23
+ }
24
+ function isAnyArrayBuffer(value) {
25
+ return isArrayBuffer(value) || isSharedArrayBuffer(value);
26
+ }
27
+ function isArrayBuffer(value) {
28
+ try {
29
+ _getArrayBufferByteLength.call(value);
30
+ return true;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+ function isSharedArrayBuffer(value) {
36
+ if (_getSharedArrayBufferByteLength === void 0) return false;
37
+ try {
38
+ _getSharedArrayBufferByteLength.call(value);
39
+ return true;
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+ function isArrayBufferView(value) {
45
+ return ArrayBuffer.isView(value);
46
+ }
47
+ function isTypedArray(value) {
48
+ return _getTypedArrayToStringTag.call(value) !== void 0;
49
+ }
50
+ function isUint8Array(value) {
51
+ return _getTypedArrayToStringTag.call(value) === "Uint8Array";
52
+ }
53
+ function isUint8ClampedArray(value) {
54
+ return _getTypedArrayToStringTag.call(value) === "Uint8ClampedArray";
55
+ }
56
+ function isUint16Array(value) {
57
+ return _getTypedArrayToStringTag.call(value) === "Uint16Array";
58
+ }
59
+ function isUint32Array(value) {
60
+ return _getTypedArrayToStringTag.call(value) === "Uint32Array";
61
+ }
62
+ function isInt8Array(value) {
63
+ return _getTypedArrayToStringTag.call(value) === "Int8Array";
64
+ }
65
+ function isInt16Array(value) {
66
+ return _getTypedArrayToStringTag.call(value) === "Int16Array";
67
+ }
68
+ function isInt32Array(value) {
69
+ return _getTypedArrayToStringTag.call(value) === "Int32Array";
70
+ }
71
+ function isFloat32Array(value) {
72
+ return _getTypedArrayToStringTag.call(value) === "Float32Array";
73
+ }
74
+ function isFloat64Array(value) {
75
+ return _getTypedArrayToStringTag.call(value) === "Float64Array";
76
+ }
77
+ function isBigInt64Array(value) {
78
+ return _getTypedArrayToStringTag.call(value) === "BigInt64Array";
79
+ }
80
+ function isBigUint64Array(value) {
81
+ return _getTypedArrayToStringTag.call(value) === "BigUint64Array";
82
+ }
83
+ function isDataView(value) {
84
+ return ArrayBuffer.isView(value) && _getTypedArrayToStringTag.call(value) === void 0;
85
+ }
86
+ function isMap(value) {
87
+ try {
88
+ _getMapSize.call(value);
89
+ return true;
90
+ } catch {
91
+ return false;
92
+ }
93
+ }
94
+ function isSet(value) {
95
+ try {
96
+ _getSetSize.call(value);
97
+ return true;
98
+ } catch {
99
+ return false;
100
+ }
101
+ }
102
+ function isWeakMap(value) {
103
+ try {
104
+ _weakMapHas.call(value, null);
105
+ return true;
106
+ } catch {
107
+ return false;
108
+ }
109
+ }
110
+ function isWeakSet(value) {
111
+ try {
112
+ _weakSetHas.call(value, null);
113
+ return true;
114
+ } catch {
115
+ return false;
116
+ }
117
+ }
118
+ function isMapIterator(value) {
119
+ return isObjectLike(value) && value[Symbol.toStringTag] === "Map Iterator";
120
+ }
121
+ function isSetIterator(value) {
122
+ return isObjectLike(value) && value[Symbol.toStringTag] === "Set Iterator";
123
+ }
124
+ function isDate(value) {
125
+ try {
126
+ _dateValueOf.call(value);
127
+ return true;
128
+ } catch {
129
+ return false;
130
+ }
131
+ }
132
+ function isRegExp(value) {
133
+ return isObjectLike(value) && value[Symbol.toStringTag] === void 0 && _toString.call(value) === "[object RegExp]";
134
+ }
135
+ function isNativeError(value) {
136
+ return isObjectLike(value) && value[Symbol.toStringTag] === void 0 && _toString.call(value) === "[object Error]";
137
+ }
138
+ function isAsyncFunction(value) {
139
+ return typeof value === "function" && value[Symbol.toStringTag] === "AsyncFunction";
140
+ }
141
+ function isGeneratorFunction(value) {
142
+ return typeof value === "function" && value[Symbol.toStringTag] === "GeneratorFunction";
143
+ }
144
+ function isGeneratorObject(value) {
145
+ return isObjectLike(value) && value[Symbol.toStringTag] === "Generator";
146
+ }
147
+ function isPromise(value) {
148
+ return isObjectLike(value) && value[Symbol.toStringTag] === "Promise";
149
+ }
150
+ function isBooleanObject(value) {
151
+ if (!isObjectLike(value)) return false;
152
+ try {
153
+ _booleanValueOf.call(value);
154
+ return true;
155
+ } catch {
156
+ return false;
157
+ }
158
+ }
159
+ function isNumberObject(value) {
160
+ if (!isObjectLike(value)) return false;
161
+ try {
162
+ _numberValueOf.call(value);
163
+ return true;
164
+ } catch {
165
+ return false;
166
+ }
167
+ }
168
+ function isStringObject(value) {
169
+ if (!isObjectLike(value)) return false;
170
+ try {
171
+ _stringValueOf.call(value);
172
+ return true;
173
+ } catch {
174
+ return false;
175
+ }
176
+ }
177
+ function isSymbolObject(value) {
178
+ if (!isObjectLike(value)) return false;
179
+ try {
180
+ _symbolValueOf.call(value);
181
+ return true;
182
+ } catch {
183
+ return false;
184
+ }
185
+ }
186
+ function isBigIntObject(value) {
187
+ if (!isObjectLike(value)) return false;
188
+ try {
189
+ _bigIntValueOf.call(value);
190
+ return true;
191
+ } catch {
192
+ return false;
193
+ }
194
+ }
195
+ function isBoxedPrimitive(value) {
196
+ return isBooleanObject(value) || isStringObject(value) || isNumberObject(value) || isSymbolObject(value) || isBigIntObject(value);
197
+ }
198
+ function isArgumentsObject(value) {
199
+ return isObjectLike(value) && value[Symbol.toStringTag] === void 0 && _toString.call(value) === "[object Arguments]";
200
+ }
201
+ function isModuleNamespaceObject(value) {
202
+ return isObjectLike(value) && value[Symbol.toStringTag] === "Module";
203
+ }
204
+ function isProxy(value) {
205
+ return false;
206
+ }
207
+ function isCryptoKey(value) {
208
+ return isObjectLike(value) && _toString.call(value) === "[object CryptoKey]";
209
+ }
210
+ function isKeyObject(value) {
211
+ return false;
212
+ }
213
+ const types = {
214
+ isAnyArrayBuffer,
215
+ isArrayBuffer,
216
+ isArrayBufferView,
217
+ isArgumentsObject,
218
+ isAsyncFunction,
219
+ isBigInt64Array,
220
+ isBigUint64Array,
221
+ isBigIntObject,
222
+ isBooleanObject,
223
+ isBoxedPrimitive,
224
+ isCryptoKey,
225
+ isDataView,
226
+ isDate,
227
+ isFloat32Array,
228
+ isFloat64Array,
229
+ isGeneratorFunction,
230
+ isGeneratorObject,
231
+ isInt8Array,
232
+ isInt16Array,
233
+ isInt32Array,
234
+ isKeyObject,
235
+ isMap,
236
+ isMapIterator,
237
+ isModuleNamespaceObject,
238
+ isNativeError,
239
+ isNumberObject,
240
+ isPromise,
241
+ isProxy,
242
+ isRegExp,
243
+ isSet,
244
+ isSetIterator,
245
+ isSharedArrayBuffer,
246
+ isStringObject,
247
+ isSymbolObject,
248
+ isTypedArray,
249
+ isUint8Array,
250
+ isUint8ClampedArray,
251
+ isUint16Array,
252
+ isUint32Array,
253
+ isWeakMap,
254
+ isWeakSet
255
+ };
3
256
  var types_default = types;
4
257
  export {
5
- types_default as default
258
+ types_default as default,
259
+ isAnyArrayBuffer,
260
+ isArgumentsObject,
261
+ isArrayBuffer,
262
+ isArrayBufferView,
263
+ isAsyncFunction,
264
+ isBigInt64Array,
265
+ isBigIntObject,
266
+ isBigUint64Array,
267
+ isBooleanObject,
268
+ isBoxedPrimitive,
269
+ isCryptoKey,
270
+ isDataView,
271
+ isDate,
272
+ isFloat32Array,
273
+ isFloat64Array,
274
+ isGeneratorFunction,
275
+ isGeneratorObject,
276
+ isInt16Array,
277
+ isInt32Array,
278
+ isInt8Array,
279
+ isKeyObject,
280
+ isMap,
281
+ isMapIterator,
282
+ isModuleNamespaceObject,
283
+ isNativeError,
284
+ isNumberObject,
285
+ isPromise,
286
+ isProxy,
287
+ isRegExp,
288
+ isSet,
289
+ isSetIterator,
290
+ isSharedArrayBuffer,
291
+ isStringObject,
292
+ isSymbolObject,
293
+ isTypedArray,
294
+ isUint16Array,
295
+ isUint32Array,
296
+ isUint8Array,
297
+ isUint8ClampedArray,
298
+ isWeakMap,
299
+ isWeakSet
6
300
  };
@@ -0,0 +1,6 @@
1
+ export * from "./types/index.js";
2
+ import types from "./types/index.js";
3
+ var types_default = types;
4
+ export {
5
+ types_default as default
6
+ };
@@ -0,0 +1,2 @@
1
+ export declare function getSystemErrorName(err: number): string;
2
+ export declare function getSystemErrorMap(): Map<number, [string, string]>;
@@ -1,3 +1,98 @@
1
- export * from '@gjsify/deno_std/node/util';
2
- import util from '@gjsify/deno_std/node/util';
3
- export default util;
1
+ import type { InspectOptions } from 'node:util';
2
+ import * as types from './types.js';
3
+ import { getSystemErrorName, getSystemErrorMap } from './errors.js';
4
+ export { types };
5
+ export { getSystemErrorName, getSystemErrorMap };
6
+ declare const kCustomInspect: unique symbol;
7
+ export declare function inspect(value: unknown, opts?: boolean | InspectOptions): string;
8
+ export declare namespace inspect {
9
+ var custom: typeof kCustomInspect;
10
+ var defaultOptions: {
11
+ showHidden: boolean;
12
+ depth: number;
13
+ colors: boolean;
14
+ maxArrayLength: number;
15
+ maxStringLength: number;
16
+ breakLength: number;
17
+ compact: number;
18
+ sorted: boolean;
19
+ };
20
+ var colors: Record<string, [number, number]>;
21
+ var styles: Record<string, string>;
22
+ }
23
+ export declare function format(fmt: string, ...args: unknown[]): string;
24
+ export declare function formatWithOptions(inspectOptions: InspectOptions, fmt: string, ...args: unknown[]): string;
25
+ declare const kCustomPromisify: unique symbol;
26
+ export declare function promisify<T extends (...args: unknown[]) => void>(fn: T): (...args: unknown[]) => Promise<unknown>;
27
+ export declare namespace promisify {
28
+ var custom: typeof kCustomPromisify;
29
+ }
30
+ export declare function callbackify<T>(fn: () => Promise<T>): (callback: (err: Error | null, result?: T) => void) => void;
31
+ export declare function callbackify<T>(fn: (...args: unknown[]) => Promise<T>): (...args: unknown[]) => void;
32
+ export declare function deprecate<T extends (...args: unknown[]) => unknown>(fn: T, msg: string, code?: string): T;
33
+ export declare function debuglog(section: string): (...args: unknown[]) => void;
34
+ export declare function inherits(ctor: Function, superCtor: Function): void;
35
+ export declare function isBoolean(value: unknown): value is boolean;
36
+ export declare function isNull(value: unknown): value is null;
37
+ export declare function isNullOrUndefined(value: unknown): value is null | undefined;
38
+ export declare function isNumber(value: unknown): value is number;
39
+ export declare function isString(value: unknown): value is string;
40
+ export declare function isSymbol(value: unknown): value is symbol;
41
+ export declare function isUndefined(value: unknown): value is undefined;
42
+ export declare function isObject(value: unknown): value is object;
43
+ export declare function isError(value: unknown): value is Error;
44
+ export declare function isFunction(value: unknown): value is Function;
45
+ export declare function isRegExp(value: unknown): value is RegExp;
46
+ export declare function isArray(value: unknown): value is unknown[];
47
+ export declare function isPrimitive(value: unknown): boolean;
48
+ export declare function isDate(value: unknown): value is Date;
49
+ export declare function isBuffer(value: unknown): boolean;
50
+ export declare const TextDecoder: {
51
+ new (label?: string, options?: TextDecoderOptions): TextDecoder;
52
+ prototype: TextDecoder;
53
+ };
54
+ export declare const TextEncoder: {
55
+ new (): TextEncoder;
56
+ prototype: TextEncoder;
57
+ };
58
+ export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
59
+ export declare function toUSVString(string: string): string;
60
+ declare const _default: {
61
+ format: typeof format;
62
+ formatWithOptions: typeof formatWithOptions;
63
+ inspect: typeof inspect;
64
+ promisify: typeof promisify;
65
+ callbackify: typeof callbackify;
66
+ deprecate: typeof deprecate;
67
+ debuglog: typeof debuglog;
68
+ inherits: typeof inherits;
69
+ types: typeof types;
70
+ isBoolean: typeof isBoolean;
71
+ isNull: typeof isNull;
72
+ isNullOrUndefined: typeof isNullOrUndefined;
73
+ isNumber: typeof isNumber;
74
+ isString: typeof isString;
75
+ isSymbol: typeof isSymbol;
76
+ isUndefined: typeof isUndefined;
77
+ isObject: typeof isObject;
78
+ isError: typeof isError;
79
+ isFunction: typeof isFunction;
80
+ isRegExp: typeof isRegExp;
81
+ isArray: typeof isArray;
82
+ isPrimitive: typeof isPrimitive;
83
+ isDate: typeof isDate;
84
+ isBuffer: typeof isBuffer;
85
+ isDeepStrictEqual: typeof isDeepStrictEqual;
86
+ toUSVString: typeof toUSVString;
87
+ TextDecoder: {
88
+ new (label?: string, options?: TextDecoderOptions): TextDecoder;
89
+ prototype: TextDecoder;
90
+ };
91
+ TextEncoder: {
92
+ new (): TextEncoder;
93
+ prototype: TextEncoder;
94
+ };
95
+ getSystemErrorName: typeof getSystemErrorName;
96
+ getSystemErrorMap: typeof getSystemErrorMap;
97
+ };
98
+ export default _default;
@@ -1,3 +1,85 @@
1
- export * from '@gjsify/deno_std/node/util/types';
2
- import types from '@gjsify/deno_std/node/util/types';
1
+ export declare function isAnyArrayBuffer(value: unknown): value is ArrayBuffer | SharedArrayBuffer;
2
+ export declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
3
+ export declare function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer;
4
+ export declare function isArrayBufferView(value: unknown): value is ArrayBufferView;
5
+ export declare function isTypedArray(value: unknown): boolean;
6
+ export declare function isUint8Array(value: unknown): value is Uint8Array;
7
+ export declare function isUint8ClampedArray(value: unknown): value is Uint8ClampedArray;
8
+ export declare function isUint16Array(value: unknown): value is Uint16Array;
9
+ export declare function isUint32Array(value: unknown): value is Uint32Array;
10
+ export declare function isInt8Array(value: unknown): value is Int8Array;
11
+ export declare function isInt16Array(value: unknown): value is Int16Array;
12
+ export declare function isInt32Array(value: unknown): value is Int32Array;
13
+ export declare function isFloat32Array(value: unknown): value is Float32Array;
14
+ export declare function isFloat64Array(value: unknown): value is Float64Array;
15
+ export declare function isBigInt64Array(value: unknown): value is BigInt64Array;
16
+ export declare function isBigUint64Array(value: unknown): value is BigUint64Array;
17
+ export declare function isDataView(value: unknown): value is DataView;
18
+ export declare function isMap(value: unknown): value is Map<unknown, unknown>;
19
+ export declare function isSet(value: unknown): value is Set<unknown>;
20
+ export declare function isWeakMap(value: unknown): value is WeakMap<WeakKey, unknown>;
21
+ export declare function isWeakSet(value: unknown): value is WeakSet<WeakKey>;
22
+ export declare function isMapIterator(value: unknown): boolean;
23
+ export declare function isSetIterator(value: unknown): boolean;
24
+ export declare function isDate(value: unknown): value is Date;
25
+ export declare function isRegExp(value: unknown): value is RegExp;
26
+ export declare function isNativeError(value: unknown): value is Error;
27
+ export declare function isAsyncFunction(value: unknown): boolean;
28
+ export declare function isGeneratorFunction(value: unknown): value is GeneratorFunction;
29
+ export declare function isGeneratorObject(value: unknown): value is Generator;
30
+ export declare function isPromise(value: unknown): value is Promise<unknown>;
31
+ export declare function isBooleanObject(value: unknown): boolean;
32
+ export declare function isNumberObject(value: unknown): boolean;
33
+ export declare function isStringObject(value: unknown): boolean;
34
+ export declare function isSymbolObject(value: unknown): boolean;
35
+ export declare function isBigIntObject(value: unknown): boolean;
36
+ export declare function isBoxedPrimitive(value: unknown): boolean;
37
+ export declare function isArgumentsObject(value: unknown): value is IArguments;
38
+ export declare function isModuleNamespaceObject(value: unknown): boolean;
39
+ export declare function isProxy(value: unknown): boolean;
40
+ export declare function isCryptoKey(value: unknown): boolean;
41
+ export declare function isKeyObject(value: unknown): boolean;
42
+ declare const types: {
43
+ isAnyArrayBuffer: typeof isAnyArrayBuffer;
44
+ isArrayBuffer: typeof isArrayBuffer;
45
+ isArrayBufferView: typeof isArrayBufferView;
46
+ isArgumentsObject: typeof isArgumentsObject;
47
+ isAsyncFunction: typeof isAsyncFunction;
48
+ isBigInt64Array: typeof isBigInt64Array;
49
+ isBigUint64Array: typeof isBigUint64Array;
50
+ isBigIntObject: typeof isBigIntObject;
51
+ isBooleanObject: typeof isBooleanObject;
52
+ isBoxedPrimitive: typeof isBoxedPrimitive;
53
+ isCryptoKey: typeof isCryptoKey;
54
+ isDataView: typeof isDataView;
55
+ isDate: typeof isDate;
56
+ isFloat32Array: typeof isFloat32Array;
57
+ isFloat64Array: typeof isFloat64Array;
58
+ isGeneratorFunction: typeof isGeneratorFunction;
59
+ isGeneratorObject: typeof isGeneratorObject;
60
+ isInt8Array: typeof isInt8Array;
61
+ isInt16Array: typeof isInt16Array;
62
+ isInt32Array: typeof isInt32Array;
63
+ isKeyObject: typeof isKeyObject;
64
+ isMap: typeof isMap;
65
+ isMapIterator: typeof isMapIterator;
66
+ isModuleNamespaceObject: typeof isModuleNamespaceObject;
67
+ isNativeError: typeof isNativeError;
68
+ isNumberObject: typeof isNumberObject;
69
+ isPromise: typeof isPromise;
70
+ isProxy: typeof isProxy;
71
+ isRegExp: typeof isRegExp;
72
+ isSet: typeof isSet;
73
+ isSetIterator: typeof isSetIterator;
74
+ isSharedArrayBuffer: typeof isSharedArrayBuffer;
75
+ isStringObject: typeof isStringObject;
76
+ isSymbolObject: typeof isSymbolObject;
77
+ isTypedArray: typeof isTypedArray;
78
+ isUint8Array: typeof isUint8Array;
79
+ isUint8ClampedArray: typeof isUint8ClampedArray;
80
+ isUint16Array: typeof isUint16Array;
81
+ isUint32Array: typeof isUint32Array;
82
+ isWeakMap: typeof isWeakMap;
83
+ isWeakSet: typeof isWeakSet;
84
+ };
3
85
  export default types;
@@ -0,0 +1,3 @@
1
+ export * from './types/index.js';
2
+ import types from './types/index.js';
3
+ export default types;
package/package.json CHANGED
@@ -1,33 +1,30 @@
1
1
  {
2
2
  "name": "@gjsify/util",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Node.js util module for Gjs",
5
5
  "type": "module",
6
- "main": "lib/cjs/index.js",
7
6
  "module": "lib/esm/index.js",
8
7
  "types": "lib/types/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
- "import": {
12
- "types": "./lib/types/index.d.ts",
13
- "default": "./lib/esm/index.js"
14
- },
15
- "require": {
16
- "types": "./lib/types/index.d.ts",
17
- "default": "./lib/cjs/index.js"
18
- }
10
+ "types": "./lib/types/index.d.ts",
11
+ "default": "./lib/esm/index.js"
12
+ },
13
+ "./types": {
14
+ "types": "./lib/types/types.d.ts",
15
+ "default": "./lib/esm/types.js"
19
16
  }
20
17
  },
21
18
  "scripts": {
22
- "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
23
- "print:name": "echo '@gjsify/util'",
24
- "build": "yarn print:name && yarn build:gjsify && yarn build:types",
19
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
20
+ "check": "tsc --noEmit",
21
+ "build": "yarn build:gjsify && yarn build:types",
25
22
  "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
26
- "build:types": "tsc --project tsconfig.types.json || exit 0",
23
+ "build:types": "tsc",
27
24
  "build:test": "yarn build:test:gjs && yarn build:test:node",
28
25
  "build:test:gjs": "gjsify build src/test.ts --app gjs --outfile test.gjs.mjs",
29
26
  "build:test:node": "gjsify build src/test.ts --app node --outfile test.node.mjs",
30
- "test": "yarn print:name && yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
27
+ "test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
31
28
  "test:gjs": "gjs -m test.gjs.mjs",
32
29
  "test:node": "node test.node.mjs"
33
30
  },
@@ -37,18 +34,10 @@
37
34
  "util"
38
35
  ],
39
36
  "devDependencies": {
40
- "@gjsify/cli": "^0.0.4",
41
- "@gjsify/unit": "^0.0.4",
42
- "@types/inherits": "^0.0.33",
43
- "@types/node": "^20.10.5",
44
- "typescript": "^5.3.3"
45
- },
46
- "dependencies": {
47
- "@gjsify/deno_std": "^0.0.4",
48
- "is-arguments": "^1.1.1",
49
- "is-generator-function": "^1.0.10",
50
- "is-typed-array": "^1.1.12",
51
- "util": "^0.12.5",
52
- "which-typed-array": "^1.1.13"
37
+ "@gjsify/cli": "^0.1.0",
38
+ "@gjsify/unit": "^0.1.0",
39
+ "@types/inherits": "^2.0.0",
40
+ "@types/node": "^25.5.0",
41
+ "typescript": "^6.0.2"
53
42
  }
54
43
  }
package/src/errors.ts ADDED
@@ -0,0 +1,101 @@
1
+ // Reference: Node.js lib/internal/errors.js — system error name mapping (Linux errno codes)
2
+ // Reimplemented for GJS
3
+
4
+ const linuxErrors: Record<number, string> = {
5
+ [-1]: 'EPERM', [-2]: 'ENOENT', [-3]: 'ESRCH', [-4]: 'EINTR',
6
+ [-5]: 'EIO', [-6]: 'ENXIO', [-7]: 'E2BIG', [-8]: 'ENOEXEC',
7
+ [-9]: 'EBADF', [-10]: 'ECHILD', [-11]: 'EAGAIN', [-12]: 'ENOMEM',
8
+ [-13]: 'EACCES', [-14]: 'EFAULT', [-15]: 'ENOTBLK', [-16]: 'EBUSY',
9
+ [-17]: 'EEXIST', [-18]: 'EXDEV', [-19]: 'ENODEV', [-20]: 'ENOTDIR',
10
+ [-21]: 'EISDIR', [-22]: 'EINVAL', [-23]: 'ENFILE', [-24]: 'EMFILE',
11
+ [-25]: 'ENOTTY', [-26]: 'ETXTBSY', [-27]: 'EFBIG', [-28]: 'ENOSPC',
12
+ [-29]: 'ESPIPE', [-30]: 'EROFS', [-31]: 'EMLINK', [-32]: 'EPIPE',
13
+ [-33]: 'EDOM', [-34]: 'ERANGE', [-35]: 'EDEADLK', [-36]: 'ENAMETOOLONG',
14
+ [-37]: 'ENOLCK', [-38]: 'ENOSYS', [-39]: 'ENOTEMPTY', [-40]: 'ELOOP',
15
+ [-42]: 'ENOMSG', [-43]: 'EIDRM', [-44]: 'ECHRNG', [-45]: 'EL2NSYNC',
16
+ [-46]: 'EL3HLT', [-47]: 'EL3RST', [-48]: 'ELNRNG', [-49]: 'EUNATCH',
17
+ [-50]: 'ENOCSI', [-51]: 'EL2HLT', [-52]: 'EBADE', [-53]: 'EBADR',
18
+ [-54]: 'EXFULL', [-55]: 'ENOANO', [-56]: 'EBADRQC', [-57]: 'EBADSLT',
19
+ [-59]: 'EBFONT', [-60]: 'ENOSTR', [-61]: 'ENODATA', [-62]: 'ETIME',
20
+ [-63]: 'ENOSR', [-64]: 'ENONET', [-65]: 'ENOPKG', [-66]: 'EREMOTE',
21
+ [-67]: 'ENOLINK', [-68]: 'EADV', [-69]: 'ESRMNT', [-70]: 'ECOMM',
22
+ [-71]: 'EPROTO', [-72]: 'EMULTIHOP', [-73]: 'EDOTDOT', [-74]: 'EBADMSG',
23
+ [-75]: 'EOVERFLOW', [-76]: 'ENOTUNIQ', [-77]: 'EBADFD', [-78]: 'EREMCHG',
24
+ [-79]: 'ELIBACC', [-80]: 'ELIBBAD', [-81]: 'ELIBSCN', [-82]: 'ELIBMAX',
25
+ [-83]: 'ELIBEXEC', [-84]: 'EILSEQ', [-85]: 'ERESTART', [-86]: 'ESTRPIPE',
26
+ [-87]: 'EUSERS', [-88]: 'ENOTSOCK', [-89]: 'EDESTADDRREQ', [-90]: 'EMSGSIZE',
27
+ [-91]: 'EPROTOTYPE', [-92]: 'ENOPROTOOPT', [-93]: 'EPROTONOSUPPORT',
28
+ [-94]: 'ESOCKTNOSUPPORT', [-95]: 'ENOTSUP', [-96]: 'EPFNOSUPPORT',
29
+ [-97]: 'EAFNOSUPPORT', [-98]: 'EADDRINUSE', [-99]: 'EADDRNOTAVAIL',
30
+ [-100]: 'ENETDOWN', [-101]: 'ENETUNREACH', [-102]: 'ENETRESET',
31
+ [-103]: 'ECONNABORTED', [-104]: 'ECONNRESET', [-105]: 'ENOBUFS',
32
+ [-106]: 'EISCONN', [-107]: 'ENOTCONN', [-108]: 'ESHUTDOWN',
33
+ [-109]: 'ETOOMANYREFS', [-110]: 'ETIMEDOUT', [-111]: 'ECONNREFUSED',
34
+ [-112]: 'EHOSTDOWN', [-113]: 'EHOSTUNREACH', [-114]: 'EALREADY',
35
+ [-115]: 'EINPROGRESS', [-116]: 'ESTALE', [-117]: 'EUCLEAN',
36
+ [-118]: 'ENOTNAM', [-119]: 'ENAVAIL', [-120]: 'EISNAM',
37
+ [-121]: 'EREMOTEIO', [-122]: 'EDQUOT', [-123]: 'ENOMEDIUM',
38
+ [-124]: 'EMEDIUMTYPE', [-125]: 'ECANCELED', [-126]: 'ENOKEY',
39
+ [-127]: 'EKEYEXPIRED', [-128]: 'EKEYREVOKED', [-129]: 'EKEYREJECTED',
40
+ };
41
+
42
+ const darwinErrors: Record<number, string> = {
43
+ [-1]: 'EPERM', [-2]: 'ENOENT', [-3]: 'ESRCH', [-4]: 'EINTR',
44
+ [-5]: 'EIO', [-6]: 'ENXIO', [-7]: 'E2BIG', [-8]: 'ENOEXEC',
45
+ [-9]: 'EBADF', [-10]: 'ECHILD', [-11]: 'EDEADLK', [-12]: 'ENOMEM',
46
+ [-13]: 'EACCES', [-14]: 'EFAULT', [-15]: 'ENOTBLK', [-16]: 'EBUSY',
47
+ [-17]: 'EEXIST', [-18]: 'EXDEV', [-19]: 'ENODEV', [-20]: 'ENOTDIR',
48
+ [-21]: 'EISDIR', [-22]: 'EINVAL', [-23]: 'ENFILE', [-24]: 'EMFILE',
49
+ [-25]: 'ENOTTY', [-26]: 'ETXTBSY', [-27]: 'EFBIG', [-28]: 'ENOSPC',
50
+ [-29]: 'ESPIPE', [-30]: 'EROFS', [-31]: 'EMLINK', [-32]: 'EPIPE',
51
+ [-33]: 'EDOM', [-34]: 'ERANGE', [-35]: 'EAGAIN', [-36]: 'EINPROGRESS',
52
+ [-37]: 'EALREADY', [-38]: 'ENOTSOCK', [-39]: 'EDESTADDRREQ',
53
+ [-40]: 'EMSGSIZE', [-41]: 'EPROTOTYPE', [-42]: 'ENOPROTOOPT',
54
+ [-43]: 'EPROTONOSUPPORT', [-44]: 'ESOCKTNOSUPPORT', [-45]: 'ENOTSUP',
55
+ [-46]: 'EPFNOSUPPORT', [-47]: 'EAFNOSUPPORT', [-48]: 'EADDRINUSE',
56
+ [-49]: 'EADDRNOTAVAIL', [-50]: 'ENETDOWN', [-51]: 'ENETUNREACH',
57
+ [-52]: 'ENETRESET', [-53]: 'ECONNABORTED', [-54]: 'ECONNRESET',
58
+ [-55]: 'ENOBUFS', [-56]: 'EISCONN', [-57]: 'ENOTCONN',
59
+ [-58]: 'ESHUTDOWN', [-59]: 'ETOOMANYREFS', [-60]: 'ETIMEDOUT',
60
+ [-61]: 'ECONNREFUSED', [-62]: 'ELOOP', [-63]: 'ENAMETOOLONG',
61
+ [-64]: 'EHOSTDOWN', [-65]: 'EHOSTUNREACH', [-66]: 'ENOTEMPTY',
62
+ [-67]: 'EPROCLIM', [-68]: 'EUSERS', [-69]: 'EDQUOT', [-70]: 'ESTALE',
63
+ [-71]: 'EREMOTE', [-72]: 'EBADRPC', [-73]: 'ERPCMISMATCH',
64
+ [-74]: 'EPROGUNAVAIL', [-75]: 'EPROGMISMATCH', [-76]: 'EPROCUNAVAIL',
65
+ [-77]: 'ENOLCK', [-78]: 'ENOSYS', [-79]: 'EFTYPE', [-80]: 'EAUTH',
66
+ [-81]: 'ENEEDAUTH', [-82]: 'EPWROFF', [-83]: 'EDEVERR',
67
+ [-84]: 'EOVERFLOW', [-85]: 'EBADEXEC', [-86]: 'EBADARCH',
68
+ [-87]: 'ESHLIBVERS', [-88]: 'EBADMACHO', [-89]: 'ECANCELED',
69
+ [-90]: 'EIDRM', [-91]: 'ENOMSG', [-92]: 'EILSEQ', [-93]: 'ENOATTR',
70
+ [-94]: 'EBADMSG', [-95]: 'EMULTIHOP', [-96]: 'ENODATA',
71
+ [-97]: 'ENOLINK', [-98]: 'ENOSR', [-99]: 'ENOSTR', [-100]: 'EPROTO',
72
+ [-101]: 'ETIME', [-102]: 'EOPNOTSUPP',
73
+ };
74
+
75
+ function getPlatform(): string {
76
+ if (typeof globalThis.process?.platform === 'string') return globalThis.process.platform;
77
+ return 'linux';
78
+ }
79
+
80
+ export function getSystemErrorName(err: number): string {
81
+ if (typeof err !== 'number') {
82
+ throw new TypeError('The "err" argument must be of type number. Received type ' + typeof err);
83
+ }
84
+ if (err >= 0) {
85
+ throw new RangeError(`The value of "err" is out of range. It must be a negative integer. Received ${err}`);
86
+ }
87
+
88
+ const platform = getPlatform();
89
+ const map = platform === 'darwin' ? darwinErrors : linuxErrors;
90
+ return map[err] || `Unknown system error ${err}`;
91
+ }
92
+
93
+ export function getSystemErrorMap(): Map<number, [string, string]> {
94
+ const platform = getPlatform();
95
+ const map = platform === 'darwin' ? darwinErrors : linuxErrors;
96
+ const result = new Map<number, [string, string]>();
97
+ for (const [key, name] of Object.entries(map)) {
98
+ result.set(Number(key), [name, '']);
99
+ }
100
+ return result;
101
+ }