@gjsify/util 0.0.3 → 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.
package/README.md CHANGED
@@ -1,6 +1,32 @@
1
1
  # @gjsify/util
2
2
 
3
- Node.js util module for Gjs
3
+ GJS implementation of the Node.js `util` module. Provides inspect, format, promisify, types, and more.
4
+
5
+ Part of the [gjsify](https://github.com/gjsify/gjsify) project — Node.js and Web APIs for GJS (GNOME JavaScript).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @gjsify/util
11
+ # or
12
+ yarn add @gjsify/util
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { inspect, format, promisify, types } from '@gjsify/util';
19
+
20
+ console.log(inspect({ key: 'value' }));
21
+ console.log(format('Hello %s', 'world'));
22
+ console.log(types.isPromise(Promise.resolve()));
23
+ ```
24
+
4
25
  ## Inspirations and credits
5
- * https://github.com/browserify/node-util
6
- * https://github.com/denoland/deno_std/blob/main/node/util.ts
26
+
27
+ - https://github.com/browserify/node-util
28
+ - https://github.com/denoland/deno_std/blob/main/node/util.ts
29
+
30
+ ## License
31
+
32
+ MIT
@@ -0,0 +1,261 @@
1
+ const linuxErrors = {
2
+ [-1]: "EPERM",
3
+ [-2]: "ENOENT",
4
+ [-3]: "ESRCH",
5
+ [-4]: "EINTR",
6
+ [-5]: "EIO",
7
+ [-6]: "ENXIO",
8
+ [-7]: "E2BIG",
9
+ [-8]: "ENOEXEC",
10
+ [-9]: "EBADF",
11
+ [-10]: "ECHILD",
12
+ [-11]: "EAGAIN",
13
+ [-12]: "ENOMEM",
14
+ [-13]: "EACCES",
15
+ [-14]: "EFAULT",
16
+ [-15]: "ENOTBLK",
17
+ [-16]: "EBUSY",
18
+ [-17]: "EEXIST",
19
+ [-18]: "EXDEV",
20
+ [-19]: "ENODEV",
21
+ [-20]: "ENOTDIR",
22
+ [-21]: "EISDIR",
23
+ [-22]: "EINVAL",
24
+ [-23]: "ENFILE",
25
+ [-24]: "EMFILE",
26
+ [-25]: "ENOTTY",
27
+ [-26]: "ETXTBSY",
28
+ [-27]: "EFBIG",
29
+ [-28]: "ENOSPC",
30
+ [-29]: "ESPIPE",
31
+ [-30]: "EROFS",
32
+ [-31]: "EMLINK",
33
+ [-32]: "EPIPE",
34
+ [-33]: "EDOM",
35
+ [-34]: "ERANGE",
36
+ [-35]: "EDEADLK",
37
+ [-36]: "ENAMETOOLONG",
38
+ [-37]: "ENOLCK",
39
+ [-38]: "ENOSYS",
40
+ [-39]: "ENOTEMPTY",
41
+ [-40]: "ELOOP",
42
+ [-42]: "ENOMSG",
43
+ [-43]: "EIDRM",
44
+ [-44]: "ECHRNG",
45
+ [-45]: "EL2NSYNC",
46
+ [-46]: "EL3HLT",
47
+ [-47]: "EL3RST",
48
+ [-48]: "ELNRNG",
49
+ [-49]: "EUNATCH",
50
+ [-50]: "ENOCSI",
51
+ [-51]: "EL2HLT",
52
+ [-52]: "EBADE",
53
+ [-53]: "EBADR",
54
+ [-54]: "EXFULL",
55
+ [-55]: "ENOANO",
56
+ [-56]: "EBADRQC",
57
+ [-57]: "EBADSLT",
58
+ [-59]: "EBFONT",
59
+ [-60]: "ENOSTR",
60
+ [-61]: "ENODATA",
61
+ [-62]: "ETIME",
62
+ [-63]: "ENOSR",
63
+ [-64]: "ENONET",
64
+ [-65]: "ENOPKG",
65
+ [-66]: "EREMOTE",
66
+ [-67]: "ENOLINK",
67
+ [-68]: "EADV",
68
+ [-69]: "ESRMNT",
69
+ [-70]: "ECOMM",
70
+ [-71]: "EPROTO",
71
+ [-72]: "EMULTIHOP",
72
+ [-73]: "EDOTDOT",
73
+ [-74]: "EBADMSG",
74
+ [-75]: "EOVERFLOW",
75
+ [-76]: "ENOTUNIQ",
76
+ [-77]: "EBADFD",
77
+ [-78]: "EREMCHG",
78
+ [-79]: "ELIBACC",
79
+ [-80]: "ELIBBAD",
80
+ [-81]: "ELIBSCN",
81
+ [-82]: "ELIBMAX",
82
+ [-83]: "ELIBEXEC",
83
+ [-84]: "EILSEQ",
84
+ [-85]: "ERESTART",
85
+ [-86]: "ESTRPIPE",
86
+ [-87]: "EUSERS",
87
+ [-88]: "ENOTSOCK",
88
+ [-89]: "EDESTADDRREQ",
89
+ [-90]: "EMSGSIZE",
90
+ [-91]: "EPROTOTYPE",
91
+ [-92]: "ENOPROTOOPT",
92
+ [-93]: "EPROTONOSUPPORT",
93
+ [-94]: "ESOCKTNOSUPPORT",
94
+ [-95]: "ENOTSUP",
95
+ [-96]: "EPFNOSUPPORT",
96
+ [-97]: "EAFNOSUPPORT",
97
+ [-98]: "EADDRINUSE",
98
+ [-99]: "EADDRNOTAVAIL",
99
+ [-100]: "ENETDOWN",
100
+ [-101]: "ENETUNREACH",
101
+ [-102]: "ENETRESET",
102
+ [-103]: "ECONNABORTED",
103
+ [-104]: "ECONNRESET",
104
+ [-105]: "ENOBUFS",
105
+ [-106]: "EISCONN",
106
+ [-107]: "ENOTCONN",
107
+ [-108]: "ESHUTDOWN",
108
+ [-109]: "ETOOMANYREFS",
109
+ [-110]: "ETIMEDOUT",
110
+ [-111]: "ECONNREFUSED",
111
+ [-112]: "EHOSTDOWN",
112
+ [-113]: "EHOSTUNREACH",
113
+ [-114]: "EALREADY",
114
+ [-115]: "EINPROGRESS",
115
+ [-116]: "ESTALE",
116
+ [-117]: "EUCLEAN",
117
+ [-118]: "ENOTNAM",
118
+ [-119]: "ENAVAIL",
119
+ [-120]: "EISNAM",
120
+ [-121]: "EREMOTEIO",
121
+ [-122]: "EDQUOT",
122
+ [-123]: "ENOMEDIUM",
123
+ [-124]: "EMEDIUMTYPE",
124
+ [-125]: "ECANCELED",
125
+ [-126]: "ENOKEY",
126
+ [-127]: "EKEYEXPIRED",
127
+ [-128]: "EKEYREVOKED",
128
+ [-129]: "EKEYREJECTED"
129
+ };
130
+ const darwinErrors = {
131
+ [-1]: "EPERM",
132
+ [-2]: "ENOENT",
133
+ [-3]: "ESRCH",
134
+ [-4]: "EINTR",
135
+ [-5]: "EIO",
136
+ [-6]: "ENXIO",
137
+ [-7]: "E2BIG",
138
+ [-8]: "ENOEXEC",
139
+ [-9]: "EBADF",
140
+ [-10]: "ECHILD",
141
+ [-11]: "EDEADLK",
142
+ [-12]: "ENOMEM",
143
+ [-13]: "EACCES",
144
+ [-14]: "EFAULT",
145
+ [-15]: "ENOTBLK",
146
+ [-16]: "EBUSY",
147
+ [-17]: "EEXIST",
148
+ [-18]: "EXDEV",
149
+ [-19]: "ENODEV",
150
+ [-20]: "ENOTDIR",
151
+ [-21]: "EISDIR",
152
+ [-22]: "EINVAL",
153
+ [-23]: "ENFILE",
154
+ [-24]: "EMFILE",
155
+ [-25]: "ENOTTY",
156
+ [-26]: "ETXTBSY",
157
+ [-27]: "EFBIG",
158
+ [-28]: "ENOSPC",
159
+ [-29]: "ESPIPE",
160
+ [-30]: "EROFS",
161
+ [-31]: "EMLINK",
162
+ [-32]: "EPIPE",
163
+ [-33]: "EDOM",
164
+ [-34]: "ERANGE",
165
+ [-35]: "EAGAIN",
166
+ [-36]: "EINPROGRESS",
167
+ [-37]: "EALREADY",
168
+ [-38]: "ENOTSOCK",
169
+ [-39]: "EDESTADDRREQ",
170
+ [-40]: "EMSGSIZE",
171
+ [-41]: "EPROTOTYPE",
172
+ [-42]: "ENOPROTOOPT",
173
+ [-43]: "EPROTONOSUPPORT",
174
+ [-44]: "ESOCKTNOSUPPORT",
175
+ [-45]: "ENOTSUP",
176
+ [-46]: "EPFNOSUPPORT",
177
+ [-47]: "EAFNOSUPPORT",
178
+ [-48]: "EADDRINUSE",
179
+ [-49]: "EADDRNOTAVAIL",
180
+ [-50]: "ENETDOWN",
181
+ [-51]: "ENETUNREACH",
182
+ [-52]: "ENETRESET",
183
+ [-53]: "ECONNABORTED",
184
+ [-54]: "ECONNRESET",
185
+ [-55]: "ENOBUFS",
186
+ [-56]: "EISCONN",
187
+ [-57]: "ENOTCONN",
188
+ [-58]: "ESHUTDOWN",
189
+ [-59]: "ETOOMANYREFS",
190
+ [-60]: "ETIMEDOUT",
191
+ [-61]: "ECONNREFUSED",
192
+ [-62]: "ELOOP",
193
+ [-63]: "ENAMETOOLONG",
194
+ [-64]: "EHOSTDOWN",
195
+ [-65]: "EHOSTUNREACH",
196
+ [-66]: "ENOTEMPTY",
197
+ [-67]: "EPROCLIM",
198
+ [-68]: "EUSERS",
199
+ [-69]: "EDQUOT",
200
+ [-70]: "ESTALE",
201
+ [-71]: "EREMOTE",
202
+ [-72]: "EBADRPC",
203
+ [-73]: "ERPCMISMATCH",
204
+ [-74]: "EPROGUNAVAIL",
205
+ [-75]: "EPROGMISMATCH",
206
+ [-76]: "EPROCUNAVAIL",
207
+ [-77]: "ENOLCK",
208
+ [-78]: "ENOSYS",
209
+ [-79]: "EFTYPE",
210
+ [-80]: "EAUTH",
211
+ [-81]: "ENEEDAUTH",
212
+ [-82]: "EPWROFF",
213
+ [-83]: "EDEVERR",
214
+ [-84]: "EOVERFLOW",
215
+ [-85]: "EBADEXEC",
216
+ [-86]: "EBADARCH",
217
+ [-87]: "ESHLIBVERS",
218
+ [-88]: "EBADMACHO",
219
+ [-89]: "ECANCELED",
220
+ [-90]: "EIDRM",
221
+ [-91]: "ENOMSG",
222
+ [-92]: "EILSEQ",
223
+ [-93]: "ENOATTR",
224
+ [-94]: "EBADMSG",
225
+ [-95]: "EMULTIHOP",
226
+ [-96]: "ENODATA",
227
+ [-97]: "ENOLINK",
228
+ [-98]: "ENOSR",
229
+ [-99]: "ENOSTR",
230
+ [-100]: "EPROTO",
231
+ [-101]: "ETIME",
232
+ [-102]: "EOPNOTSUPP"
233
+ };
234
+ function getPlatform() {
235
+ if (typeof globalThis.process?.platform === "string") return globalThis.process.platform;
236
+ return "linux";
237
+ }
238
+ function getSystemErrorName(err) {
239
+ if (typeof err !== "number") {
240
+ throw new TypeError('The "err" argument must be of type number. Received type ' + typeof err);
241
+ }
242
+ if (err >= 0) {
243
+ throw new RangeError(`The value of "err" is out of range. It must be a negative integer. Received ${err}`);
244
+ }
245
+ const platform = getPlatform();
246
+ const map = platform === "darwin" ? darwinErrors : linuxErrors;
247
+ return map[err] || `Unknown system error ${err}`;
248
+ }
249
+ function getSystemErrorMap() {
250
+ const platform = getPlatform();
251
+ const map = platform === "darwin" ? darwinErrors : linuxErrors;
252
+ const result = /* @__PURE__ */ new Map();
253
+ for (const [key, name] of Object.entries(map)) {
254
+ result.set(Number(key), [name, ""]);
255
+ }
256
+ return result;
257
+ }
258
+ export {
259
+ getSystemErrorMap,
260
+ getSystemErrorName
261
+ };