mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Refactored emoji filtering to only loop once
Small perf improvment, also easier to read now because we can use 0 index which is more obvious as to what we're doing
This commit is contained in:
parent
c681b8e9be
commit
df57b8c944
@ -1,26 +1,32 @@
|
||||
const emojiRegex = require('emoji-regex');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports.filterEmojiCommits = (content) => {
|
||||
if (!_.isArray(content)) {
|
||||
throw new Error('Expected array of strings.');
|
||||
}
|
||||
|
||||
const timestamp = /^[0-9]{10} /;
|
||||
const separator = /^\* /;
|
||||
const hash = /^\[[0-9a-f]{9}\]/;
|
||||
const url = /^\(https?:\/\/[^)]+\) /;
|
||||
|
||||
return content.map((line) => {
|
||||
return '* ' + line
|
||||
const getCommitMessageFromLine = line => line
|
||||
.replace(timestamp, '')
|
||||
.replace(separator, '')
|
||||
.replace(hash, '')
|
||||
.replace(url, '');
|
||||
}).filter((line) => {
|
||||
const match = emojiRegex().exec(line);
|
||||
return match && match.index === 2;
|
||||
});
|
||||
|
||||
module.exports.filterEmojiCommits = (content) => {
|
||||
if (!_.isArray(content)) {
|
||||
throw new Error('Expected array of strings.');
|
||||
}
|
||||
|
||||
return content.reduce((emojiLines, currentLine) => {
|
||||
const commitMessage = getCommitMessageFromLine(currentLine);
|
||||
|
||||
const match = emojiRegex().exec(commitMessage);
|
||||
if (match && match.index === 0) {
|
||||
return emojiLines.concat(`* ${commitMessage}`);
|
||||
}
|
||||
|
||||
return emojiLines;
|
||||
}, []);
|
||||
};
|
||||
|
||||
module.exports.checkMissingOptions = (options = {}, ...requiredFields) => {
|
||||
|
Loading…
Reference in New Issue
Block a user