-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom inspection for Node.js and Deno
- Loading branch information
1 parent
24d6855
commit 6ec5f2f
Showing
6 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./inspect/deno.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const DEFAULT_INSPECT_OPTIONS = { | ||
depth: 4, | ||
indentLevel: 0, | ||
sorted: false, | ||
trailingComma: false, | ||
compact: true, | ||
iterableLimit: 100, | ||
showProxy: false, | ||
colors: false, | ||
getters: false, | ||
showHidden: false, | ||
}; | ||
|
||
/** | ||
* @example | ||
* ``` | ||
* // deno-lint-ignore no-explicit-any | ||
* (Float16Array.prototype as any)[Symbol.for("Deno.customInspect")] = customInspect; | ||
* ``` | ||
* @todo Current custom inspector cannot access options. See [enhance custom inspect API proposal](https://github.com/denoland/deno/issues/8099) | ||
*/ | ||
export function customInspect(inspect: typeof Deno.inspect): string { | ||
const array = []; | ||
for (let i = 0; i < this.length; ++i) { | ||
array[i] = this[i]; | ||
} | ||
|
||
return `Float16Array(${this.length}) ${inspect(array, DEFAULT_INSPECT_OPTIONS)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-env node */ | ||
|
||
"use strict"; | ||
|
||
const util = require("util"); | ||
|
||
/** | ||
* @example | ||
* ``` | ||
* Float16Array.prototype[Symbol.for("nodejs.util.inspect.custom")] = customInspect; | ||
* ``` | ||
*/ | ||
module.exports.customInspect = function customInspect(_deps, options) { | ||
const array = []; | ||
for (let i = 0; i < this.length; ++i) { | ||
array[i] = this[i]; | ||
} | ||
|
||
return `Float16Array(${this.length}) ${util.inspect(array, options)}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-env node */ | ||
|
||
import util from "util"; | ||
|
||
/** | ||
* @example | ||
* ``` | ||
* Float16Array.prototype[Symbol.for("nodejs.util.inspect.custom")] = customInspect; | ||
* ``` | ||
*/ | ||
export function customInspect(_deps, options) { | ||
const array = []; | ||
for (let i = 0; i < this.length; ++i) { | ||
array[i] = this[i]; | ||
} | ||
|
||
return `Float16Array(${this.length}) ${util.inspect(array, options)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters