On this page
@std/text
Overview Jump to heading
Utility functions for working with text.
import { toCamelCase, compareSimilarity } from "@std/text"; import { assertEquals } from "@std/assert"; assertEquals(toCamelCase("snake_case"), "snakeCase"); const words = ["hi", "help", "hello"]; // Words most similar to "hep" will be at the front assertEquals(words.sort(compareSimilarity("hep")), ["help", "hi", "hello"]);
Add to your project Jump to heading
deno add jsr:@std/text
See all symbols in @std/text on
Why use @std/text? Jump to heading
Reach for it when you need reliable, well-tested text manipulation utilities such as case conversions, string similarity, and common text ops.
Examples Jump to heading
import { compareSimilarity, toKebabCase } from "@std/text"; console.log(toKebabCase("HelloWorld")); const candidates = ["install", "init", "info"]; console.log(candidates.sort(compareSimilarity("in")));
Find the closest suggestion Jump to heading
import { closestString } from "@std/text/closest-string"; const options = ["length", "size", "help"]; console.log(closestString("hep", options)); // "help"
Compute edit distance Jump to heading
import { levenshteinDistance } from "@std/text"; console.log(levenshteinDistance("kitten", "sitting")); // 3
Sort a list by similarity Jump to heading
import { wordSimilaritySort } from "@std/text"; const cmds = ["install", "init", "info", "inspect"]; console.log(wordSimilaritySort("in", cmds)); // e.g., ["init", "info", "install", "inspect"]
Dedent a multiline string (unstable) Jump to heading
import { dedent } from "@std/text/unstable-dedent"; const msg = dedent` Line one Line two Line three `; console.log(msg); // "Line one\n Line two\nLine three\n"
Unicode-aware reverse (unstable) Jump to heading
import { reverse } from "@std/text/unstable-reverse"; console.log(reverse("mañana")); // "anañam" // Preserve grapheme clusters like emoji sequences console.log(reverse("👩❤️💋👨", { handleUnicode: true }));
Tips Jump to heading
- Use similarity comparisons for CLI fuzzy matching and suggestions.
- Prefer these utils over ad-hoc regex when readability matters.
- Use
closestString()
when you need one best suggestion; usewordSimilaritySort()
to rank many. - Some utilities are marked unstable; import them via
@std/text/unstable-*
and expect potential API changes.