Skip to content

Instantly share code, notes, and snippets.

@Steveorevo
Created September 1, 2022 06:20
Show Gist options
  • Save Steveorevo/4139b235054976e8566ce6f844a1b5f5 to your computer and use it in GitHub Desktop.
Save Steveorevo/4139b235054976e8566ce6f844a1b5f5 to your computer and use it in GitHub Desktop.
JavaScript style camelcase to PHP style underscore and back
// Underscore to camelcase
function usToCC(str) {
return str.replace(/_([a-z])/g, function (g) { return g[1].toUpperCase(); });
}
// Camelcase to underscore
function ccToUs(str) {
return str.replace(/([a-z][A-Z])/g, function (g) { return g[0] + '_' + g[1].toLowerCase() });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment