Skip to content

Commit

Permalink
refactor: make splitByCase more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 17, 2021
1 parent 0d51cd2 commit f7c6d26
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ export function splitByCase (str: string, splitters = STR_SPLITTERS): string[] {
buff = ''
previusUpper = false
previousSplitter = true
} else if (!previousSplitter && !previusUpper && isUppercase(char)) {
continue
}

const isUpper = isUppercase(char)
if (!previousSplitter && (!previusUpper && isUpper /* rising edge */)) {
parts.push(buff)
buff = char
previusUpper = true
previusUpper = isUpper
previousSplitter = false
} else {
buff += char
previusUpper = isUppercase(char)
previousSplitter = isSplitter
continue
}

buff += char
previusUpper = isUpper
previousSplitter = isSplitter
}

if (buff) {
Expand Down

0 comments on commit f7c6d26

Please sign in to comment.