Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

console-powers

> 编程语言
Open source

New way to debug & inspect in the browser. Ditch console.log.

783 stars0 likes0 views
WebsiteGitHub

About

New way to debug & inspect in the browser. Ditch console.log.

console-powers

New way to debug & inspect in the browser. Ditch console.log.

Install

bash
npm install console-powers

Why

  • Quicker debugging for large objects. Have you spent time clicking on the expand button in DevTools every time you console.log() a big object, or have you spent time doing data drilling so it's easier to see? With ii() and it's depth and keys options you can see an entire object with only the keys you want.
  • Better table printing. connsole.table() always displays (index) column that adds clutter. Also, console.table() doesn't support displaying nested objects in the table cell making it's use limited.
  • Write less, use inline. You can sneak in ii() — return ii(data) — and it will print and return the value so you don't need to make a separate variable, print the value, and then return it. Also, if your don't have a shorthand for console.log, writing ii is faster.
  • And many more. Better date/time printing, more readable Map printing, adaptive string trimming, and many more improvements over default logging methods.

Usage

The library can be mentally split in two: 1) ii() that aims to replace console.log + tt() that aims to replace console.table, 2) the core API that allows doing advanced printing in the browser console. This is a getting started for 1). For 2) see API section.

  1. Add ii and tt to the global scope so you can use it anywhere without importing it – just like console.log:
    typescript
    import { addToGlobalScope, addNoopToGlobalScope } from 'console-powers/global'
    
    if (import.meta.env.DEV) {
        addToGlobalScope()
        ii.defaults.depth = 8 // if you like, change the default options
    } else {
        addNoopToGlobalScope()
    }
  2. Use anywhere instead of console.log and console.table:
    typescript
    // use inline — ii() returns the first arg you pass to it
    const markdownTree = ii(await worker.parseMarkdownTree())

Examples

Inspect

typescript
import { ii } from "console-powers";

// inspect-inspect
ii({
    type: "group",
    priority: 1,
    items: [{ type: "new" }, { type: "delimiter" }, { type: "value" }],
    location: {
        start: {
            line: 1,
            column: 0,
        },
        end: {
            line: 4,
            column: 10,
        },
    },
});

Tables

typescript
import { tt } from "console-powers";

// table-table
tt([
    {
        model: 'MacBook Air 13"',
        year: new Date(2020, 10, 23),
        price: 999,
    },
    {
        model: 'MacBook Air 15"',
        year: new Date(2023, 9, 18),
        price: 1299,
    },
    {
        model: 'MacBook Pro 13"',
        year: new Date(2019, 11, 2),
        price: 1499,
    },
])

Styling

…

API

ii()

ii() (inspect-inspect) is an all-in-one utility function encompassing the entire library. It's the easiest and recommended way to use the library. You can start using ii() instead of console.log(). It uses consoleInspect() under the hood.

ii(value: T, ...args: any[]): T

Tip: Use ii() inside expressions – it returns the first argument your pass to it:

typescript
function getData() {
    // ii() will return the first parameter, instead of needing to create a variable for it
    return ii(data)
}
ii.defaults

Type: ConsoleInspectOptions

The default options passed to consoleInspect(). Expand consoleInspect docs for list of all options and what they do.

ii.depth(depth: number): InspectInspect

Alias: ii.d(depth: number): InspectInspect

Changes how many levels of a nested object are expanded by default. Returns itself to allow chaining:

typescript
ii.depth(6)(nestedObject)
ii.keys(...keys: string[]): InspectInspect

Alias: ii.k(...keys: string[]): InspectInspect

Whitelist keys to include in the log. For nested object, keys work per level — at particular level of nesting if no key matches any of the keys the whole level is shown. For nested object, showing a key also shows its children. Returns itself to allow chaining:

typescript
ii.keys('start', 'end', 'type')({
    type: 'paragraph',
    start: 0,
    end: 10,
    nodes: [{
        ...
    }]
})
ii.pre(value: unknown): unknown

Allows you to manipulate the value before printing it. For example, in Solid.js Signals are functions with no parameters and you can ensure it always prints the value and not the Signal itself:

typescript
ii.pre = (value: unknown): unknown => {
    // is it a Solid.js Signal?
    return typeof value === 'function' && value.length === 0
        ? value()
        : value
}

tt()

tt() (table-table) aims to replace console.table() by providing extra features and cleaner design. It uses consoleTable() under the hood.

tt(value: T, ...args: any[]): T

Tip: Use tt() inside expressions – it returns the first argument your pass to it:

