Skip to content

Instantly share code, notes, and snippets.

@matthijsgroen
Created January 4, 2012 07:38
Show Gist options
  • Save matthijsgroen/1558986 to your computer and use it in GitHub Desktop.
Save matthijsgroen/1558986 to your computer and use it in GitHub Desktop.
Convert javascript to coffeescript (ideal for jasmine specs)
" convert javascript to coffeescript
command! ConvertJs :call ConvertJs()
function! ConvertJs()
:norm =G
:silent :%s/;$//e
:silent :%s/var //ge
:silent :g/^\s\+})$/d
:silent :%s/function() {/->/ge
:silent :%s/^\(\s\+\)\(\w\+\)$/\1\2 = null/e
:silent :%s/function(\(\w\+\)) {/(\1) ->/ge
:silent :%s/\/\//#/ge
:silent :%s/beforeEach(->/beforeEach ->/e
:silent :g/^})$/d
:silent :%s/describe(/describe /ge
:silent :%s/it(/it /ge
:silent :%s/this\./@/ge
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment