From f6bfdd66a69fb01077e488b5a67a38ca3d43610e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schwarzkopf=20Bal=C3=A1zs?= Date: Mon, 14 Sep 2020 16:22:07 +0200 Subject: feat(std/node): Add AssertionError class (#7210) --- std/node/util.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'std/node/util.ts') diff --git a/std/node/util.ts b/std/node/util.ts index ce1c06b7c..9cca3e835 100644 --- a/std/node/util.ts +++ b/std/node/util.ts @@ -4,13 +4,34 @@ import * as types from "./_util/_util_types.ts"; export { types }; +const DEFAULT_INSPECT_OPTIONS = { + showHidden: false, + depth: 2, + colors: false, + customInspect: true, + showProxy: false, + maxArrayLength: 100, + maxStringLength: Infinity, + breakLength: 80, + compact: 3, + sorted: false, + getters: false, +}; + +inspect.defaultOptions = DEFAULT_INSPECT_OPTIONS; +inspect.custom = Deno.customInspect; + +// TODO(schwarzkopfb): make it in-line with Node's implementation +// Ref: https://nodejs.org/dist/latest-v14.x/docs/api/util.html#util_util_inspect_object_options // eslint-disable-next-line @typescript-eslint/no-explicit-any export function inspect(object: unknown, ...opts: any): string { + opts = { ...DEFAULT_INSPECT_OPTIONS, ...opts }; return Deno.inspect(object, { - depth: opts.depth ?? 4, - iterableLimit: opts.iterableLimit ?? 100, - compact: !!(opts.compact ?? true), - sorted: !!(opts.sorted ?? false), + depth: opts.depth, + iterableLimit: opts.maxArrayLength, + compact: !!opts.compact, + sorted: !!opts.sorted, + showProxy: !!opts.showProxy, }); } -- cgit v1.2.3