9 changed files with 193 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||||
|
// Minimal assert module implementation for browser
|
||||
|
const assert = { |
||||
|
ok: (value, message) => { |
||||
|
if (!value) { |
||||
|
throw new Error(message || "Assertion failed"); |
||||
|
} |
||||
|
}, |
||||
|
equal: (actual, expected, message) => { |
||||
|
if (actual !== expected) { |
||||
|
throw new Error(message || `Expected ${expected} but got ${actual}`); |
||||
|
} |
||||
|
}, |
||||
|
strictEqual: (actual, expected, message) => { |
||||
|
if (actual !== expected) { |
||||
|
throw new Error(message || `Expected ${expected} but got ${actual}`); |
||||
|
} |
||||
|
}, |
||||
|
deepEqual: (actual, expected, message) => { |
||||
|
if (JSON.stringify(actual) !== JSON.stringify(expected)) { |
||||
|
throw new Error( |
||||
|
message || |
||||
|
`Expected ${JSON.stringify(expected)} but got ${JSON.stringify(actual)}`, |
||||
|
); |
||||
|
} |
||||
|
}, |
||||
|
fail: (message) => { |
||||
|
throw new Error(message || "Assertion failed"); |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default assert; |
@ -0,0 +1,14 @@ |
|||||
|
// Minimal http module implementation for browser
|
||||
|
const http = { |
||||
|
request: () => { |
||||
|
throw new Error("http.request is not supported in browser"); |
||||
|
}, |
||||
|
get: () => { |
||||
|
throw new Error("http.get is not supported in browser"); |
||||
|
}, |
||||
|
createServer: () => { |
||||
|
throw new Error("http.createServer is not supported in browser"); |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default http; |
@ -0,0 +1,14 @@ |
|||||
|
// Minimal https module implementation for browser
|
||||
|
const https = { |
||||
|
request: () => { |
||||
|
throw new Error("https.request is not supported in browser"); |
||||
|
}, |
||||
|
get: () => { |
||||
|
throw new Error("https.get is not supported in browser"); |
||||
|
}, |
||||
|
createServer: () => { |
||||
|
throw new Error("https.createServer is not supported in browser"); |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default https; |
@ -0,0 +1,25 @@ |
|||||
|
// Minimal stream module implementation for browser
|
||||
|
const stream = { |
||||
|
Readable: class Readable { |
||||
|
constructor() { |
||||
|
throw new Error("stream.Readable is not supported in browser"); |
||||
|
} |
||||
|
}, |
||||
|
Writable: class Writable { |
||||
|
constructor() { |
||||
|
throw new Error("stream.Writable is not supported in browser"); |
||||
|
} |
||||
|
}, |
||||
|
Transform: class Transform { |
||||
|
constructor() { |
||||
|
throw new Error("stream.Transform is not supported in browser"); |
||||
|
} |
||||
|
}, |
||||
|
PassThrough: class PassThrough { |
||||
|
constructor() { |
||||
|
throw new Error("stream.PassThrough is not supported in browser"); |
||||
|
} |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default stream; |
@ -0,0 +1,16 @@ |
|||||
|
// Minimal tty module implementation for browser
|
||||
|
const tty = { |
||||
|
isatty: () => false, |
||||
|
ReadStream: class ReadStream { |
||||
|
constructor() { |
||||
|
throw new Error("tty.ReadStream is not supported in browser"); |
||||
|
} |
||||
|
}, |
||||
|
WriteStream: class WriteStream { |
||||
|
constructor() { |
||||
|
throw new Error("tty.WriteStream is not supported in browser"); |
||||
|
} |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default tty; |
@ -0,0 +1,25 @@ |
|||||
|
// Minimal url module implementation for browser
|
||||
|
const url = { |
||||
|
parse: (urlString) => { |
||||
|
try { |
||||
|
return new URL(urlString); |
||||
|
} catch (e) { |
||||
|
throw new Error(`Invalid URL: ${urlString}`); |
||||
|
} |
||||
|
}, |
||||
|
format: (urlObj) => { |
||||
|
if (urlObj instanceof URL) { |
||||
|
return urlObj.href; |
||||
|
} |
||||
|
return urlObj.toString(); |
||||
|
}, |
||||
|
resolve: (from, to) => { |
||||
|
try { |
||||
|
return new URL(to, from).href; |
||||
|
} catch (e) { |
||||
|
throw new Error(`Invalid URL resolution: ${from} -> ${to}`); |
||||
|
} |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default url; |
@ -0,0 +1,31 @@ |
|||||
|
// Minimal util module implementation for browser
|
||||
|
const util = { |
||||
|
inherits: () => {}, |
||||
|
format: (...args) => args.join(" "), |
||||
|
inspect: (obj) => JSON.stringify(obj), |
||||
|
isArray: Array.isArray, |
||||
|
isBoolean: (val) => typeof val === "boolean", |
||||
|
isNull: (val) => val === null, |
||||
|
isNullOrUndefined: (val) => val == null, |
||||
|
isNumber: (val) => typeof val === "number", |
||||
|
isString: (val) => typeof val === "string", |
||||
|
isSymbol: (val) => typeof val === "symbol", |
||||
|
isUndefined: (val) => val === undefined, |
||||
|
isRegExp: (val) => val instanceof RegExp, |
||||
|
isDate: (val) => val instanceof Date, |
||||
|
isError: (val) => val instanceof Error, |
||||
|
isFunction: (val) => typeof val === "function", |
||||
|
isObject: (val) => val !== null && typeof val === "object", |
||||
|
isPrimitive: (val) => { |
||||
|
return ( |
||||
|
val === null || |
||||
|
typeof val === "boolean" || |
||||
|
typeof val === "number" || |
||||
|
typeof val === "string" || |
||||
|
typeof val === "symbol" || |
||||
|
typeof val === "undefined" |
||||
|
); |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default util; |
@ -0,0 +1,29 @@ |
|||||
|
// Minimal zlib module implementation for browser
|
||||
|
const zlib = { |
||||
|
gzip: () => { |
||||
|
throw new Error("zlib.gzip is not supported in browser"); |
||||
|
}, |
||||
|
gunzip: () => { |
||||
|
throw new Error("zlib.gunzip is not supported in browser"); |
||||
|
}, |
||||
|
deflate: () => { |
||||
|
throw new Error("zlib.deflate is not supported in browser"); |
||||
|
}, |
||||
|
inflate: () => { |
||||
|
throw new Error("zlib.inflate is not supported in browser"); |
||||
|
}, |
||||
|
createGzip: () => { |
||||
|
throw new Error("zlib.createGzip is not supported in browser"); |
||||
|
}, |
||||
|
createGunzip: () => { |
||||
|
throw new Error("zlib.createGunzip is not supported in browser"); |
||||
|
}, |
||||
|
createDeflate: () => { |
||||
|
throw new Error("zlib.createDeflate is not supported in browser"); |
||||
|
}, |
||||
|
createInflate: () => { |
||||
|
throw new Error("zlib.createInflate is not supported in browser"); |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
export default zlib; |
Loading…
Reference in new issue