feat(helper/stream): add browser-compatible Writable interface
Define Writable interface, ConsoleWritable (console.log), and StderrWritable (console.error) as browser-safe stream abstractions. Export DEFAULT_STREAM backed by StderrWritable to match Python's sys.stderr default.
This commit is contained in:
parent
c297bb4499
commit
e6b7f02166
1 changed files with 32 additions and 1 deletions
|
|
@ -1,2 +1,33 @@
|
||||||
|
/**
|
||||||
|
* Minimal writable stream interface for browser compatibility.
|
||||||
|
*
|
||||||
|
* This abstracts over Node.js streams and browser console output,
|
||||||
|
* providing a common write target for handlers.
|
||||||
|
*/
|
||||||
|
export interface Writable {
|
||||||
|
write(data: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
export type MillisecondsSinceUnixEpoch = number;
|
/**
|
||||||
|
* A Writable backed by console.log.
|
||||||
|
*/
|
||||||
|
export class ConsoleWritable implements Writable {
|
||||||
|
write(data: string): void {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Writable backed by console.error (stderr equivalent).
|
||||||
|
*/
|
||||||
|
export class StderrWritable implements Writable {
|
||||||
|
write(data: string): void {
|
||||||
|
console.error(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default output stream. Uses console.error to match Python's default
|
||||||
|
* of writing to sys.stderr.
|
||||||
|
*/
|
||||||
|
export const DEFAULT_STREAM: Writable = new StderrWritable();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue