0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

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