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 5/18/2026
Yes, slugify splits camelCase strings by default. This is controlled by the decamelize option.
According to the documentation in [index.d.ts:L40-L50], the decamelize option is set to true by default and "Convert[s] camelcase to separate words. Internally it does fooBar → foo bar."
Here are examples from the test suite [test.js:L107-L110]:
test('decamelize option', t => {
t.is(slugify('fooBar'), 'foo-bar');
t.is(slugify('fooBar', {decamelize: false}), 'foobar');
});
So when you call slugify('fooBar') with default options, it returns 'foo-bar' because camelCase is split into separate words and then joined with the separator. If you disable this behavior with {decamelize: false}, you get 'foobar' instead.
FOLLOW_UPS:
- How does the decamelize feature work internally?
- What other string transformations does slugify apply?
- Can you customize the separator character used?
Want to ask your own question?
Open chat for sindresorhus/slugify →Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/slugify. AI answers can be incomplete or stale — verify before relying on them.