Skip to content

Tersible

type Tersible<T = unknown> = T & {
tersify(this: T, options?: Partial<TersifyOptions>): string
}

Tersible<T> is T plus a tersify() method. Any value of this shape controls its own output: tersify() calls the method instead of applying the default rules, unless raw: true is set.

The method receives the options the caller passed, so an implementation can honour maxLength. Nothing enforces the cap on the value you return.

class Point {
constructor(
public x: number,
public y: number
) {}
tersify() {
return `Point(${this.x}, ${this.y})`
}
}
import type { Tersible } from 'tersify'
function log(value: Tersible) {
console.info(value.tersify({ maxLength: 80 }))
}

Tersible defaults its parameter to unknown, so the bare form accepts any self-formatting value.

See Custom output for the guide.