Skip to content

Instantly share code, notes, and snippets.

@amiralles
Created November 24, 2021 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiralles/3e1f8a9db9dd58d10f3112f910910cd1 to your computer and use it in GitHub Desktop.
Save amiralles/3e1f8a9db9dd58d10f3112f910910cd1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Converts camelCased words into snake_cased ones.
# (This might be seful when you have to convert a JS object into an Elixir one.)
# TODO: Ignore quoted strings.
function camel_to_snake_case {
while read -r line; do
echo $line | sed 's/\(.\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]'
done
}
camel_to_snake_case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment