Skip to content

Commit

Permalink
refactor: rename ConsoleOptions to InspectOptions (denoland#4493)
Browse files Browse the repository at this point in the history
  • Loading branch information
cknight authored Mar 26, 2020
1 parent fd432e2 commit a053462
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
43 changes: 35 additions & 8 deletions cli/js/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ declare namespace Deno {
*/
export function loadavg(): number[];

/** Get the `hostname`. Requires `allow-env` permission.
/** Get the `hostname` of the machine the Deno process is running on.
*
* console.log(Deno.hostname());
*
* Requires `allow-env` permission.
*/
export function hostname(): string;

Expand Down Expand Up @@ -2021,20 +2023,45 @@ declare namespace Deno {
* Signals numbers. This is platform dependent. */
export const Signal: typeof MacOSSignal | typeof LinuxSignal;

/** **UNSTABLE**: rename to `InspectOptions`. */
interface ConsoleOptions {
interface InspectOptions {
showHidden?: boolean;
depth?: number;
colors?: boolean;
indentLevel?: number;
}

/** **UNSTABLE**: `ConsoleOptions` rename to `InspectOptions`. Also the exact
* form of string output subject to change.
/** **UNSTABLE**: The exact form of the string output is under consideration
* and may change.
*
* Converts the input into a string that has the same format as printed by
* `console.log()`.
*
* const obj = {};
* obj.propA = 10;
* obj.propB = "hello"
* const objAsString = Deno.inspect(obj); //{ propA: 10, propB: "hello" }
* console.log(obj); //prints same value as objAsString, e.g. { propA: 10, propB: "hello" }
*
* You can also register custom inspect functions, via the `customInspect` Deno
* symbol on objects, to control and customize the output.
*
* class A {
* x = 10;
* y = "hello";
* [Deno.symbols.customInspect](): string {
* return "x=" + this.x + ", y=" + this.y;
* }
* }
*
* const inStringFormat = Deno.inspect(new A()); //"x=10, y=hello"
* console.log(inStringFormat); //prints "x=10, y=hello"
*
* Finally, a number of output options are also available.
*
* Converts input into string that has the same format as printed by
* `console.log()`. */
export function inspect(value: unknown, options?: ConsoleOptions): string;
* const out = Deno.inspect(obj, {showHidden: true, depth: 4, colors: true, indentLevel: 2});
*
*/
export function inspect(value: unknown, options?: InspectOptions): string;

export type OperatingSystem = "mac" | "win" | "linux";

Expand Down
4 changes: 2 additions & 2 deletions cli/js/lib.deno.shared_globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ declare namespace __blob {
}

declare namespace __console {
type ConsoleOptions = Partial<{
type InspectOptions = Partial<{
showHidden: boolean;
depth: number;
colors: boolean;
Expand Down Expand Up @@ -970,7 +970,7 @@ declare namespace __console {
* `inspect()` converts input into string that has the same format
* as printed by `console.log(...)`;
*/
export function inspect(value: unknown, options?: ConsoleOptions): string;
export function inspect(value: unknown, options?: InspectOptions): string;
}

declare namespace __event {
Expand Down
8 changes: 4 additions & 4 deletions cli/js/web/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { cliTable } from "./console_table.ts";
import { exposeForTest } from "../internals.ts";

type ConsoleContext = Set<unknown>;
type ConsoleOptions = Partial<{
type InspectOptions = Partial<{
showHidden: boolean;
depth: number;
colors: boolean;
Expand Down Expand Up @@ -383,7 +383,7 @@ function createObjectString(

export function stringifyArgs(
args: unknown[],
{ depth = DEFAULT_MAX_DEPTH, indentLevel = 0 }: ConsoleOptions = {}
{ depth = DEFAULT_MAX_DEPTH, indentLevel = 0 }: InspectOptions = {}
): string {
const first = args[0];
let a = 0;
Expand Down Expand Up @@ -522,7 +522,7 @@ export class Console {
debug = this.log;
info = this.log;

dir = (obj: unknown, options: ConsoleOptions = {}): void => {
dir = (obj: unknown, options: InspectOptions = {}): void => {
this.printFunc(stringifyArgs([obj], options) + "\n", false);
};

Expand Down Expand Up @@ -749,7 +749,7 @@ export const customInspect = Symbol.for("Deno.customInspect");

export function inspect(
value: unknown,
{ depth = DEFAULT_MAX_DEPTH }: ConsoleOptions = {}
{ depth = DEFAULT_MAX_DEPTH }: InspectOptions = {}
): string {
if (typeof value === "string") {
return value;
Expand Down

0 comments on commit a053462

Please sign in to comment.