Skip to content

Commit

Permalink
✨ ii() utility
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Dec 10, 2024
1 parent 0611981 commit 7c47180
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// main
export { default as ii } from "./src/inspect/ii";

// core
export { default as consolePrint } from "./src/core/consolePrint";
export { consoleText } from "./src/core/consoleText";
Expand Down
36 changes: 36 additions & 0 deletions src/inspect/ii.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import consolePrint from "../core/consolePrint";
import type ConsoleSpan from "../core/ConsoleSpan";
import { consoleText } from "../core/consoleText";
import consoleInspect from "./consoleInspect";

export default function ii<T>(value: T, ...args: unknown[]): T;
export default function ii(...args: unknown[]): unknown {
if (args.length === 0) {
return undefined;
}

if (hasWebContext()) {
const spans: ConsoleSpan[] = [];
let first = true;
for (const value of args) {
if (!first) {
first = false;
spans.push(consoleText(" "));
}
spans.push(
...consoleInspect(value, {
print: false,
}),
);
}
consolePrint(spans);
} else {
console.log(...args);
}

return args[0];
}

function hasWebContext(): boolean {
return typeof window !== "undefined";
}

0 comments on commit 7c47180

Please sign in to comment.