Skip to content

Installation

Terminal window
npm install tersify
Terminal window
pnpm add tersify
Terminal window
yarn add tersify

tersify ships as both ESM and CommonJS, with type declarations for each, so either module system works without a shim.

import { tersify } from 'tersify'
const { tersify } = require('tersify')

The package publishes a browser field that swaps two modules at bundle time:

Module Node build Browser build
constants constants.ts constants.browser.ts
tersifyFunction tersifyFunction.ts tersifyFunction.browser.ts

The Node build parses function source with acorn to produce the most compact representation it can. The browser build drops acorn entirely and falls back to string-based formatting, which keeps the bundle small. Any bundler that honours the browser field — Vite, webpack, esbuild, Rollup with @rollup/plugin-node-resolve — picks the right one for you.

Function output can therefore differ slightly between the two builds. Everything else — objects, arrays, primitives, class instances, options — behaves identically.