
Company News
Socket Joins New OpenJS Program to Fund Node.js Security Work
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.
A lightweight collection of handy string manipulation utilities — slugify, truncate, capitalize, camelToKebab, maskEmail, and more.
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.
npm install stringloom
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.
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"
| Option | Type | Default | Description |
|---|---|---|---|
separator | string | "-" | Character to replace spaces with |
lowercase | boolean | true | Convert to lowercase |
truncate("The quick brown fox jumps over the lazy dog", { length: 20 })
// "The quick brown fox…"
truncate("abcdefghij", { length: 7, ellipsis: "...", wordBoundary: false })
// "abcd..."
| Option | Type | Default | Description |
|---|---|---|---|
length | number | 30 | Max length including ellipsis |
ellipsis | string | "…" | String appended when truncated |
wordBoundary | boolean | true | Truncate at nearest word boundary |
truncateMiddle("abcdefghijklmnopqrstuvwxyz", { length: 10 })
// "abcde…wxyz"
| Option | Type | Default | Description |
|---|---|---|---|
length | number | 30 | Max length including ellipsis |
ellipsis | string | "…" | String inserted in the middle |
capitalize("hello world") // "Hello world"
capitalizeWords("hello world") // "Hello World"
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.
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) | Type | Default | Description |
|---|---|---|---|
char | string | "*" | Character used for masking |
keepStart | number | 4 | Visible characters at the start |
keepEnd | number | 0 | Visible characters at the end |
reverse("hello") // "olleh"
reverse("🚀🌍") // "🌍🚀"
Unicode-safe string reversal.
countWords("Hello, World!") // 2
countOccurrences("banana", "an") // 2
padStart("42", 5, "0") // "00042"
padEnd("42", 5, "0") // "42000"
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.
stripHtml("<p>Hello <b>World</b></p>") // "Hello World"
stripWhitespace(" h e l l o ") // "hello"
collapseWhitespace(" hello world ") // "hello world"
deburr("Héllo Wörld") // "Hello World"
escapeRegExp("hello.*(world)?") // "hello\\.\\*\\(world\\)\\?"
isPalindrome("Racecar") // true
isBlank(" ") // true
isNumeric("12345") // true
isAlpha("hello") // true
isAlphanumeric("hello123") // true
isEmail("a@b.com") // true
isEmail("not-an-email") // false
isUrl("https://example.com") // true
isUrl("example.com") // false
sanitizeFilename("my<file>:name?.txt") // "my_file_name_.txt"
sanitizeFilename("CON") // "_CON"
initials("John Doe") // "JD"
initials("alice bob charlie") // "ABC"
excerpt("The quick brown fox jumps over the lazy dog", "fox", { radius: 5 })
// "…brown fox jumps…"
| Option | Type | Default | Description |
|---|---|---|---|
radius | number | 30 | Characters to include around the phrase |
omission | string | "…" | Indicator for omitted text |
| Function | Description |
|---|---|
slugify | Convert string to URL-friendly slug |
deburr | Remove accents/diacritics |
truncate | Truncate with ellipsis & word boundary support |
truncateMiddle | Truncate from the middle |
capitalize | Capitalize first letter |
capitalizeWords | Capitalize first letter of every word |
toCamelCase | Convert to camelCase |
toPascalCase | Convert to PascalCase |
toKebabCase | Convert to kebab-case |
toSnakeCase | Convert to snake_case |
camelToKebab | camelCase/PascalCase to kebab-case |
camelToSnake | camelCase/PascalCase to snake_case |
maskEmail | Mask an email address |
mask | Mask a string with configurable visibility |
maskPhone | Mask a phone number (keeps last 4 digits) |
reverse | Unicode-safe string reversal |
countWords | Count words in a string |
countOccurrences | Count substring occurrences |
padStart | Left-pad a string |
padEnd | Right-pad a string |
template | {{key}} placeholder interpolation |
stripHtml | Remove HTML tags |
stripWhitespace | Remove all whitespace |
collapseWhitespace | Collapse whitespace to single spaces |
escapeRegExp | Escape a string for safe regex usage |
isPalindrome | Check if string is a palindrome |
isBlank | Check if string is empty/whitespace |
isNumeric | Check if string is all digits |
isAlpha | Check if string is all letters |
isAlphanumeric | Check if string is letters + digits |
isEmail | Basic email validation |
isUrl | Check if string is a valid http/https URL |
sanitizeFilename | Sanitize a string for safe filenames |
initials | Extract initials from a name |
excerpt | Extract snippet around a search phrase |
MIT
FAQs
A lightweight collection of handy string manipulation utilities — slugify, truncate, capitalize, camelToKebab, maskEmail, and more.
The npm package stringloom receives a total of 2 weekly downloads. As such, stringloom popularity was classified as not popular.
We found that stringloom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Company News
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.

Security News
Two compromised GitHub Actions were re-enabled with malicious tags intact, exposing thousands of downstream repositories to Mini Shai-Hulud.

Research
/Security News
A malicious Firefox extension fetches its payload after installation to evade detection, steal Google session cookies, and automate account takeover.