PascalCase DEAcronym-er
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));
})