Refactored line parsing to use regex

Was having issues debugging the index issue, and regex cleans it up a little
This commit is contained in:
Fabien O'Carroll 2019-03-13 15:27:55 +01:00
parent f8f96b49db
commit c681b8e9be

View File

@ -6,22 +6,21 @@ module.exports.filterEmojiCommits = (content) => {
throw new Error('Expected array of strings.');
}
content = content.filter(function (line, index, obj) {
const sqbracket = line.substring(line.indexOf('['), line.indexOf(']') + 1);
const rdbracket = line.substring(line.indexOf('('), line.indexOf(')') + 2);
const contributor = line.substring(line.lastIndexOf('-') - 1, line.length);
// NOTE: modify original line
line = line.replace(sqbracket, '');
line = line.replace(rdbracket, '');
line = line.replace(contributor, '');
obj[index] = line;
const timestamp = /^[0-9]{10} /;
const separator = /^\* /;
const hash = /^\[[0-9a-f]{9}\]/;
const url = /^\(https?:\/\/[^)]+\) /;
return content.map((line) => {
return '* ' + line
.replace(timestamp, '')
.replace(separator, '')
.replace(hash, '')
.replace(url, '');
}).filter((line) => {
const match = emojiRegex().exec(line);
return match && match.index === 2;
});
return content;
};
module.exports.checkMissingOptions = (options = {}, ...requiredFields) => {