Skip to content

Instantly share code, notes, and snippets.

@laiso
Created December 12, 2014 04:41
Show Gist options
  • Save laiso/cb9e1df150f3a1b472a8 to your computer and use it in GitHub Desktop.
Save laiso/cb9e1df150f3a1b472a8 to your computer and use it in GitHub Desktop.
英文をメソッド名にするやつ(ローワーキャメルケース)
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