- Docs
- Word splitting
Word splitting
Exactly how @samline/string splits text into words, with separators, camelCase, acronyms, digits and any script.
Every case function starts from words(text). The rules, in order:
- A lower-case letter or digit followed by an upper-case letter starts a new word:
fooBar→foo,Bar;version2Beta→version2,Beta. - An acronym ends before its last capital when a lower-case letter follows:
XMLHttpRequest→XML,Http,Request. - Any character that is not a letter or a digit separates words: spaces,
-,_,.,/and punctuation. - Letters from any script count as letters, so
añoNuevo→año,Nuevo.
| Input | Words |
|---|---|
getHTTPResponseCode |
get, HTTP, Response, Code |
snake_case-and.dot/path |
snake, case, and, dot, path |
--leading and trailing__ |
leading, and, trailing |
version2Beta |
version2, Beta |
Digits stay attached to the word before them, so v2 and utf8 do not break into pieces. Mixed-case names follow rule 1: iPhone15 → i, Phone15.