Created
December 12, 2014 04:41
-
-
Save laiso/cb9e1df150f3a1b472a8 to your computer and use it in GitHub Desktop.
英文をメソッド名にするやつ(ローワーキャメルケース)
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
var select = window.getSelection().toString(); | |
var text = (select.length > 0)? select: document.querySelector("span.gt-card-ttl-txt").innerText; // Google Translate | |
var words = text.split(" "); | |
var methodName = ""; | |
for (var i = 0, l = words.length; i < l; i++) { | |
var word = words[i]; | |
if (word.length === 0) { | |
continue; | |
} | |
if (i === 0) { | |
word = word.toLowerCase(); | |
} else { | |
word = word[0].toUpperCase() + word.slice(1, word.length); | |
} | |
methodName += word; | |
} | |
alert(methodName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment