diff --git a/src/data.ts b/src/data.ts index 7590e4a..0dd40be 100644 --- a/src/data.ts +++ b/src/data.ts @@ -1,6 +1,8 @@ import type { CompoundTag } from "./tag.js"; import { Int } from "./primitive.js"; +import type { inspect as inspectFn, InspectOptionsStylized } from "node:util"; + export type Name = string | null; export type Endian = "big" | "little"; export type Compression = "gzip" | "deflate"; @@ -83,4 +85,8 @@ export class NBTData { get [Symbol.toStringTag]() { return "NBTData" as const; } + + [Symbol.for("nodejs.util.inspect.custom")](depth: number, options: InspectOptionsStylized, inspect: typeof inspectFn) { + return `${this[Symbol.toStringTag]} ${inspect(this.#data,{ colors: true })}`; + } } \ No newline at end of file diff --git a/src/primitive.ts b/src/primitive.ts index 558c1d3..2f84668 100644 --- a/src/primitive.ts +++ b/src/primitive.ts @@ -1,3 +1,5 @@ +import type { inspect as inspectFn, InspectOptionsStylized } from "node:util"; + export class Byte extends Number { constructor(value: T) { super(value << 24 >> 24); @@ -10,6 +12,10 @@ export class Byte extends Number { get [Symbol.toStringTag]() { return "Byte" as const; } + + [Symbol.for("nodejs.util.inspect.custom")](_: number, { stylize }: InspectOptionsStylized) { + return stylize(`${this.valueOf()}b`,"number"); + } } export class Short extends Number { @@ -24,6 +30,10 @@ export class Short extends Number { get [Symbol.toStringTag]() { return "Short" as const; } + + [Symbol.for("nodejs.util.inspect.custom")](_: number, { stylize }: InspectOptionsStylized) { + return stylize(`${this.valueOf()}s`,"number"); + } } export class Int extends Number { @@ -38,6 +48,10 @@ export class Int extends Number { get [Symbol.toStringTag]() { return "Int" as const; } + + [Symbol.for("nodejs.util.inspect.custom")](_: number, options: InspectOptionsStylized, inspect: typeof inspectFn) { + return `Int { ${inspect(this.valueOf(),{ colors: true })} }`; + } } export class Float extends Number { @@ -52,4 +66,8 @@ export class Float extends Number { get [Symbol.toStringTag]() { return "Float" as const; } + + [Symbol.for("nodejs.util.inspect.custom")](_: number, { stylize }: InspectOptionsStylized) { + return stylize(`${this.valueOf()}f`,"number"); + } } \ No newline at end of file