Question
Does slugify split camelCase strings? Show me the relevant logic.
About sindresorhus/slugify · 2 messages · last activity 8/1/2026
Does slugify split camelCase strings? Show me the relevant logic.
Perfect! Here's the actual implementation logic:
The decamelization happens in the decamelize function [index.js:L5-L14], which uses a series of regex replacements to insert spaces between camelCase segments:
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');
This function is called conditionally in the main slugify function [index.js:L84-L86]:
if (options.decamelize) {
string = decamelize(string);
}
The regex patterns handle:
APIs)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.