When apply kebabCase wit a string separated by spaces it does not add the hyphen
Environment
Package 1.3.0 Node v21.7.3 Vue 3
Reproduction
import { kebabCase } from "scule"
console.log(kebabCase("A string with Spaces"))
Expect: a-string-with-spaces
Actual: a string with spaces
Describe the bug
Trying to convert a string into a slug for a URI and noticed this behaviour.
Additional context
I noticed the tests do not have test cases for string with spaces and wonder if this is intended behaviour.
Logs
No response
@potsed
By default it looks like the kebabCase function passes a string through the splitByCase function for it's underlying implementation. The functions type itself only takes .You can get around it if you need with a kebabCase(splitByCase('text to convert, [' '])) which adds the space as a joiner to the splitByCase function as it is not part of the default Splitter types. It could be added as default, but I suspect there are edge cases and side effects with whitespace that you might avoid by implementing this way instead of including spaces by default.
Hi @ontoneio
Thanks for the response. While I get your points about edge cases and side-effects and do appreciate the workaround, it is still a workaround.
I do think it is more likely that people will want to do kebab-case specifically with spaces as a default. This is the first example of a string conversion lib I've experienced where it is not a default, so it seems an odd choice not to default to converting spaces. (see https://github.com/az33zy/slugrace at https://slugrace.zy.ke/ )
Wouldn't most devs who specifically request a a string conversion to kebab, snake, camel, pascal or indeed any other expect the spaces to be removed as part of that conversion?
It's cool if not, but if not it probably should be documented behavior.
Anyway - thanks :)
@potsed
By default it looks like the
kebabCasefunction passes a string through thesplitByCasefunction for it's underlying implementation. The functions type itself only takes .You can get around it if you need with akebabCase(splitByCase('text to convert, [' ']))which adds the space as a joiner to thesplitByCasefunction as it is not part of the defaultSplittertypes. It could be added as default, but I suspect there are edge cases and side effects with whitespace that you might avoid by implementing this way instead of including spaces by default.