Created
January 26, 2010 10:00
-
-
Save satyr/286723 to your computer and use it in GitHub Desktop.
upper/lower/title/flipped case
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
function casecmd(fn) CmdUtils.CreateCommand({ | |
name: fn.name +' case', | |
description: 'Makes text '+ fn.name +' case.', | |
icon: icon(fn('Aa')), | |
argument: noun_arb_text, | |
execute: function case_execute({object: {text, html}}){ | |
if(!text) return; | |
var t = fn(text); | |
CmdUtils.setSelection(fn(html), {text: t}) || CmdUtils.copyToClipboard(t); | |
}, | |
preview: function case_preview(pb, {object: {html}}){ | |
pb.innerHTML = html ? fn(html) : this.previewDefault(pb); | |
}, | |
}); | |
function icon(txt){ | |
var cv = CmdUtils.getHiddenWindow().document.createElementNS( | |
'http://www.w3.org/1999/xhtml', 'canvas'); | |
cv.width = cv.height = 16; | |
var cc = cv.getContext('2d'); | |
cc.font = '16px monospace'; | |
cc.textBaseline = 'top'; | |
cc.fillStyle = 'rgba(0,0,0,0.8)'; | |
cc.fillText(txt, 0, 0); | |
return cv.toDataURL('image/png'); | |
} | |
casecmd(function upper(s) s.toUpperCase()) | |
casecmd(function lower(s) s.toLowerCase()); | |
casecmd(function title(s){ | |
return s.replace( | |
/\w(\w*)/g, function($, r) $[0].toUpperCase() + r.toLowerCase()); | |
}); | |
casecmd(function flipped(s){ | |
var r = '', v; | |
for each(let c in s) | |
r += c === (v = c.toUpperCase()) ? c.toLowerCase() : v; | |
return r; | |
}); | |
$.extend(feed, { | |
authors: [{name: 'powchin', homepage: 'http://friendfeed.com/powchin'}, | |
{name: 'satyr' , homepage: 'http://friendfeed.com/matyr'}], | |
license: 'MIT', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment