# tersify

> Creates a terse representation of code

Latest version **4.0.7** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install tersify
pnpm add tersify
yarn add tersify
bun add tersify
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.7 |
| Published | 2026-09-07 |
| First published | 2017-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 359.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 8 |
| Author | Homa Wong |
| Maintainers | unional |

## Links

- npm: https://www.npmjs.com/package/tersify
- Repository: https://github.com/cyberuni/tersify
- Homepage: https://github.com/cyberuni/tersify/tree/main/packages/tersify
- Issues: https://github.com/cyberuni/tersify/issues
- npm.io page: https://npm.io/package/tersify

## Dependencies (2)

- [acorn](https://npm.io/package/acorn.md) ^8.18.0
- [unpartial](https://npm.io/package/unpartial.md) ^1.0.7

## Recent versions

- 4.0.7 (latest) — 2026-09-07
- 4.0.6 — 2026-09-01
- 4.0.5 — 2026-09-01
- 4.0.4 — 2026-09-01
- 4.0.3 — 2026-08-31
- 4.0.2 — 2026-08-24
- 4.0.1 — 2026-05-24
- 4.0.0 — 2026-02-17
- 3.12.1 — 2023-02-12
- 3.12.0 — 2023-02-12
- 3.11.1 — 2022-12-05
- 3.11.0 — 2022-12-03
- 3.10.5 — 2022-09-14
- 3.10.2 — 2022-06-11
- 3.10.1 — 2022-06-10
- … 55 more at https://npm.io/package/tersify/versions

## README

# tersify

[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]

[![GitHub NodeJS][github-nodejs]][github-action-url]
[![Codecov][codecov-image]][codecov-url]

[![Changesets][changesets-image]][changesets-url]

[![Visual Studio Code][vscode-image]][vscode-url]

Create a readable terse representation of the subject.

You can specify `maxLength` to further trim the resulting string.

You can also override the result by providing your own `tersify()` function on the subject.

```ts
import { tersify } from 'tersify'

// `() => 'foo'`
tersify(() => { return 'foo' })

// `fn(x, y) { return x + y; }`
tersify(function (x, y) { return x + y })

// `fn foo(y) { return y++; }`
tersify(function foo(y) { return y++ })

// Change result to 80 character long.
// result will have `...` to indicate info missing.
// e.g. `{ a: 'a', ... }`
tersify({...}, { maxLength: 80 })

// '{ a: 1 }`
tersify({ a: 1 })

// `() => Sym(abc)`
tersify(() => { return Symbol.for(abc) })
```

## `tersible`

Inject a `tersify()` function to the subject.

```ts
import { tersible } from 'tersify'

const increment = tersible(
	a => a + 1,
	() => 'a++'
)
increment.tersify() // 'a++'

// `{ a: 1 }`
tersible({ a: 1 }, function () {
	return `{ a: ${this.a} }`
}).tersify()

const decrement = tersible(a => a--, 'a--')
decrement.tersify() // 'a--'

// `a: 10`
tersible({ a: 1 }, options => `a: ${options.maxLength}`).tersify({ maxLength: 10 })
```

## `Tersiblized`

Mixin `Tersible` to a class.

```ts
import { Tersiblized } from 'tersify'

class Foo {
	a = 1
}
class Boo extends Tersiblized(Foo, function () {
	return `{ a: ${this.a} }`
}) {}

const boo = new Boo()
boo.a = 3
boo.tersify() // '{ a: 3 }'
```

[changesets-image]: https://img.shields.io/badge/maintained%20with-changesets-176de3.svg
[changesets-url]: https://github.com/changesets/changesets
[codecov-image]: https://codecov.io/gh/cyberuni/tersify/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/cyberuni/tersify
[downloads-image]: https://img.shields.io/npm/dm/tersify.svg?style=flat
[downloads-url]: https://npmjs.org/package/tersify
[github-nodejs]: https://github.com/cyberuni/tersify/actions/workflows/release.yml/badge.svg
[github-action-url]: https://github.com/cyberuni/tersify/actions
[npm-image]: https://img.shields.io/npm/v/tersify.svg?style=flat
[npm-url]: https://npmjs.org/package/tersify
[vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
[vscode-url]: https://code.visualstudio.com/

---
_Source: https://npm.io/package/tersify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
