Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When apply kebabCase wit a string separated by spaces it does not add the hyphen #86

Open
potsed opened this issue May 22, 2024 · 2 comments

Comments

@potsed
Copy link

potsed commented May 22, 2024

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

@ontoneio
Copy link

ontoneio commented Jul 16, 2024

@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.

@potsed
Copy link
Author

potsed commented Jul 21, 2024

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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants