forked from quizlet/ts-migration
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstripComments.js
27 lines (27 loc) · 946 Bytes
/
stripComments.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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripComments = void 0;
function stripComments(code, comments) {
const codeSplitByLine = code.split("\n");
let count = 0;
const res = codeSplitByLine.reduce((acc, line) => {
if (comments.some(c => line.includes(c))) {
const matchedComment = comments.find(c => line.includes(c));
const matchedIndex = line.indexOf(matchedComment);
if (matchedIndex > 0) {
const firstPartOfLine = line.slice(0, matchedIndex);
if (firstPartOfLine.match(/\S/)) {
acc.push(firstPartOfLine);
count = count + 1;
}
}
}
else {
acc.push(line);
}
return acc;
}, []);
return [res.join("\n"), count];
}
exports.stripComments = stripComments;
//# sourceMappingURL=stripComments.js.map