typescript
function getData() {
    // tt() will return the first parameter, instead of needing to create a variable for it
    return tt(data)
}
tt.defaults

Type: ConsoleTableOptions

The default options passed to consoleTable(). Expand consoleTable docs for list of all options and what they do.

tt.pre(value: unknown): unknown

Allows you to manipulate the value before printing it. For example, in Solid.js Signals are functions with no parameters and you can ensure it always prints the value and not the Signal itself:

typescript
tt.pre = (value: unknown): unknown => {
    // is it a Solid.js Signal?
    return typeof value === 'function' && value.length === 0
        ? value()
        : value
}

console-powers/global

addToGlobalScope()

Imported from console-powers/global. It adds ii and tt and it's TypeScript types to the global scope so you can use it anywhere without importing it – just like console.log.

addNoopToGlobalScope()

Imported from console-powers/global. It adds empty/noop functions for ii and tt so if you accidentally forget a ii or tt call during development it won't crash in production.

consoleInspect()

consoleInspect(values: any[], options?: ConsoleInspectOptions): ConsoleSpan[]

ConsoleInspectOptions.depth

Type: number
Default: 2

For nested objects, how many levels are expanded by default. Levels after that will be collapsed.

ConsoleInspectOptions.keys

Type: string[] Default: undefined

Whitelist keys to include in the log. For nested object, keys work per level — at particular level of nesting if no key matches any of the keys the whole level is shown. For nested object, showing a key also shows its children.

ConsoleInspectOptions.wrap

Type: "auto" | "single-line" | "multi-line" | number
Default: "auto"

Configure when the algorithm puts things on new lines:

  • "auto" — tries to guess the available space and wraps based on it.
  • "single-line" — never wraps on new lines, the entire output is a single line.
  • "multi-line" — always starts a new line when dwelling into a new object/array.
  • number — set the maximum number of characters per line before it wraps to the next line.
ConsoleInspectOptions.indent

Type: number
Default: 4

How much spaces to add when going down a level.

ConsoleInspectOptions.theme

Type: 'light' | 'dark'
Default: automatically determined based on the system theme.

Determines the colors that will be used to style the output.

ConsoleInspectOptions.print

Type: boolean
Default: true

If set to false, the method won't print to the console. In this case, you probably want to get the return value of the method and use it.

consoleTable()

Great for debugging. Especially great when you have an array of objects that aren't deeply nested.

consoleTable(value: any, options: ConsoleTableOptions): ConsoleSpan[]

ConsoleTableOptions.wrap

Type: "auto" | number
Default: "auto"

ConsoleTableOptions.theme

Type: 'light' | 'dark'
Default: automatically determined based on the system theme.

Determines the colors that will be used to style the output.

ConsoleTableOptions.print

Type: boolean
Default: true

If set to false, the method won't print to the console. In this case, you probably want to get the return value of the method and use it.

API (core)

consolePrint(spans: ConsoleSpan[]): void

Prints the provided spans to the console.

consoleText(text: string, style?: ConsoleStyle): ConsoleSpan

Creates a styled text span.

consoleObject(object: object): ConsoleSpan

An object, class, HTML element. It shows a preview of the object and an option to expand it to see it's properties. The same thing as console.dirxml(object).

consoleApply(spans: ConsoleSpan | ConsoleSpan[], style: ConsoleStyle): ConsoleSpan[]

Apply additional styles to all provided spans.

consoleGroup(options: ConsoleGroupOptions): ConsoleSpan

It creates a group using console.group() or console.groupCollapsed() with the provided header and body.

typescript
consolePrint(
    consoleGroup({
        expanded: false, // default "false"
        header: "Expand me",
        body: "Here I am",
    }),
);

Note: The method calls consoleFlush() and flushes everything up until now before starting a new group.

consoleFlush(): ConsoleSpan

Calls console.log() on all spans provided before it. Internally, consolePrint() uses consoleFlush() at the end.

typescript
consolePrint(
    consoleText('take a look at'),
    consoleObject(object),
    consoleFlush(),
    consoleText('this is a new line and a new console.log() statement')
)

ConsoleStyle

  • background and its longhand equivalents
  • border and its longhand equivalents
  • border-radius
  • box-decoration-break
  • box-shadow
  • clear and float
  • color
  • display
  • font and its longhand equivalents
  • line-height
  • margin
  • outline and its longhand equivalents
  • padding
  • text-* properties such as text-transform
  • white-space
  • word-spacing and word-break
  • writing-mode

Issues· 1 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言