-
Notifications
You must be signed in to change notification settings - Fork 17
/
lumos.js
106 lines (84 loc) · 2.49 KB
/
lumos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env node
var fs = require('fs');
var chalk = require('chalk');
var path = require('path');
var cwd = process.cwd();
var img = ['.jpg','.jpeg','.png','.gif','.bmp','.tif','.svg'];
var zip =['.rar', '.jar', '.zip', '.tar', '.mar', '.iso', '.lz', '.7zip', '.tgz', '.gz', '.bz2'];
var codes = ['.cpp','.c','.py','.html','.js','.css','.java','.csproj','.rb','.pl','.pm','.sh', '.kt'];
var length = 0;
var columns = process.stdout.columns;
fs.readdir(cwd, function(err, items) {
var max = getMaxLength(items);
var div = Math.floor(columns / max);
for (var i=0; i<items.length; i++) {
if(i % div == 0 && i != 0){
console.log('');
}
if(!path.extname(items[i])){
process.stdout.write(chalk.blue.bold(items[i]));
for(var j = items[i].length; j <= max; j++){
process.stdout.write(" ");
}
}
else if(checkImg(path.extname(items[i]))){
process.stdout.write(chalk.magenta.bold(items[i]));
for(var j1 = items[i].length; j1 <= max; j1++){
process.stdout.write(" ");
}
}
else if(checkZip(path.extname(items[i]))){
process.stdout.write(chalk.red.bold(items[i]));
for(var j2 = items[i].length; j2 <= max; j2++){
process.stdout.write(" ");
}
}
else if(checkCode(path.extname(items[i]))){
process.stdout.write(chalk.yellow.bold(items[i]));
for(var j3 = items[i].length; j3 <= max; j3++){
process.stdout.write(" ");
}
}
else{
process.stdout.write(items[i]);
for(var j4 = items[i].length; j4 <= max; j4++){
process.stdout.write(" ");
}
}
}
console.log('');
});
function getMaxLength(items){
var max = 0;
for(var i = 0; i< items.length ; i++){
if(items[i].length > max){
max = items[i].length;
}
}
return max;
}
// Checking Functions
function checkImg(ext){
for(var i = 0; i < img.length ; i++){
if(ext === img[i]){
return true;
}
}
return false;
}
function checkZip(ext){
for(var i = 0; i < zip.length ; i++){
if(ext === zip[i]){
return true;
}
}
return false;
}
function checkCode(ext){
for(var i = 0; i < codes.length ; i ++){
if(ext === codes[i]){
return true;
}
}
return false;
}