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 →
39 /100 Needs Attention
Development Activity 0
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
93%
Apache 2.0

Openship

Devops · Hosting Control Panel

14,912

Openship is an open-source, self-hostable deployment platform that points at a repo and builds, ships, routes, and TLS-terminates the app — driven from a desktop app, web dashboard, or CLI.

View details
84
Repo Health
85
Technical
65
Dependency
Built with
TypeScript 93%
Updated 5 days ago
TypeScript
98%
MIT

Promptfoo

AI Development

26,358

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
67
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
64%
AGPL 3.0

Puter

Developer Tools · File Storage

43,864

A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.

View details
88
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 64%
JavaScript 33%
Updated 5 days ago
Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,326

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
87
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 5 days ago
TypeScript
61%
AGPL 3.0

Silex

Design Tools · No Code Platforms

3,015

Free, open-source visual website builder that exports clean HTML/CSS — no lock-in, no subscription, host anywhere

View details
89
Repo Health
68
Technical
67
Dependency
Built with
TypeScript 61%
Rust 15%
JavaScript 11%
Updated 6 days ago
Python
100%
Other

Sourcebot

AI Code Assistants · Developer Tools · Search

4,005

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
86
Repo Health
83
Technical
61
Dependency
Built with
Python 100%
Updated 1 weeks ago
TypeScript
48%
MIT

supermemory

AI Development · AI Memory · Note Taking

31,370

The state-of-the-art memory and context engine for AI agents — ranked #1 on all three major AI memory benchmarks.

View details
88
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 48%
MDX 32%
Python 17%
Updated 5 days ago
JavaScript
93%
Apache 2.0

swagger-ui

Developer Tools

29,042

Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.

View details
98
Repo Health
83
Technical
62
Dependency
Built with
JavaScript 93%
Updated 6 days ago
Rust
93%
Other

Tabby

AI Code Assistants

33,924

Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.

View details
55
Repo Health
78
Technical
61
Dependency
Built with
Rust 93%
Updated 4 months 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