diff options
author | Benjamin Lupton <b@lupton.cc> | 2020-08-13 04:03:51 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 14:03:51 -0400 |
commit | 452693256ce7b607fa0b9454b22c57748f616742 (patch) | |
tree | 31126efb5a41bc5de305feab540dd582c60960c5 /std/node | |
parent | 3d70a2b94eac4d4032b8b11039efe6d070fa114f (diff) |
feat(std/node): add util.inspect (#6833)
Diffstat (limited to 'std/node')
-rw-r--r-- | std/node/util.ts | 10 | ||||
-rw-r--r-- | std/node/util_test.ts | 10 |
2 files changed, 19 insertions, 1 deletions
diff --git a/std/node/util.ts b/std/node/util.ts index 8e3c50b87..e897931f2 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 cedd85a87..b1be36ce1 100644 --- a/std/node/util_test.ts +++ b/std/node/util_test.ts @@ -1,7 +1,15 @@ -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() { assert(util.isBoolean(true)); |