dedent

A tiny ES6 string tag that strips indentation from multi-line template strings.

Library
npm
v1.7.2
1,191 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
40 /100 Fair
Development Activity 4
Maintenance 20
Community 48
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
84 /100 Excellent
Architecture 75
Code Quality 82
Innovation 85
Learning Curve 92

dedent is a small, dependency-free TypeScript library that removes leading indentation from multi-line JavaScript template literals. It can be used either as a template tag (dedent...) or as a plain function call (dedent(str)), and finds the minimum common indentation across all lines before stripping it, so source code can stay nicely indented without that indentation leaking into the resulting string.

Beyond the default behavior, dedent exposes a .withOptions() API for controlling how multi-line interpolated values are re-aligned, whether special characters are escaped, and whether surrounding whitespace is trimmed. An optional dedent/macro entry point integrates with babel-plugin-macros to evaluate the tag entirely at build time, eliminating any runtime cost for projects using Babel.

What You Get

  • A default export usable as both a template tag (dedenttext) and a plain function (dedent(text))
  • A .withOptions() method for creating reusable, preconfigured dedent variants
  • Options for alignValues (re-indenting multi-line interpolated values), escapeSpecialCharacters, and trimWhitespace
  • Escape-sequence unescaping (\n, \t, \xHH, \u{…}, etc.) applied after dedenting so literal escapes in source survive the transform
  • An optional dedent/macro entry point for babel-plugin-macros that evaluates the tag at build time with zero runtime cost
  • Dual CJS/ESM builds with full TypeScript type declarations for both module formats

Common Use Cases

  • Writing readable multi-line error messages, CLI help text, or log output inside indented code blocks
  • Generating SQL, GraphQL, or shell command strings from indented template literals without leaking whitespace
  • Producing fixture or snapshot-test strings that need to match exactly, independent of surrounding source indentation
  • Composing multi-line prompts or templates for LLM calls where extra leading whitespace would alter output

Under The Hood

Architecture dedent is implemented as a single ~140-line TypeScript module (src/dedent.ts) built around a createDedent(options) factory that closes over the current option set and attaches a .withOptions() method to the returned tag function, so calling .withOptions() produces a new independently configured tagger rather than mutating shared state. The core dedent() function normalizes both call styles (tagged template with a raw strings array, or a single plain string argument) into a common code path, then runs a sequential pipeline: interpolate values (optionally realigning multi-line interpolations via a separate alignValue helper that inspects the current line’s indentation), split on newlines and compute the minimum indentation across all indented lines, strip that indentation from every line, optionally trim leading/trailing whitespace, and finally unescape backslash sequences that were preserved through the escaping pass. A parallel macro.js file integrates with babel-plugin-macros, walking tagged-template and call-expression AST nodes and replacing them with a precomputed string literal at build time.

Tech Stack The library is written in strict TypeScript with no runtime dependencies. It ships dual builds — a legacy CJS bundle and a modern ESM bundle — produced via two separate Babel invocations (build:legacy / build:modern), with .d.ts/.d.mts type declarations generated separately by tsup. The package.json exports map routes require() and import consumers to the correct build and type file. babel-plugin-macros is an optional peer dependency used only by the opt-in macro entry point. Testing runs on Jest, with an additional Bun-specific test target (test:bun) that exercises a Unicode-handling workaround for a known Bun runtime issue.

Code Quality The test suite (src/dedent.test.ts, 363 lines, plus a 66-line macro test file) covers both call styles, all three options, escape-sequence round-tripping, and macro evaluation, backed by Jest snapshot fixtures. The project layers on an unusually strict lint pipeline: ESLint with --max-warnings 0 across typescript-eslint, jsdoc, regexp, and perfectionist plugins, plus markdownlint, cspell spell-checking, and npm-package-json-lint — all wired into pre-commit hooks via husky and lint-staged. Naming is short and consistent throughout (dedent, mindent, alignValue), and the few lint-suppression comments in the source are narrowly scoped and explained inline.

Used by 18 apps in this directory

TypeScript
100%
MIT

Botpress

AI Assistants · AI Development · Customer Support

14,924

The open-source hub for building and deploying LLM-powered AI agents with TypeScript-first tooling, 40+ integrations, and a revolutionary code-execution agent framework.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 100%
Updated 1 weeks ago
Rust
67%
MIT

Bun

Developer Tools

96,068

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust 67%
C++ 19%
TypeScript 10%
Updated 6 days ago
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,787

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 75%
Updated 5 days ago
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,982

The superpowered headless CMS for developers built with GraphQL and React

View details
92
Repo Health
81
Technical
64
Dependency
Built with
TypeScript 99%
Updated 5 days ago
TypeScript
98%
Other

Kibana

Analytics · Monitoring

21,301

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
82%
MIT

LibreChat

AI Assistants · Developer Tools

45,009

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 82%
JavaScript 17%
Updated 5 days ago
TypeScript
100%
MIT

Llama Coder

AI Development · Low Code Platforms

7,135

Generate multi-file web apps from a single prompt using open-source LLMs — an open-source alternative to Claude Artifacts.

View details
71
Repo Health
66
Technical
69
Dependency
Built with
TypeScript 100%
Updated 2 weeks ago
TypeScript
90%
MIT

open-pencil

AI Design Tools · Design Tools

8,642

An open-source design editor that reads native Figma files, ships a built-in AI assistant with 100+ design tools, and offers real-time serverless collaboration — all without giving up your files.

View details
81
Repo Health
78
Technical
69
Dependency
Built with
TypeScript 90%
Updated 1 weeks ago
HTML
36%

OpenPanel

Devops · Hosting Control Panel

749

Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.

View details
84
Repo Health
75
Technical
63
Dependency
Built with
HTML 36%
Go 32%
TypeScript 23%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers