Introducing strfi: The Ultimate String Utility Library for JavaScript & TypeScript

Published: (January 4, 2026 at 03:40 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Introduction

Hey dev.to community! 👋

I’m thrilled to announce strfi – a comprehensive, zero‑dependency, tree‑shakeable collection of over 150 pure string utilities for modern JavaScript and TypeScript projects.

If you’re tired of pulling in heavy libraries for simple string tasks like slugifying text, escaping HTML, calculating edit distance, or formatting bytes, strfi is here to be your lightweight yet powerful string toolkit.

  • Zero runtime dependencies
  • Fully tree‑shakeable – import only the functions you need
  • Excellent TypeScript support with precise types
  • Unicode‑aware and locale‑sensitive where applicable
  • No unsafe practices (no eval(), etc.)
  • Tiny minified bundle: ~22 KB
  • Works everywhere: Node.js 16+, modern browsers, Deno, Bun, React Native, Cloudflare Workers

Installation

npm install strfi

Or with Yarn / pnpm:

yarn add strfi
# or
pnpm add strfi

Usage Example

import {
  slugify,
  escapeHtml,
  capitalize,
  levenshteinDistance,
  formatBytes,
  camelCase,
  truncate,
  isEmail,
} from 'strfi';

console.log(slugify('Hello World! 🚀'));                     // "hello-world"
console.log(escapeHtml('alert("xss")'));                     // "<script>alert("xss")</script>"
console.log(capitalize('javascript'));                     // "Javascript"
console.log(levenshteinDistance('kitten', 'sitting'));     // 3
console.log(formatBytes(1500000));                         // "1.43 MB"
console.log(camelCase('foo-bar_baz'));                     // "fooBarBaz"
console.log(truncate('Very long text here', { length: 10 })); // "Very lo..."
console.log(isEmail('test@example.com'));                  // true

All Features – Grouped by Category

Case Transformations

  • toUpperCase, toLowerCase, capitalize, uncapitalize, titleCase, camelCase, pascalCase, snakeCase, kebabCase, constantCase, dotCase, pathCase, sentenceCase, swapCase
  • isUpperCase, isLowerCase, isTitleCase

Whitespace Operations

  • trim, trimStart, trimEnd, trimChars, trimCharsStart, trimCharsEnd
  • collapseWhitespace, removeWhitespace, padStart, padEnd, center, repeat, insert, removeAt, indent, dedent

String Manipulation

  • reverse, truncate, truncateMiddle, wordWrap, slugify, between, betweenAll, remove, replaceFirst, replaceLast, replaceAll, mask, shuffle, chunk, splitBy, join, stripTags, normalizeLineEndings, surround, ensurePrefix, ensureSuffix, removePrefix, removeSuffix, lines, first, last

String Validation

  • isBlank, isNotBlank, isEmpty, isNotEmpty, isAlpha, isAlphanumeric, isNumeric, isInteger, isDecimal, isAscii, isPrintableAscii, isHexadecimal, isUUID, isEmail, isURL, isJSON, isIPv4, isIPv6, isCreditCard, isSlug
  • startsWith, endsWith, contains, containsAll, containsAny, matches, compare, equals, equalsIgnoreCase, isPalindrome, isWhitespace, hasUpperCase, hasLowerCase, hasDigits, hasSpecialChars

Encoding & Escaping

  • escapeHtml, unescapeHtml, escapeXml, unescapeXml, escapeRegex, escapeSqlLike, escapeShell
  • toBase64, fromBase64, toBase64Url, fromBase64Url, encodeUrl, decodeUrl, toHex, fromHex, toAsciiCodes, fromAsciiCodes, rot13

Search & Analysis

  • countOccurrences, countWords, countLines, countSentences, countParagraphs
  • charFrequency, wordFrequency, indicesOf, nthIndexOf
  • extractNumbers, extractWords, extractEmails, extractUrls, extractHashtags, extractMentions
  • levenshteinDistance, similarity, longestCommonSubstring, longestCommonPrefix, longestCommonSuffix

Unicode & i18n

  • normalize, removeDiacritics, toCodePoints, fromCodePoints, graphemeLength, toGraphemes, toWords
  • isLetter, isDigit, isSpace, isPunctuation, isRTL, isLTR, getDirection
  • formatNumber, formatDate, formatCurrency, formatRelativeTime, pluralize, collate
  • getLocaleDisplayName, getRegionDisplayName

Formatting & Utilities

  • template, format, formatNamed, sprintf, zeroPad, formatThousands, formatBytes, formatDuration, ordinal, loremIpsum, randomString, uuid, hashCode

What’s Next?

  • npm: (link to package)
  • GitHub: (repository link)

If you give strfi a try, let me know in the comments – what’s your favorite utility? Any missing feature you’d love to see?

Stars, feedback, and shares are hugely appreciated. Thank you! 🚀

Happy coding!

Back to Blog

Related posts

Read more »

Anguar Tips #4

Introduction Some tips for working with Angular – from a frontend developer Part 4. These tips assume you already have experience with Angular, so we won’t div...