lib/pirate-speak.js
function applyCase(wordA, wordB) {
	// Exception to avoid words like "I" being converted to "ME"
	if (wordA.length === 1 && wordB.length !== 1) return wordB;
	// Uppercase
	if (wordA === wordA.toUpperCase()) return wordB.toUpperCase();
	// Lowercase
	if (wordA === wordA.toLowerCase()) return wordB.toLowerCase();
	// Capitialized
	var firstChar = wordA.slice(0, 1);
	var otherChars = wordA.slice(1);
	if (firstChar === firstChar.toUpperCase() && otherChars === otherChars.toLowerCase()) {
		return wordB.slice(0, 1).toUpperCase() + wordB.slice(1).toLowerCase();
	}
	// Other cases
	return wordB;
}
function applyCase(wordA, wordB) {
	// Exception to avoid words like "I" being converted to "ME"
	if (wordA.length === 1 && wordB.length !== 1) return wordB;
	// Uppercase
	if (wordA === wordA.toUpperCase()) return wordB.toUpperCase();
	// Lowercase
	if (wordA === wordA.toLowerCase()) return wordB.toLowerCase();
	// Capitialized
	var firstChar = wordA.slice(0, 1);
	var otherChars = wordA.slice(1);
	if (firstChar === firstChar.toUpperCase() && otherChars === otherChars.toLowerCase()) {
		return wordB.slice(0, 1).toUpperCase() + wordB.slice(1).toLowerCase();
	}
	// Other cases
	return wordB;
}
function applyCase ( wordA , wordB ) { // Exception to avoid words like "I" being converted to "ME" if ( wordA . length === 1 && wordB . length !== 1 ) return wordB ; // Uppercase if ( wordA === wordA . toUpperCase ( ) ) return wordB . toUpperCase ( ) ; // Lowercase if ( wordA === wordA . toLowerCase ( ) ) return wordB . toLowerCase ( ) ; // Capitialized var firstChar = wordA . slice ( 0 , 1 ) ; var otherChars = wordA . slice ( 1 ) ; if ( firstChar === firstChar . toUpperCase ( ) && otherChars === otherChars . toLowerCase ( ) ) { return wordB . slice ( 0 , 1 ) . toUpperCase ( ) + wordB . slice ( 1 ) . toLowerCase ( ) ; } // Other cases return wordB ; }
Take the case from wordA and apply it to wordB
Take the case from wordA and apply it to wordB