almostnode 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.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +731 -0
  3. package/dist/__sw__.js +394 -0
  4. package/dist/ai-chatbot-demo-entry.d.ts +6 -0
  5. package/dist/ai-chatbot-demo-entry.d.ts.map +1 -0
  6. package/dist/ai-chatbot-demo.d.ts +42 -0
  7. package/dist/ai-chatbot-demo.d.ts.map +1 -0
  8. package/dist/assets/runtime-worker-D9x_Ddwz.js +60543 -0
  9. package/dist/assets/runtime-worker-D9x_Ddwz.js.map +1 -0
  10. package/dist/convex-app-demo-entry.d.ts +6 -0
  11. package/dist/convex-app-demo-entry.d.ts.map +1 -0
  12. package/dist/convex-app-demo.d.ts +68 -0
  13. package/dist/convex-app-demo.d.ts.map +1 -0
  14. package/dist/cors-proxy.d.ts +46 -0
  15. package/dist/cors-proxy.d.ts.map +1 -0
  16. package/dist/create-runtime.d.ts +42 -0
  17. package/dist/create-runtime.d.ts.map +1 -0
  18. package/dist/demo.d.ts +6 -0
  19. package/dist/demo.d.ts.map +1 -0
  20. package/dist/dev-server.d.ts +97 -0
  21. package/dist/dev-server.d.ts.map +1 -0
  22. package/dist/frameworks/next-dev-server.d.ts +202 -0
  23. package/dist/frameworks/next-dev-server.d.ts.map +1 -0
  24. package/dist/frameworks/vite-dev-server.d.ts +85 -0
  25. package/dist/frameworks/vite-dev-server.d.ts.map +1 -0
  26. package/dist/index.cjs +14965 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.ts +71 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.mjs +14867 -0
  31. package/dist/index.mjs.map +1 -0
  32. package/dist/next-demo.d.ts +49 -0
  33. package/dist/next-demo.d.ts.map +1 -0
  34. package/dist/npm/index.d.ts +71 -0
  35. package/dist/npm/index.d.ts.map +1 -0
  36. package/dist/npm/registry.d.ts +66 -0
  37. package/dist/npm/registry.d.ts.map +1 -0
  38. package/dist/npm/resolver.d.ts +52 -0
  39. package/dist/npm/resolver.d.ts.map +1 -0
  40. package/dist/npm/tarball.d.ts +29 -0
  41. package/dist/npm/tarball.d.ts.map +1 -0
  42. package/dist/runtime-interface.d.ts +90 -0
  43. package/dist/runtime-interface.d.ts.map +1 -0
  44. package/dist/runtime.d.ts +103 -0
  45. package/dist/runtime.d.ts.map +1 -0
  46. package/dist/sandbox-helpers.d.ts +43 -0
  47. package/dist/sandbox-helpers.d.ts.map +1 -0
  48. package/dist/sandbox-runtime.d.ts +65 -0
  49. package/dist/sandbox-runtime.d.ts.map +1 -0
  50. package/dist/server-bridge.d.ts +89 -0
  51. package/dist/server-bridge.d.ts.map +1 -0
  52. package/dist/shims/assert.d.ts +51 -0
  53. package/dist/shims/assert.d.ts.map +1 -0
  54. package/dist/shims/async_hooks.d.ts +37 -0
  55. package/dist/shims/async_hooks.d.ts.map +1 -0
  56. package/dist/shims/buffer.d.ts +20 -0
  57. package/dist/shims/buffer.d.ts.map +1 -0
  58. package/dist/shims/child_process-browser.d.ts +92 -0
  59. package/dist/shims/child_process-browser.d.ts.map +1 -0
  60. package/dist/shims/child_process.d.ts +93 -0
  61. package/dist/shims/child_process.d.ts.map +1 -0
  62. package/dist/shims/chokidar.d.ts +55 -0
  63. package/dist/shims/chokidar.d.ts.map +1 -0
  64. package/dist/shims/cluster.d.ts +52 -0
  65. package/dist/shims/cluster.d.ts.map +1 -0
  66. package/dist/shims/crypto.d.ts +122 -0
  67. package/dist/shims/crypto.d.ts.map +1 -0
  68. package/dist/shims/dgram.d.ts +34 -0
  69. package/dist/shims/dgram.d.ts.map +1 -0
  70. package/dist/shims/diagnostics_channel.d.ts +80 -0
  71. package/dist/shims/diagnostics_channel.d.ts.map +1 -0
  72. package/dist/shims/dns.d.ts +87 -0
  73. package/dist/shims/dns.d.ts.map +1 -0
  74. package/dist/shims/domain.d.ts +25 -0
  75. package/dist/shims/domain.d.ts.map +1 -0
  76. package/dist/shims/esbuild.d.ts +105 -0
  77. package/dist/shims/esbuild.d.ts.map +1 -0
  78. package/dist/shims/events.d.ts +37 -0
  79. package/dist/shims/events.d.ts.map +1 -0
  80. package/dist/shims/fs.d.ts +115 -0
  81. package/dist/shims/fs.d.ts.map +1 -0
  82. package/dist/shims/fsevents.d.ts +67 -0
  83. package/dist/shims/fsevents.d.ts.map +1 -0
  84. package/dist/shims/http.d.ts +217 -0
  85. package/dist/shims/http.d.ts.map +1 -0
  86. package/dist/shims/http2.d.ts +81 -0
  87. package/dist/shims/http2.d.ts.map +1 -0
  88. package/dist/shims/https.d.ts +36 -0
  89. package/dist/shims/https.d.ts.map +1 -0
  90. package/dist/shims/inspector.d.ts +25 -0
  91. package/dist/shims/inspector.d.ts.map +1 -0
  92. package/dist/shims/module.d.ts +22 -0
  93. package/dist/shims/module.d.ts.map +1 -0
  94. package/dist/shims/net.d.ts +100 -0
  95. package/dist/shims/net.d.ts.map +1 -0
  96. package/dist/shims/os.d.ts +159 -0
  97. package/dist/shims/os.d.ts.map +1 -0
  98. package/dist/shims/path.d.ts +72 -0
  99. package/dist/shims/path.d.ts.map +1 -0
  100. package/dist/shims/perf_hooks.d.ts +50 -0
  101. package/dist/shims/perf_hooks.d.ts.map +1 -0
  102. package/dist/shims/process.d.ts +93 -0
  103. package/dist/shims/process.d.ts.map +1 -0
  104. package/dist/shims/querystring.d.ts +23 -0
  105. package/dist/shims/querystring.d.ts.map +1 -0
  106. package/dist/shims/readdirp.d.ts +52 -0
  107. package/dist/shims/readdirp.d.ts.map +1 -0
  108. package/dist/shims/readline.d.ts +62 -0
  109. package/dist/shims/readline.d.ts.map +1 -0
  110. package/dist/shims/rollup.d.ts +34 -0
  111. package/dist/shims/rollup.d.ts.map +1 -0
  112. package/dist/shims/sentry.d.ts +163 -0
  113. package/dist/shims/sentry.d.ts.map +1 -0
  114. package/dist/shims/stream.d.ts +181 -0
  115. package/dist/shims/stream.d.ts.map +1 -0
  116. package/dist/shims/tls.d.ts +53 -0
  117. package/dist/shims/tls.d.ts.map +1 -0
  118. package/dist/shims/tty.d.ts +30 -0
  119. package/dist/shims/tty.d.ts.map +1 -0
  120. package/dist/shims/url.d.ts +64 -0
  121. package/dist/shims/url.d.ts.map +1 -0
  122. package/dist/shims/util.d.ts +106 -0
  123. package/dist/shims/util.d.ts.map +1 -0
  124. package/dist/shims/v8.d.ts +73 -0
  125. package/dist/shims/v8.d.ts.map +1 -0
  126. package/dist/shims/vfs-adapter.d.ts +126 -0
  127. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  128. package/dist/shims/vm.d.ts +45 -0
  129. package/dist/shims/vm.d.ts.map +1 -0
  130. package/dist/shims/worker_threads.d.ts +66 -0
  131. package/dist/shims/worker_threads.d.ts.map +1 -0
  132. package/dist/shims/ws.d.ts +66 -0
  133. package/dist/shims/ws.d.ts.map +1 -0
  134. package/dist/shims/zlib.d.ts +161 -0
  135. package/dist/shims/zlib.d.ts.map +1 -0
  136. package/dist/transform.d.ts +24 -0
  137. package/dist/transform.d.ts.map +1 -0
  138. package/dist/virtual-fs.d.ts +226 -0
  139. package/dist/virtual-fs.d.ts.map +1 -0
  140. package/dist/vite-demo.d.ts +35 -0
  141. package/dist/vite-demo.d.ts.map +1 -0
  142. package/dist/vite-sw.js +132 -0
  143. package/dist/worker/runtime-worker.d.ts +8 -0
  144. package/dist/worker/runtime-worker.d.ts.map +1 -0
  145. package/dist/worker-runtime.d.ts +50 -0
  146. package/dist/worker-runtime.d.ts.map +1 -0
  147. package/package.json +85 -0
  148. package/src/ai-chatbot-demo-entry.ts +244 -0
  149. package/src/ai-chatbot-demo.ts +509 -0
  150. package/src/convex-app-demo-entry.ts +1107 -0
  151. package/src/convex-app-demo.ts +1316 -0
  152. package/src/cors-proxy.ts +81 -0
  153. package/src/create-runtime.ts +147 -0
  154. package/src/demo.ts +304 -0
  155. package/src/dev-server.ts +274 -0
  156. package/src/frameworks/next-dev-server.ts +2224 -0
  157. package/src/frameworks/vite-dev-server.ts +702 -0
  158. package/src/index.ts +101 -0
  159. package/src/next-demo.ts +1784 -0
  160. package/src/npm/index.ts +347 -0
  161. package/src/npm/registry.ts +152 -0
  162. package/src/npm/resolver.ts +385 -0
  163. package/src/npm/tarball.ts +209 -0
  164. package/src/runtime-interface.ts +103 -0
  165. package/src/runtime.ts +1046 -0
  166. package/src/sandbox-helpers.ts +173 -0
  167. package/src/sandbox-runtime.ts +252 -0
  168. package/src/server-bridge.ts +426 -0
  169. package/src/shims/assert.ts +664 -0
  170. package/src/shims/async_hooks.ts +86 -0
  171. package/src/shims/buffer.ts +75 -0
  172. package/src/shims/child_process-browser.ts +217 -0
  173. package/src/shims/child_process.ts +463 -0
  174. package/src/shims/chokidar.ts +313 -0
  175. package/src/shims/cluster.ts +67 -0
  176. package/src/shims/crypto.ts +830 -0
  177. package/src/shims/dgram.ts +47 -0
  178. package/src/shims/diagnostics_channel.ts +196 -0
  179. package/src/shims/dns.ts +172 -0
  180. package/src/shims/domain.ts +58 -0
  181. package/src/shims/esbuild.ts +805 -0
  182. package/src/shims/events.ts +195 -0
  183. package/src/shims/fs.ts +803 -0
  184. package/src/shims/fsevents.ts +63 -0
  185. package/src/shims/http.ts +904 -0
  186. package/src/shims/http2.ts +96 -0
  187. package/src/shims/https.ts +86 -0
  188. package/src/shims/inspector.ts +30 -0
  189. package/src/shims/module.ts +82 -0
  190. package/src/shims/net.ts +359 -0
  191. package/src/shims/os.ts +195 -0
  192. package/src/shims/path.ts +199 -0
  193. package/src/shims/perf_hooks.ts +92 -0
  194. package/src/shims/process.ts +346 -0
  195. package/src/shims/querystring.ts +97 -0
  196. package/src/shims/readdirp.ts +228 -0
  197. package/src/shims/readline.ts +110 -0
  198. package/src/shims/rollup.ts +80 -0
  199. package/src/shims/sentry.ts +133 -0
  200. package/src/shims/stream.ts +1126 -0
  201. package/src/shims/tls.ts +95 -0
  202. package/src/shims/tty.ts +64 -0
  203. package/src/shims/url.ts +171 -0
  204. package/src/shims/util.ts +312 -0
  205. package/src/shims/v8.ts +113 -0
  206. package/src/shims/vfs-adapter.ts +402 -0
  207. package/src/shims/vm.ts +83 -0
  208. package/src/shims/worker_threads.ts +111 -0
  209. package/src/shims/ws.ts +382 -0
  210. package/src/shims/zlib.ts +289 -0
  211. package/src/transform.ts +313 -0
  212. package/src/types/external.d.ts +67 -0
  213. package/src/virtual-fs.ts +903 -0
  214. package/src/vite-demo.ts +577 -0
  215. package/src/worker/runtime-worker.ts +128 -0
  216. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * tls shim - TLS/SSL is not available in browser
