@ende/text

ende add jsr:@ende/text

Version 2026.10.15 on JSR.

Utility functions for working with text.

import { toCamelCase, compareSimilarity } from "@ende/text";
import { assertEquals } from "@ende/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"]);

Modules

Exports

  • closestString — Finds the most similar string from an array of strings.
  • ClosestStringOptions — Options for closestString.
  • compareSimilarity — Takes a string and generates a comparator function to determine which of two strings is more similar to the given one.
  • CompareSimilarityOptions — Options for compareSimilarity.
  • levenshteinDistance — Calculates the Levenshtein distance between two strings.
  • toCamelCase — Converts a string into camelCase.
  • toKebabCase — Converts a string into kebab-case.
  • toPascalCase — Converts a string into PascalCase.
  • toSnakeCase — Converts a string into snake_case.
  • truncate — Truncates a string to at most `maxLength` UTF-16 code units. When truncation occurs the suffix is included within the `maxLength` budget. Surrogate pairs are never split, so the result may be shorter than `maxLength` when a cut would land inside a pair. When the suffix itself contains surrogate pairs and `maxLength` is very small, the result can even be empty.
  • TruncateOptions — Options for truncate.
  • wordSimilaritySort — Sorts a string-array by similarity to a given string.
  • WordSimilaritySortOptions — Options for wordSimilaritySort.