New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

stringloom

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stringloom

A lightweight collection of handy string manipulation utilities — slugify, truncate, capitalize, camelToKebab, maskEmail, and more.

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

npm version npm downloads license GitHub stars

stringloom

A lightweight, zero-dependency collection of string manipulation utilities for JavaScript and TypeScript. Think of it as a focused alternative to lodash's string methods.

Install

npm install stringloom

Usage

import { slugify, maskEmail, toCamelCase } from "stringloom";

slugify("Hello World!");           // "hello-world"
maskEmail("john.doe@example.com"); // "j******e@example.com"
toCamelCase("background-color");   // "backgroundColor"

Works with both ESM (import) and CommonJS (require). Full TypeScript types included.

API

Slugify

slugify("Hello World!")                       // "hello-world"
slugify("Héllo Wörld")                        // "hello-world"
slugify("foo bar", { separator: "_" })        // "foo_bar"
slugify("Hello World", { lowercase: false })  // "Hello-World"
OptionTypeDefaultDescription
separatorstring"-"Character to replace spaces with
lowercasebooleantrueConvert to lowercase

Truncate

truncate("The quick brown fox jumps over the lazy dog", { length: 20 })
// "The quick brown fox…"

truncate("abcdefghij", { length: 7, ellipsis: "...", wordBoundary: false })
// "abcd..."
OptionTypeDefaultDescription
lengthnumber30Max length including ellipsis
ellipsisstring"…"String appended when truncated
wordBoundarybooleantrueTruncate at nearest word boundary

Truncate (Middle)

truncateMiddle("abcdefghijklmnopqrstuvwxyz", { length: 10 })
// "abcde…wxyz"
OptionTypeDefaultDescription
lengthnumber30Max length including ellipsis
ellipsisstring"…"String inserted in the middle

Capitalize

capitalize("hello world")       // "Hello world"
capitalizeWords("hello world")  // "Hello World"

Case Conversion

toCamelCase("hello-world")       // "helloWorld"
toPascalCase("hello-world")      // "HelloWorld"
toKebabCase("helloWorld")        // "hello-world"
toSnakeCase("helloWorld")        // "hello_world"
camelToKebab("backgroundColor")  // "background-color"
camelToSnake("backgroundColor")  // "background_color"

Handles camelCase, PascalCase, kebab-case, snake_case, and whitespace-separated input.

Masking

maskEmail("john.doe@example.com")  // "j******e@example.com"

mask("4242424242424242")                           // "4242************"
mask("4242424242424242", { keepStart: 0, keepEnd: 4 }) // "************4242"

maskPhone("+1 (555) 123-4567")  // "***********4567"
Option (mask)TypeDefaultDescription
charstring"*"Character used for masking
keepStartnumber4Visible characters at the start
keepEndnumber0Visible characters at the end

Reverse

reverse("hello")  // "olleh"
reverse("🚀🌍")   // "🌍🚀"

Unicode-safe string reversal.

Counting

countWords("Hello, World!")    // 2
countOccurrences("banana", "an")  // 2

Padding

padStart("42", 5, "0")  // "00042"
padEnd("42", 5, "0")    // "42000"

Template

template("Hello, {{name}}!", { name: "World" })  // "Hello, World!"
template("{{a}} + {{b}} = {{c}}", { a: "1", b: "2", c: "3" })
// "1 + 2 = 3"

Simple {{key}} placeholder interpolation. Unknown placeholders are left as-is.

Strip / Collapse

stripHtml("<p>Hello <b>World</b></p>")  // "Hello World"
stripWhitespace("  h e l l o  ")        // "hello"
collapseWhitespace("  hello   world  ") // "hello world"

Deburr (Remove Accents)

deburr("Héllo Wörld") // "Hello World"

Escape RegExp

escapeRegExp("hello.*(world)?") // "hello\\.\\*\\(world\\)\\?"

Checks

isPalindrome("Racecar")   // true
isBlank("  ")              // true
isNumeric("12345")         // true
isAlpha("hello")           // true
isAlphanumeric("hello123") // true

Validators

isEmail("a@b.com")           // true
isEmail("not-an-email")      // false
isUrl("https://example.com") // true
isUrl("example.com")         // false

Sanitize Filename

sanitizeFilename("my<file>:name?.txt") // "my_file_name_.txt"
sanitizeFilename("CON")                // "_CON"

Initials

initials("John Doe")           // "JD"
initials("alice bob charlie")  // "ABC"

Excerpt

excerpt("The quick brown fox jumps over the lazy dog", "fox", { radius: 5 })
// "…brown fox jumps…"
OptionTypeDefaultDescription
radiusnumber30Characters to include around the phrase
omissionstring"…"Indicator for omitted text

All Exports

FunctionDescription
slugifyConvert string to URL-friendly slug
deburrRemove accents/diacritics
truncateTruncate with ellipsis & word boundary support
truncateMiddleTruncate from the middle
capitalizeCapitalize first letter
capitalizeWordsCapitalize first letter of every word
toCamelCaseConvert to camelCase
toPascalCaseConvert to PascalCase
toKebabCaseConvert to kebab-case
toSnakeCaseConvert to snake_case
camelToKebabcamelCase/PascalCase to kebab-case
camelToSnakecamelCase/PascalCase to snake_case
maskEmailMask an email address
maskMask a string with configurable visibility
maskPhoneMask a phone number (keeps last 4 digits)
reverseUnicode-safe string reversal
countWordsCount words in a string
countOccurrencesCount substring occurrences
padStartLeft-pad a string
padEndRight-pad a string
template{{key}} placeholder interpolation
stripHtmlRemove HTML tags
stripWhitespaceRemove all whitespace
collapseWhitespaceCollapse whitespace to single spaces
escapeRegExpEscape a string for safe regex usage
isPalindromeCheck if string is a palindrome
isBlankCheck if string is empty/whitespace
isNumericCheck if string is all digits
isAlphaCheck if string is all letters
isAlphanumericCheck if string is letters + digits
isEmailBasic email validation
isUrlCheck if string is a valid http/https URL
sanitizeFilenameSanitize a string for safe filenames
initialsExtract initials from a name
excerptExtract snippet around a search phrase

License

MIT

Keywords

string

FAQs

Package last updated on 27 Feb 2026

Related posts