Does slugify split camelCase strings? Show me the relevant logic.
Does slugify split camelCase strings? Show me the relevant logic.
About sindresorhus/slugify · 2 messages · last activity 7/6/2026
Question
RepoPilot
Yes, slugify splits camelCase strings by default. This is controlled by the decamelize option, which defaults to true [index.d.ts:L40].
Here's the relevant logic from the main function [index.js:L46-L111]:
if (options.decamelize) {
string = decamelize(string);
}
The decamelize option converts camelCase to separate words. According to the documentation, internally it does fooBar → foo bar [index.d.ts:L40].
For example:
slugify('fooBar')returns'foo-bar'[index.d.ts:L44]slugify('fooBar', {decamelize: false})returns'foobar'(with decamelize disabled) [index.d.ts:L45]
You can disable this behavior by passing {decamelize: false} to the options.
FOLLOW_UPS:
- How does the decamelize function work internally?
- What other transformations happen after decamelizing?
- How can I preserve camelCase in specific parts?
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.