dedent

import { dedent } from "jsr:@ende/text/unstable-dedent";

function · experimental

function dedent(input: string): string

Removes indentation from multiline strings.

  • Removes leading newline
  • Removes a single trailing newline (with any preceding whitespace on that line)
  • Replaces whitespace-only lines with empty lines
  • Finds the minimum indentation among remaining lines and removes that much indentation from all of them
input: string

The string to remove indentation from.

Returns

The string without indentation.

Example: Usage

import { dedent } from "@ende/text/unstable-dedent";
import { assertEquals } from "@ende/assert";

assertEquals(
  dedent(`
    {
      msg: "Hello",
    }
  `),
  `{\n  msg: "Hello",\n}`
);

function · experimental

function dedent(input: TemplateStringsArray, ...values: unknown[]): string

Removes indentation from multiline strings.

  • Removes leading newline
  • Removes a single trailing newline (with any preceding whitespace on that line)
  • Replaces whitespace-only lines with empty lines
  • Finds the minimum indentation among remaining lines and removes that much indentation from all of them
input: TemplateStringsArray

The template to remove indentation from.

...values: unknown[]

The template substitution values.

Returns

The string without indentation.

Example: Usage

import { dedent } from "@ende/text/unstable-dedent";
import { assertEquals } from "@ende/assert";

assertEquals(
  dedent`line 1
         line 2`,
  "line 1\nline 2"
);

function · experimental

function dedent(input: TemplateStringsArray | string, ...values: unknown[]): string

Source