Skip to content

Instantly share code, notes, and snippets.

@Chudesnov
Created April 28, 2014 21:24
Show Gist options
  • Save Chudesnov/11384476 to your computer and use it in GitHub Desktop.
Save Chudesnov/11384476 to your computer and use it in GitHub Desktop.
// capitalize words
function ucFirstAllWords( str )
{
var pieces = str.split(" ");
for ( var i = 0; i < pieces.length; i++ )
{
var j = pieces[i].charAt(0).toUpperCase();
pieces[i] = j + pieces[i].substr(1);
}
return pieces.join(" ");
}
// except for words listed here: http://aitech.ac.jp/~ckelly/midi/help/caps.html:
var stopList = "a,abaft,aboard,about,above,absent,across,afore,after,against,along,alongside,amid,amidst,among,amongst,an,anenst,apropos,apud,around,as,aside,astride,at,athwart,atop,barring,before,behind,below,beneath,beside,besides,between,beyond,but,by,circa,concerning,despite,down,during,except,excluding,failing,following,for,forenenst,from,given,in,including,inside,into,like,mid,midst,minus,modulo,near,next,notwithstanding,o',of,off,on,onto,opposite,out,outside,over,pace,past,per,plus,pro,qua,regarding,round,sans,save,since,than,through,throughout,till,times,to,toward,towards,under,underneath,unlike,until,unto,up,upon,versus,via,vice,vis-à-vis,with,within,without,worth";
function ucFirstAllWords( str )
{
var pieces = str.split(" ");
for ( var i = 0; i < pieces.length; i++ )
{
if (stopList.indexOf(pieces[i].toLowerCase()) > -1)
//stop word
// do something about it. or don't
continue;
var j = pieces[i].charAt(0).toUpperCase();
pieces[i] = j + pieces[i].substr(1);
}
return pieces.join(" ");
}
// how to trim properly
String.prototype.toSong = function(){
var result;
result = this.trim().replace(/(\s)\s+/g,'$1');
return ucFirstAllWords(result);
}
trimmer = function(p,t){
p=ge('audio_performer_edit');
t=ge('audio_title_edit');
b=ge('audio_save_btn');
p.value=p.value.toSong();
t.value=t.value.toSong();
}
// get bad songs
res = [];
a.forEach(function(el){
var el5=el[5].toSong(),
el6=el[6].toSong();
if(el6.length!==el[6].length||el5.length!==el[5].length)
res.push(el5+' - '+el6);
});
res.sort().join('\n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment