Skip to content

Commit cedbc0f

Browse files
committed
Modularize
1 parent f9eedfa commit cedbc0f

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<head>
44
<title>Lines Of Code</title>
55
<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
6-
<script type="text/javascript" src = "index.js"></script>
6+
<script type = "text/javascript" src = "traverseDirectory.js"></script>
7+
<script type = "text/javascript" src = "lineOfCode.js"></script>
8+
<script type = "text/javascript" src = "index.js"></script>
79
</head>
810
<body>
911

index.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
1-
var getLinesOfCodePromise = gitUrl => {
2-
return new Promise(function(resolve, reject) {
3-
$.ajax({
4-
url: gitUrl,
5-
success: result => {
6-
var decoded_string = atob(result.content);
7-
resolve(decoded_string.split('\n').length - 1);
8-
},
9-
error: (jqXHR, textStatus, errorThrown) => {
10-
reject(textStatus);
11-
},
12-
});
13-
});
14-
};
15-
16-
var getLinesOfCode = getLinesOfCodePromise(
1+
var linesOfCode = getLinesOfCode(
172
'https://api.github.com/repos/Ankit-22/AutoConnect/git/blobs/e6b32bc7884bb98a5024981d37fec787514b56c8'
183
);
194

20-
getLinesOfCode.then(
21-
data => {
22-
console.log(data);
23-
},
24-
error => {
25-
console.log(error);
26-
}
27-
);
5+
console.log(linesOfCode);
6+
7+
gitDirectoryScrapper("https://api.github.com/repos/Ankit-22/AutoConnect/contents/");

lineOfCode.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var getLinesOfCode = gitUrl => {
2+
var linesOfCodePromise = new Promise( (resolve, reject) => {
3+
$.ajax({
4+
url: gitUrl,
5+
success: result => {
6+
var decoded_string = atob(result.content);
7+
resolve(decoded_string.split('\n').length - 1);
8+
},
9+
error: (jqXHR, textStatus, errorThrown) => {
10+
reject(textStatus);
11+
},
12+
});
13+
});
14+
15+
linesOfCodePromise.then(
16+
data => {
17+
return data;
18+
},
19+
error => {
20+
console.log(error);
21+
return -1;
22+
}
23+
);
24+
};

linguist.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var linguistPromise = new Promise( (resolve, reject) => {
1313

1414
var convertLinguistJsonArrayToObject = jsonArray => {
1515
var linguistJsonObject = {};
16-
jsonArray.forEach( (jsonObject) => {
16+
jsonArray.forEach( jsonObject => {
1717
linguistJsonObject[jsonObject.language] = jsonObject.extensions;
1818
});
1919
return linguistJsonObject;
@@ -24,7 +24,7 @@ var convertLinguistDataToJson = linguistData => {
2424
var jsonData = [];
2525
var flag = false;
2626
var flag2 = false;
27-
linguistLines.forEach( (linguistLine) => {
27+
linguistLines.forEach( linguistLine => {
2828
if(flag && !linguistLine.startsWith(" ")) flag = false;
2929
else if(flag) {
3030
if(linguistLine.startsWith(" extensions:")) flag2 = true;

traverseDirectory.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ var gitDirectoryScrapper = directoryUrl => {
2424
}
2525
);
2626
};
27-
28-
gitDirectoryScrapper("https://api.github.com/repos/Ankit-22/AutoConnect/contents/");

0 commit comments

Comments
 (0)