Use const wherever possible in js/
[plack-app-gruntmaster.git] / js / 90-divine-format.js
index 5369b748abe2c966245448376e7e81c11fd5af21..da4885695889324bcd9a0712920901b7b5385cee 100644 (file)
@@ -1,52 +1,40 @@
+const ext_table = {
+       'c'   : 'C',
+
+       'cc'  : 'CPP',
+       'cpp' : 'CPP',
+       'cxx' : 'CPP',
+       'C'   : 'CPP',
+
+       'go'  : 'GOLANG',
+
+       'gs'  : 'GOLFSCRIPT',
+
+       'hs'  : 'HASKELL',
+       'lhs' : 'HASKELL',
+
+       'lisp': 'SBCL',
+       'lsp' : 'SBCL',
+       'cl'  : 'SBCL',
+       'l'   : 'SBCL',
+
+       'java': 'JAVA',
+
+       'pas' : 'PASCAL',
+
+       'pl'  : 'PERL',
+
+       'py'  : 'PYTHON',
+
+       'rb'  : 'RUBY'
+}
+
 function divine_format() {
-       var filename = $('#prog')[0].value;
-       var ext = /\.([^.]*)$/.exec(filename)[1];
-       var format;
-
-       switch(ext) {
-       case 'c':
-               format = 'C';
-               break;
-       case 'cc':
-       case 'cpp':
-       case 'cxx':
-       case 'C':
-               format = 'CPP';
-               break;
-       case 'go':
-               format = 'GOLANG';
-               break;
-       case 'hs':
-       case 'lhs':
-               format = 'HASKELL';
-               break;
-       case 'lisp':
-       case 'lsp':
-       case 'cl':
-       case 'l':
-               format = 'SBCL';
-               break;
-       case 'java':
-               format = 'JAVA';
-               break;
-       case 'pas':
-               format = 'PASCAL';
-               break;
-       case 'pl':
-               format = 'PERL';
-               break;
-       case 'py':
-               format = 'PYTHON';
-               break;
-       case 'rb':
-               format = 'RUBY';
-               break;
-       }
-
-       if(format)
-               $('#prog_format')[0].value = format;
+       const filename = $('#prog')[0].value;
+       const ext = /\.([^.]*)$/.exec(filename)[1];
+
+       if(ext_table[ext])
+               $('#prog_format')[0].value = ext_table[ext];
 }
 
-$(function() {
-       $('#prog').on('change', divine_format);
-});
+$(() => $('#prog').on('change', divine_format));
This page took 0.01093 seconds and 4 git commands to generate.