dedent

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

Library
npm
v1.7.2
1,190stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
40/100Fair
Development Activity4
Maintenance20
Community48
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture75
Code Quality82
Innovation85
Learning Curve92

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,872

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
95
Repo Health
82
Technical
66
Dependency
Built with
TypeScript100%
Updated yesterday
Rust
67%
MIT

Bun

Developer Tools

95,452

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
66
Dependency
Built with
Rust67%
C++19%
Updated today
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,761

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
67
Dependency
Built with
TypeScript75%
Updated today
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,957

The superpowered headless CMS for developers built with GraphQL and React

View details
91
Repo Health
81
Technical
64
Dependency
Built with
TypeScript99%
Updated yesterday
TypeScript
97%
Other

Kibana

Analytics · Monitoring

21,251

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
68
Dependency
Built with
TypeScript97%
Updated today
TypeScript
80%
MIT

LibreChat

Developer Tools · AI Assistants

42,216

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
68
Dependency
Built with
TypeScript80%
JavaScript19%
Updated today
TypeScript
100%
MIT

Llama Coder

AI Development · Low Code Platforms

7,115

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
73
Dependency
Built with
TypeScript100%
Updated 5 days ago
TypeScript
89%
MIT

open-pencil

AI Design Tools · Design Tools

7,864

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
80
Repo Health
78
Technical
70
Dependency
Built with
TypeScript89%
Updated today
HTML
32%

OpenPanel

Hosting Control Panel · Devops

733

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
81
Repo Health
75
Technical
63
Dependency
Built with
HTML32%
Go31%
TypeScript28%
Updated today

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

Search