A curated drawer of JavaScript string and text-processing utilities, grouped by the job they do.

Fuzzy matching & similarity

ResourceWhy it is useful
fuzzyset.jsFuzzy match typos against a known set of strings.
string-similarity-jsDice-coefficient similarity score between two strings.
string-similarityCompare similarity and find best matches in a list.

Search & match

ResourceWhy it is useful
nlp-pattern-matchPattern-based find and replace over natural language.
sql-string-searchSearch for SQL-like queries in code via AST.
js-searchClient-side full-text search over a collection of objects.

Search & replace

ResourceWhy it is useful
easy-replaceReplace strings without writing regexes.
string-apostrophesHTML-entities-aware tool to typographically correct apostrophes and single/double quotes.

Diffing

ResourceWhy it is useful
striffVery simple string diffing.

Casing

ResourceWhy it is useful
case-anythingConvert between camelCase, kebab-case, snake_case, and more.

Formatting & wrapping

ResourceWhy it is useful
wordwrapjsWord-wrap text to a given width.
splitTitleSplit titles into balanced lines for nicer wrapping.
commafy-anythingAdd thousands separators to any number string.
node-ts-dedentStrip leading indentation from template literals.
common-tagsMany template tags for formatting interpolated strings.

Unicode & emoji

ResourceWhy it is useful
unistringUnicode-aware emoji and text utilities.
emoji-regexRegex that matches all emoji as defined by Unicode.

Validation

ResourceWhy it is useful
allowed-charactersCheck if a string only contains an allowed character set.

Hashing

ResourceWhy it is useful
djb2aFast non-cryptographic hash function.

Splitting

A small escape-aware split helper that ignores separators prefixed with \\ (used by get/set/has utilities):

/**
 * Splits a string with the given separator, unless the separator
 * is escaped with `\\`. Used by the get, set, has, and hasOwn utils.
 * @param {String} str The string to split.
 * @param {String} sep Separator, `.` by default.
 * @return {Array}
 */
const split = exports.split = (str, sep = '.') => {
  let segs = str.split(sep)
  for (let i = 0; i < segs.length; i++) {
    while (segs[i] && segs[i].slice(-1) === '\\') {
      segs[i] = segs[i].slice(0, -1) + sep + segs.splice(i + 1, 1)
    }
  }
  return segs
}