Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fs = require('fs');
  2.  
  3. var colours = JSON.parse(fs.readFileSync('colours.json', 'utf8'));
  4.  
  5. function ext(ext) {
  6.     // Turn extension to colour
  7.     var keys = Object.keys(colours);
  8.     for (i=0; i<keys.length; i++) {
  9.         var extensions = colours[keys[i]].extensions;
  10.         try {
  11.             for (j=0; j<extensions.length; j++) {
  12.                 if (extensions[j] == ext) {
  13.                     if (colours[keys[i]].color != undefined) {
  14.                         return colours[keys[i]].color;
  15.                     } else {
  16.                         return null;
  17.                     }
  18.                 }
  19.             }
  20.         } catch(err) {
  21.             // Nothing
  22.         }
  23.     }
  24.     return null;
  25. }
  26.  
  27. function get(lang) {
  28.     // Turn language to colour
  29.     return colours[lang].color;
  30. }
  31.  
  32. function lang(ext) {
  33.     // Turn extension to language
  34.     var keys = Object.keys(colours);
  35.     for (i=0; i<keys.length; i++) {
  36.         var extensions = colours[keys[i]].extensions;
  37.         try {
  38.             for (j=0; j<extensions.length; j++) {
  39.                 if (extensions[j] == ext) {
  40.                     return keys[i];
  41.                 }
  42.             }
  43.         } catch(err) {
  44.             // Nothing
  45.         }
  46.     }
  47.     return null;
  48. }
  49.  
  50. console.log("== Testing ext() with '.agda' (Should Be #315665) ==");
  51. console.log(ext(".agda"));
  52. console.log("== Testing get() with 'Agda' (Should Be #315665) ==");
  53. console.log(get("Agda"));
  54. console.log("== Testing lang() with '.agda' (Should Be Agda) ==");
  55. console.log(lang(".agda"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement