Skip to content

Commit

Permalink
feat(node): add util.inspect (denoland/deno#6833)
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton authored and caspervonb committed Jan 31, 2021
1 parent 917dd46 commit 466ae0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion node/util_test.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit 466ae0a

Please sign in to comment.