mirror of
https://github.com/LukeHagar/crossws.git
synced 2025-12-09 20:37:49 +00:00
28 lines
538 B
TypeScript
28 lines
538 B
TypeScript
import { toBufferLike } from "./_utils.ts";
|
|
|
|
export class Message {
|
|
constructor(
|
|
public readonly rawData: any,
|
|
public readonly isBinary?: boolean,
|
|
) {}
|
|
|
|
text(): string {
|
|
if (typeof this.rawData === "string") {
|
|
return this.rawData;
|
|
}
|
|
const buff = toBufferLike(this.rawData);
|
|
if (typeof buff === "string") {
|
|
return buff;
|
|
}
|
|
return new TextDecoder().decode(buff);
|
|
}
|
|
|
|
toString() {
|
|
return this.text();
|
|
}
|
|
|
|
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
return this.text();
|
|
}
|
|
}
|