forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.js
33 lines (30 loc) · 840 Bytes
/
format.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
28
29
30
31
32
33
import chalk from 'chalk';
import entries from 'lodash/toPairs';
export default format;
/**
* Get formatted commit message
* @param {object} input object containing structured results
* @param {boolean} debug show debug information in commit message
* @return {string} formatted debug message
*/
function format(input, debug = false) {
const results = debug
? entries(input).reduce((registry, item) => {
const [name, value] = item;
registry[name] =
value === null ? chalk.grey(`<${name}>`) : chalk.bold(value);
return registry;
}, {})
: input;
// Return formatted string
const {type, scope, subject, body, footer} = results;
return [
`${type}${scope ? '(' : ''}${scope}${scope ? ')' : ''}${
type || scope ? ':' : ''
} ${subject}`,
body,
footer
]
.filter(Boolean)
.join('\n');
}