dedent
A tiny ES6 string tag that strips indentation from multi-line template strings.
Repository Health
Technical Analysis
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 (dedent
text) 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, andtrimWhitespace - Escape-sequence unescaping (\n, \t, \xHH, \u{…}, etc.) applied after dedenting so literal escapes in source survive the transform
- An optional
dedent/macroentry 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
Openship
Devops · Hosting Control Panel
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.
Promptfoo
AI Development
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.
Puter
Developer Tools · File Storage
A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.
Rivet
AI Agents · Developer Tools
Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.
Silex
Design Tools · No Code Platforms
Free, open-source visual website builder that exports clean HTML/CSS — no lock-in, no subscription, host anywhere
Sourcebot
AI Code Assistants · Developer Tools · Search
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.
supermemory
AI Development · AI Memory · Note Taking
The state-of-the-art memory and context engine for AI agents — ranked #1 on all three major AI memory benchmarks.
swagger-ui
Developer Tools
Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.
Tabby
AI Code Assistants
Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.