Created
May 8, 2015 21:41
-
-
Save indexzero/95e972764f534046d234 to your computer and use it in GitHub Desktop.
PascalCase DEAcronym-er
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
function deacronym(anyKey) { | |
return anyKey.replace(/([A-Z]+)[A-Z]/g, function (match, cap, i, str) { | |
var sub; | |
if (i + match.length === str.length) { | |
sub = match.slice(1); | |
} else { | |
sub = !i ? cap.slice(1) : match.slice(1, -1); | |
} | |
return match.replace(sub, sub.toLowerCase()); | |
}); | |
} | |
[ | |
'InPascal', // InPascal | |
'PREFix', // PreFix | |
'FixPOST', // FixPost | |
'AndINFix', // AndInFix | |
'PREAndINAndPostFIX' // PreAndInAndPostFix | |
].forEach(function (test) { | |
precamel = deacronym(test); | |
console.log(test, precamel, require('camel-case')(precamel)); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment