blakeembrey / change-case

Convert strings between camelCase, PascalCase, Capital Case, snake_case and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Finer tuning of split separator?

NamesMT opened this issue · comments

Currently change-case parses (splits) multiple types of casing in one pass like:

Using capitalCase():
Hello from Sn_ake's iPhone => Hello From Sn Ake S I Phone
Check out: 101 iAndroid => Check Out 101 I Android ## We are also missing the colon here

It would be amazing if we could have some / an option to finer tuning to achive results like:
Hello From Sn_ake's IPhone ## white space only
Hello From Sn_ake's iPhone ## detect common noun styling ([a-z][A-Z])

We could also think about export the factory functions so that user could use custom split functions, or accept a split function as an option.

Can you describe more about what you’re actually trying to do? I don’t think this library is designed to fit your needs, you’re probably better off just writing the code to do whatever it is you want yourself.

Hi Blake,
TL;DR of what I'm trying to achieve is a way to make the split function less agressive, or being able to pass a custom split function to it 😄
The library is awesome but sometimes too agressive in some cases as mention in the first post, that's all.


#Edited: add example for custom split function option:
Normal/current bevavior:
capitalCase('Hello linkedIn') => "Hello Linked In"

Split function:
const whitespaceSplit = (str) => str.split(' ')
capitalCase('Hello linkedIn', { splitFn: whitespaceSplit }) => "Hello LinkedIn"

The issue with your example is it still won’t work as expected, the case changing functions also lower case other characters.

It seems like what you really want is just the existing title case library? It doesn’t do any splitting or white space changes and avoids messing with words like iPhone.

Kk thank you for your time!

My network have been a pain to browse around and I didn't actually visit the factory functions (my bad),
It seems like a new package is easier to fit my case than commitings to change-case.

No worries. Let me know if that doesn't work as expected. The main problem is that the core change-case library is truly only suited for switching back and forth between programming cases, not at all for handling punctuation or sentences.