Created
September 1, 2022 06:20
-
-
Save Steveorevo/4139b235054976e8566ce6f844a1b5f5 to your computer and use it in GitHub Desktop.
JavaScript style camelcase to PHP style underscore and back
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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