Question
Does slugify split camelCase strings? Show me the relevant logic.
About sindresorhus/slugify · 2 messages · last activity 9/1/2026
Does slugify split camelCase strings? Show me the relevant logic.
Perfect! Here's the decamelization logic from [index.js:L5-L14]:
const decamelize = string => string
// Separate capitalized words.
.replaceAll(/([A-Z]{2,})(\d+)/g, '$1 $2')
.replaceAll(/([a-z\d]+)([A-Z]{2,})/g, '$1 $2')
.replaceAll(/([a-z\d])([A-Z])/g, '$1 $2')
// `[a-rt-z]` matches all lowercase characters except `s`.
// This avoids matching plural acronyms like `APIs`.
.replaceAll(/([A-Z]+)([A-Z][a-rt-z\d]+)/g, '$1 $2');
The function uses a series of regex replacements to insert spaces between camelCase boundaries:
HTML5 → HTML 5)XMLParser → XML Parser)fooBar → foo Bar)APIs by excluding the letter sWhen decamelize: true (the default), this function is called in the main slugify() function at [index.js:L81-L82].
FOLLOW_UPS:
Want to ask your own question?
Open chat for sindresorhus/slugifyPublic Q&A. Generated by RepoPilot from the actual source of sindresorhus/slugify. AI answers can be incomplete or stale — verify before relying on them.