summaryrefslogtreecommitdiff
path: root/std/node/util.ts
diff options
context:
space:
mode:
authorSchwarzkopf Balázs <schwarzkopfb@icloud.com>2020-09-14 16:22:07 +0200
committerGitHub <noreply@github.com>2020-09-14 16:22:07 +0200
commitf6bfdd66a69fb01077e488b5a67a38ca3d43610e (patch)
treeb2613d944f83bfdc2d17691494d87ca839ed4f30 /std/node/util.ts
parenta6f34d47222ad7cc40519bd95a58ae773d1fe656 (diff)
feat(std/node): Add AssertionError class (#7210)
Diffstat (limited to 'std/node/util.ts')
-rw-r--r--std/node/util.ts29
1 files changed, 25 insertions, 4 deletions
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,
});
}