Convert CamelCase to snake_case and vice versa

As the title says: Convert CamelCase to snake_case and vice versa.

The extension could even attempt to do both conversion with one icon: It can detect whether the selection is CamelCase or snake_case and convert to the other. - I know the identification of each is not unambiguous, but these are rare edge cases where the extension could just pick one or do nothing.

1 Like
# popclip
name: Variable Name Convert
icon: Var
regex: ^\s*[a-zA-Z_][a-zA-Z0-9_]*\s*$
javascript: |
  const name = popclip.input.text.replace(/^[\s_]+|[\s_]+$/g, '');
  const words = name.split('_');
  if(words.length > 1){
    return => word[0].toUpperCase() + word.slice(1).toLowerCase()).join('');
  } else {
    return name.replace(/[A-Z]/g, (match) => {
      return '_' + match.toLowerCase()
    }).replace(/^_+|_+$/, '')
after: paste-result

Cool. Works perfectly!

1 Like

Great stuff. Iā€™m actually about to release an extension similar to this as well, it will convert to 5 different common programming cases.


Just to bump this, the extension I mentioned is available now: New extension: Coding Cases