blakeembrey / change-case

Convert strings between camelCase, PascalCase, Capital Case, snake_case and more
MIT License
2.26k stars 97 forks source link

allow for better reuse #338

Closed PauloFerreira25 closed 5 months ago

PauloFerreira25 commented 5 months ago

Hello,

Please rate my idea.

My problem: I'm using kebabCase, but I need to ignore the ':' character, preventing it from being replaced.

I understand that to do this, the idea would be for me to pass a split function into Options.

However, I only need to make 1 small modification to the regex, including the ':' in DEFAULT_STRIP_REGEXP.

What I thought, if everything turns into export, I could simply import the split function, modify the options that is passed through it, and use this new function in the options parameter of kebabCase.

import { kebabCase, defaultSplitOptions, split as splitOrigin } from 'change-case';

const options = { ...defaultSplitOptions, stripRegexp: /[^\p{L}\d:]+/giu } 

kebabCase('TEST_VALUE', { split: (value) => splitOrigin(value, options) })

I understand that you can simply copy the code and place it inside my system, pointing to the split, and be happy. But I believe that allowing reuse would be better.

I believe that the PR needs to undergo changes. I only did the minimum to present the idea.

If what I proposed is not part of what the repository is proposing. Please excuse me.

Thank you for your attention.

blakeembrey commented 5 months ago

It's a good idea, but unfortunately it's not something I want to maintain in the library at this point in time. I want the flexibility to potentially refactor the code to not be a regex in the future, or to be able to refactor the regex if I have a chance to review performance. This change would tie me to the current very specific behavior. I'd honestly suggest just writing the specific split you want, since you probably don't need some of the features. A very simple split would just be:

const split = (value) => value.replace(/[^\p{L}\d\:]+/g, ' ').trim().split(' ');
PauloFerreira25 commented 5 months ago

Hello, I completely understand your opinion. This was the reason I opened a PR and asked if it would be useful.

Thank you very much for your attention.