3
+ * Provides stubs that allow code to load without crashing
4
+ */
5
+
6
+ import { EventEmitter } from './events';
7
+ import * as net from './net';
8
+
9
+ export class TLSSocket extends EventEmitter {
10
+ authorized = false;
11
+ encrypted = true;
12
+
13
+ constructor(_socket?: unknown, _options?: unknown) {
14
+ super();
15
+ }
16
+
17
+ getPeerCertificate(_detailed?: boolean): object {
18
+ return {};
19
+ }
20
+
21
+ getCipher(): { name: string; version: string } | null {
22
+ return null;
23
+ }
24
+
25
+ getProtocol(): string | null {
26
+ return null;
27
+ }
28
+
29
+ setServername(_name: string): void {}
30
+
31
+ renegotiate(_options: unknown, _callback: (err: Error | null) => void): boolean {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ export class Server extends EventEmitter {
37
+ constructor(_options?: unknown, _connectionListener?: (socket: TLSSocket) => void) {
38
+ super();
39
+ }
40
+
41
+ listen(..._args: unknown[]): this {
42
+ return this;
43
+ }
44
+
45
+ close(_callback?: (err?: Error) => void): this {
46
+ return this;
47
+ }
48
+
49
+ address(): { port: number; family: string; address: string } | string | null {
50
+ return null;
51
+ }
52
+
53
+ getTicketKeys(): Buffer {
54
+ return Buffer.from('');
55
+ }
56
+
57
+ setTicketKeys(_keys: Buffer): void {}
58
+
59
+ setSecureContext(_options: unknown): void {}
60
+ }
61
+
62
+ export function createServer(_options?: unknown, _connectionListener?: (socket: TLSSocket) => void): Server {
63
+ return new Server(_options, _connectionListener);
64
+ }
65
+
66
+ export function connect(_options: unknown, _callback?: () => void): TLSSocket {
67
+ const socket = new TLSSocket();
68
+ if (_callback) {
69
+ setTimeout(_callback, 0);
70
+ }
71
+ return socket;
72
+ }
73
+
74
+ export const createSecureContext = (_options?: unknown) => ({});
75
+
76
+ export const getCiphers = () => ['TLS_AES_256_GCM_SHA384', 'TLS_AES_128_GCM_SHA256'];
77
+
78
+ export const DEFAULT_ECDH_CURVE = 'auto';
79
+ export const DEFAULT_MAX_VERSION = 'TLSv1.3';
80
+ export const DEFAULT_MIN_VERSION = 'TLSv1.2';
81
+
82
+ export const rootCertificates: string[] = [];
83
+
84
+ export default {
85
+ TLSSocket,
86
+ Server,
87
+ createServer,
88
+ connect,
89
+ createSecureContext,
90
+ getCiphers,
91
+ DEFAULT_ECDH_CURVE,
92
+ DEFAULT_MAX_VERSION,
93
+ DEFAULT_MIN_VERSION,
94
+ rootCertificates,
95
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Node.js tty module shim
3
+ * Provides terminal detection utilities
4
+ */
5
+
6
+ import { Readable, Writable } from './stream';
7
+
8
+ export class ReadStream extends Readable {
9
+ isTTY: boolean = false;
10
+ isRaw: boolean = false;
11
+
12
+ setRawMode(mode: boolean): this {
13
+ this.isRaw = mode;
14
+ return this;
15
+ }
16
+ }
17
+
18
+ export class WriteStream extends Writable {
19
+ isTTY: boolean = false;
20
+ columns: number = 80;
21
+ rows: number = 24;
22
+
23
+ clearLine(dir: number, callback?: () => void): boolean {
24
+ if (callback) callback();
25
+ return true;
26
+ }
27
+
28
+ clearScreenDown(callback?: () => void): boolean {
29
+ if (callback) callback();
30
+ return true;
31
+ }
32
+
33
+ cursorTo(x: number, y?: number, callback?: () => void): boolean {
34
+ if (callback) callback();
35
+ return true;
36
+ }
37
+
38
+ moveCursor(dx: number, dy: number, callback?: () => void): boolean {
39
+ if (callback) callback();
40
+ return true;
41
+ }
42
+
43
+ getColorDepth(env?: object): number {
44
+ return 1; // No color support in browser
45
+ }
46
+
47
+ hasColors(count?: number | object, env?: object): boolean {
48
+ return false;
49
+ }
50
+
51
+ getWindowSize(): [number, number] {
52
+ return [this.columns, this.rows];
53
+ }
54
+ }
55
+
56
+ export function isatty(fd: number): boolean {
57
+ return false; // Browser is never a TTY
58
+ }
59
+
60
+ export default {
61
+ ReadStream,
62
+ WriteStream,
63
+ isatty,
64
+ };
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Node.js url module shim
3
+ * Uses browser's built-in URL API
4
+ */
5
+
6
+ export interface UrlObject {
7
+ protocol?: string | null;
8
+ slashes?: boolean | null;
9
+ auth?: string | null;
10
+ host?: string | null;
11
+ port?: string | null;
12
+ hostname?: string | null;
13
+ hash?: string | null;
14
+ search?: string | null;
15
+ query?: string | Record<string, string | string[]> | null;
16
+ pathname?: string | null;
17
+ path?: string | null;
18
+ href?: string;
19
+ }
20
+
21
+ export function parse(
22
+ urlString: string,
23
+ parseQueryString: boolean = false,
24
+ slashesDenoteHost: boolean = false
25
+ ): UrlObject {
26
+ try {
27
+ const url = new URL(urlString, 'http://localhost');
28
+ const result: UrlObject = {
29
+ protocol: url.protocol,
30
+ slashes: url.protocol.endsWith(':'),
31
+ auth: url.username ? `${url.username}:${url.password}` : null,
32
+ host: url.host,
33
+ port: url.port || null,
34
+ hostname: url.hostname,
35
+ hash: url.hash || null,
36
+ search: url.search || null,
37
+ query: parseQueryString ? Object.fromEntries(url.searchParams) : url.search?.slice(1) || null,
38
+ pathname: url.pathname,
39
+ path: url.pathname + url.search,
40
+ href: url.href,
41
+ };
42
+ return result;
43
+ } catch {
44
+ // Handle relative URLs
45
+ return {
46
+ protocol: null,
47
+ slashes: null,
48
+ auth: null,
49
+ host: null,
50
+ port: null,
51
+ hostname: null,
52
+ hash: null,
53
+ search: null,
54
+ query: null,
55
+ pathname: urlString,
56
+ path: urlString,
57
+ href: urlString,
58
+ };
59
+ }
60
+ }
61
+
62
+ export function format(urlObject: UrlObject): string {
63
+ if (urlObject.href) {
64
+ return urlObject.href;
65
+ }
66
+
67
+ let result = '';
68
+
69
+ if (urlObject.protocol) {
70
+ result += urlObject.protocol;
71
+ if (!urlObject.protocol.endsWith(':')) {
72
+ result += ':';
73
+ }
74
+ }
75
+
76
+ if (urlObject.slashes || urlObject.protocol === 'http:' || urlObject.protocol === 'https:') {
77
+ result += '//';
78
+ }
79
+
80
+ if (urlObject.auth) {
81
+ result += urlObject.auth + '@';
82
+ }
83
+
84
+ if (urlObject.hostname) {
85
+ result += urlObject.hostname;
86
+ } else if (urlObject.host) {
87
+ result += urlObject.host;
88
+ }
89
+
90
+ if (urlObject.port) {
91
+ result += ':' + urlObject.port;
92
+ }
93
+
94
+ if (urlObject.pathname) {
95
+ result += urlObject.pathname;
96
+ }
97
+
98
+ if (urlObject.search) {
99
+ result += urlObject.search;
100
+ } else if (urlObject.query) {
101
+ if (typeof urlObject.query === 'string') {
102
+ result += '?' + urlObject.query;
103
+ } else {
104
+ const params = new URLSearchParams();
105
+ for (const [key, value] of Object.entries(urlObject.query)) {
106
+ if (Array.isArray(value)) {
107
+ for (const v of value) {
108
+ params.append(key, v);
109
+ }
110
+ } else {
111
+ params.set(key, value);
112
+ }
113
+ }
114
+ const search = params.toString();
115
+ if (search) {
116
+ result += '?' + search;
117
+ }
118
+ }
119
+ }
120
+
121
+ if (urlObject.hash) {
122
+ result += urlObject.hash;
123
+ }
124
+
125
+ return result;
126
+ }
127
+
128
+ export function resolve(from: string, to: string): string {
129
+ try {
130
+ return new URL(to, from).href;
131
+ } catch {
132
+ return to;
133
+ }
134
+ }
135
+
136
+ // Re-export URL and URLSearchParams from globals
137
+ export const URL = globalThis.URL;
138
+ export const URLSearchParams = globalThis.URLSearchParams;
139
+
140
+ /**
141
+ * Convert a file:// URL to a file path
142
+ * Node.js: url.fileURLToPath('file:///home/user/file.txt') -> '/home/user/file.txt'
143
+ */
144
+ export function fileURLToPath(url: string | URL): string {
145
+ const urlObj = typeof url === 'string' ? new globalThis.URL(url) : url;
146
+ if (urlObj.protocol !== 'file:') {
147
+ throw new TypeError('The URL must be of scheme file');
148
+ }
149
+ // Decode percent-encoded characters and return pathname
150
+ return decodeURIComponent(urlObj.pathname);
151
+ }
152
+
153
+ /**
154
+ * Convert a file path to a file:// URL
155
+ * Node.js: url.pathToFileURL('/home/user/file.txt') -> URL { href: 'file:///home/user/file.txt' }
156
+ */
157
+ export function pathToFileURL(path: string): URL {
158
+ // Encode special characters in path
159
+ const encoded = encodeURIComponent(path).replace(/%2F/g, '/');
160
+ return new globalThis.URL('file://' + encoded);
161
+ }
162
+
163
+ export default {
164
+ parse,
165
+ format,
166
+ resolve,
167
+ URL,
168
+ URLSearchParams,
169
+ fileURLToPath,
170
+ pathToFileURL,
171
+ };
@@ -0,0 +1,312 @@
1
+ /**
2
+ * Node.js util module shim
3
+ * Basic utility functions
4
+ */
5
+
6
+ export function format(fmt: string, ...args: unknown[]): string {
7
+ if (typeof fmt !== 'string') {
8
+ return args.map((arg) => inspect(arg)).join(' ');
9
+ }
10
+
11
+ let i = 0;
12
+ return fmt.replace(/%[sdjifoO%]/g, (match) => {
13
+ if (match === '%%') return '%';
14
+ if (i >= args.length) return match;
15
+
16
+ const arg = args[i++];
17
+
18
+ switch (match) {
19
+ case '%s':
20
+ return String(arg);
21
+ case '%d':
22
+ case '%i':
23
+ return String(parseInt(String(arg), 10));
24
+ case '%f':
25
+ return String(parseFloat(String(arg)));
26
+ case '%j':
27
+ try {
28
+ return JSON.stringify(arg);
29
+ } catch {
30
+ return '[Circular]';
31
+ }
32
+ case '%o':
33
+ case '%O':
34
+ return inspect(arg);
35
+ default:
36
+ return match;
37
+ }
38
+ });
39
+ }
40
+
41
+ export function inspect(obj: unknown, options?: { depth?: number; colors?: boolean }): string {
42
+ const seen = new WeakSet();
43
+ const depth = options?.depth ?? 2;
44
+
45
+ function inspectValue(value: unknown, currentDepth: number): string {
46
+ if (value === null) return 'null';
47
+ if (value === undefined) return 'undefined';
48
+
49
+ const type = typeof value;
50
+
51
+ if (type === 'string') {
52
+ return `'${value}'`;
53
+ }
54
+
55
+ if (type === 'number' || type === 'boolean' || type === 'bigint') {
56
+ return String(value);
57
+ }
58
+
59
+ if (type === 'symbol') {
60
+ return value.toString();
61
+ }
62
+
63
+ if (type === 'function') {
64
+ const name = (value as Function).name || 'anonymous';
65
+ return `[Function: ${name}]`;
66
+ }
67
+
68
+ if (type !== 'object') {
69
+ return String(value);
70
+ }
71
+
72
+ // Handle circular references
73
+ if (seen.has(value as object)) {
74
+ return '[Circular]';
75
+ }
76
+ seen.add(value as object);
77
+
78
+ if (currentDepth > depth) {
79
+ return Array.isArray(value) ? '[Array]' : '[Object]';
80
+ }
81
+
82
+ if (Array.isArray(value)) {
83
+ if (value.length === 0) return '[]';
84
+ const items = value.map((v) => inspectValue(v, currentDepth + 1));
85
+ return `[ ${items.join(', ')} ]`;
86
+ }
87
+
88
+ if (value instanceof Date) {
89
+ return value.toISOString();
90
+ }
91
+
92
+ if (value instanceof RegExp) {
93
+ return value.toString();
94
+ }
95
+
96
+ if (value instanceof Error) {
97
+ return `${value.name}: ${value.message}`;
98
+ }
99
+
100
+ if (value instanceof Map) {
101
+ const entries = [...value.entries()].map(
102
+ ([k, v]) => `${inspectValue(k, currentDepth + 1)} => ${inspectValue(v, currentDepth + 1)}`
103
+ );
104
+ return `Map(${value.size}) { ${entries.join(', ')} }`;
105
+ }
106
+
107
+ if (value instanceof Set) {
108
+ const items = [...value].map((v) => inspectValue(v, currentDepth + 1));
109
+ return `Set(${value.size}) { ${items.join(', ')} }`;
110
+ }
111
+
112
+ // Plain object
113
+ const keys = Object.keys(value as object);
114
+ if (keys.length === 0) return '{}';
115
+
116
+ const entries = keys.map((key) => {
117
+ const val = (value as Record<string, unknown>)[key];
118
+ return `${key}: ${inspectValue(val, currentDepth + 1)}`;
119
+ });
120
+
121
+ return `{ ${entries.join(', ')} }`;
122
+ }
123
+
124
+ return inspectValue(obj, 0);
125
+ }
126
+
127
+ export function inherits(
128
+ ctor: Function,
129
+ superCtor: Function
130
+ ): void {
131
+ if (ctor === undefined || ctor === null) {
132
+ throw new TypeError('inherits: ctor must be a function');
133
+ }
134
+ if (superCtor === undefined || superCtor === null) {
135
+ // Some packages call inherits with undefined as a no-op, just return
136
+ return;
137
+ }
138
+ if (superCtor.prototype === undefined) {
139
+ // Skip if superCtor doesn't have a prototype
140
+ return;
141
+ }
142
+ (ctor as any).super_ = superCtor;
143
+ Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
144
+ }
145
+
146
+ export function deprecate<T extends Function>(
147
+ fn: T,
148
+ msg: string,
149
+ code?: string
150
+ ): T {
151
+ let warned = false;
152
+ const deprecated = function (this: unknown, ...args: unknown[]) {
153
+ if (!warned) {
154
+ console.warn(`DeprecationWarning: ${msg}${code ? ` (${code})` : ''}`);
155
+ warned = true;
156
+ }
157
+ return fn.apply(this, args);
158
+ };
159
+ return deprecated as unknown as T;
160
+ }
161
+
162
+ export function promisify<T>(
163
+ fn: (...args: [...unknown[], (err: Error | null, result: T) => void]) => void
164
+ ): (...args: unknown[]) => Promise<T> {
165
+ return (...args: unknown[]) => {
166
+ return new Promise((resolve, reject) => {
167
+ fn(...args, (err: Error | null, result: T) => {
168
+ if (err) {
169
+ reject(err);
170
+ } else {
171
+ resolve(result);
172
+ }
173
+ });
174
+ });
175
+ };
176
+ }
177
+
178
+ export function callbackify<T>(
179
+ fn: (...args: unknown[]) => Promise<T>
180
+ ): (...args: [...unknown[], (err: Error | null, result: T) => void]) => void {
181
+ return (...args: unknown[]) => {
182
+ const callback = args.pop() as (err: Error | null, result: T) => void;
183
+ fn(...args)
184
+ .then((result) => callback(null, result))
185
+ .catch((err) => callback(err, undefined as unknown as T));
186
+ };
187
+ }
188
+
189
+ export function isArray(value: unknown): value is unknown[] {
190
+ return Array.isArray(value);
191
+ }
192
+
193
+ export function isBoolean(value: unknown): value is boolean {
194
+ return typeof value === 'boolean';
195
+ }
196
+
197
+ export function isNull(value: unknown): value is null {
198
+ return value === null;
199
+ }
200
+
201
+ export function isNullOrUndefined(value: unknown): value is null | undefined {
202
+ return value === null || value === undefined;
203
+ }
204
+
205
+ export function isNumber(value: unknown): value is number {
206
+ return typeof value === 'number';
207
+ }
208
+
209
+ export function isString(value: unknown): value is string {
210
+ return typeof value === 'string';
211
+ }
212
+
213
+ export function isUndefined(value: unknown): value is undefined {
214
+ return value === undefined;
215
+ }
216
+
217
+ export function isRegExp(value: unknown): value is RegExp {
218
+ return value instanceof RegExp;
219
+ }
220
+
221
+ export function isObject(value: unknown): value is object {
222
+ return typeof value === 'object' && value !== null;
223
+ }
224
+
225
+ export function isDate(value: unknown): value is Date {
226
+ return value instanceof Date;
227
+ }
228
+
229
+ export function isError(value: unknown): value is Error {
230
+ return value instanceof Error;
231
+ }
232
+
233
+ export function isFunction(value: unknown): value is Function {
234
+ return typeof value === 'function';
235
+ }
236
+
237
+ export function isPrimitive(value: unknown): boolean {
238
+ return value === null || (typeof value !== 'object' && typeof value !== 'function');
239
+ }
240
+
241
+ export function isBuffer(value: unknown): boolean {
242
+ return value instanceof Uint8Array;
243
+ }
244
+
245
+ /**
246
+ * Returns a function that logs debug messages when NODE_DEBUG includes the section
247
+ */
248
+ export function debuglog(section: string): (...args: unknown[]) => void {
249
+ const nodeDebug = (typeof process !== 'undefined' && process.env?.NODE_DEBUG) || '';
250
+ const enabled = nodeDebug.toLowerCase().includes(section.toLowerCase());
251
+
252
+ if (enabled) {
253
+ return (...args: unknown[]) => {
254
+ console.error(`${section.toUpperCase()} ${process?.pid || 0}:`, ...args);
255
+ };
256
+ }
257
+
258
+ // Return a no-op function
259
+ return () => {};
260
+ }
261
+
262
+ // Alias for debuglog
263
+ export const debug = debuglog;
264
+
265
+ export const types = {
266
+ isArray,
267
+ isBoolean,
268
+ isNull,
269
+ isNullOrUndefined,
270
+ isNumber,
271
+ isString,
272
+ isUndefined,
273
+ isRegExp,
274
+ isObject,
275
+ isDate,
276
+ isError,
277
+ isFunction,
278
+ isPrimitive,
279
+ isBuffer,
280
+ };
281
+
282
+ // Re-export TextEncoder and TextDecoder from global
283
+ export const TextEncoder = globalThis.TextEncoder;
284
+ export const TextDecoder = globalThis.TextDecoder;
285
+
286
+ export default {
287
+ format,
288
+ inspect,
289
+ inherits,
290
+ deprecate,
291
+ promisify,
292
+ callbackify,
293
+ debuglog,
294
+ debug,
295
+ isArray,
296
+ isBoolean,
297
+ isNull,
298
+ isNullOrUndefined,
299
+ isNumber,
300
+ isString,
301
+ isUndefined,
302
+ isRegExp,
303
+ isObject,
304
+ isDate,
305
+ isError,
306
+ isFunction,
307
+ isPrimitive,
308
+ isBuffer,
309
+ types,
310
+ TextEncoder,
311
+ TextDecoder,
312
+ };