diff --git a/std/node/util.ts b/std/node/util.ts index 8e3c50b879..e897931f2e 100644 --- a/std/node/util.ts +++ b/std/node/util.ts @@ -4,6 +4,16 @@ import * as types from "./_util/_util_types.ts"; export { types }; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function inspect(object: unknown, ...opts: any): string { + return Deno.inspect(object, { + depth: opts.depth ?? 4, + iterableLimit: opts.iterableLimit ?? 100, + compact: !!(opts.compact ?? true), + sorted: !!(opts.sorted ?? false), + }); +} + export function isArray(value: unknown): boolean { return Array.isArray(value); } diff --git a/std/node/util_test.ts b/std/node/util_test.ts index cedd85a87e..b1be36ce1a 100644 --- a/std/node/util_test.ts +++ b/std/node/util_test.ts @@ -1,6 +1,14 @@ -import { assert } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../testing/asserts.ts"; +import { stripColor } from "../fmt/colors.ts"; import * as util from "./util.ts"; +Deno.test({ + name: "[util] inspect", + fn() { + assertEquals(stripColor(util.inspect({ foo: 123 })), "{ foo: 123 }"); + }, +}); + Deno.test({ name: "[util] isBoolean", fn() {