# conventional-commits-parser
[![ESM-only package][package]][package-url]
[![NPM version][npm]][npm-url]
[![Node version][node]][node-url]
[![Dependencies status][deps]][deps-url]
[![Install size][size]][size-url]
[![Build status][build]][build-url]
[![Coverage status][coverage]][coverage-url]
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
[package-url]: https://nodejs.org/api/esm.html
[npm]: https://img.shields.io/npm/v/conventional-commits-parser.svg
[npm-url]: https://npmjs.com/package/conventional-commits-parser
[node]: https://img.shields.io/node/v/conventional-commits-parser.svg
[node-url]: https://nodejs.org
[deps]: https://img.shields.io/librariesio/release/npm/conventional-commits-parser
[deps-url]: https://libraries.io/npm/conventional-commits-parser/tree
[size]: https://packagephobia.com/badge?p=conventional-commits-parser
[size-url]: https://packagephobia.com/result?p=conventional-commits-parser
[build]: https://img.shields.io/github/actions/workflow/status/conventional-changelog/conventional-changelog/tests.yaml?branch=master
[build-url]: https://github.com/conventional-changelog/conventional-changelog/actions
[coverage]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
[coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
Parse raw conventional commits.
Install
•
Usage
•
Message format
•
API
•
CLI
## Install
```bash
# pnpm
pnpm add conventional-commits-parser
# yarn
yarn add conventional-commits-parser
# npm
npm i conventional-commits-parser
```
## Usage
```js
import {
CommitParser,
parseCommits,
parseCommitsStream
} from 'conventional-commits-parser'
import { pipeline } from 'stream/promises'
import { Readable } from 'stream'
const rawCommitMessage = 'feat(scope): broadcast $destroy event on scope destruction\nCloses #1'
// to parse raw commit message manually:
const parser = new CommitParser(options)
console.log(parser.parse(rawCommitMessage))
// to parse raw commit messages async iterables:
await pipeline(
[rawCommitMessage],
parseCommits(options),
async function* (parsedCommits) {
for await (const commit of parsedCommits) {
console.log(commit)
}
}
)
// to parse raw commit messages streams:
Readable.from([rawCommitMessage])
.pipe(parseCommitsStream(options))
.on('data', commit => console.log(commit))
```
Parser expects raw commit message. Examples:
```js
'feat(scope): broadcast $destroy event on scope destruction\nCloses #1'
'feat(ng-list): Allow custom separator\nbla bla bla\n\nBREAKING CHANGE: some breaking change.\nThanks @stevemao\n'
```
It will return parsed commit object. Examples:
```js
{
type: 'feat',
scope: 'scope',
subject: 'broadcast $destroy event on scope destruction',
merge: null,
header: 'feat(scope): broadcast $destroy event on scope destruction',
body: null,
footer: 'Closes #1',
notes: [],
references:
[{
action: 'Closes',
owner: null,
repository: null,
issue: '1',
raw: '#1',
prefix: '#'
}],
mentions: [],
revert: null
}
{
type: 'feat',
scope: 'ng-list',
subject: 'Allow custom separator',
merge: null,
header: 'feat(ng-list): Allow custom separator',
body: 'bla bla bla',
footer: 'BREAKING CHANGE: some breaking change.\nThanks @stevemao',
notes:
[{
title: 'BREAKING CHANGE',
text: 'some breaking change.\nThanks @stevemao'
}],
references: [],
mentions: ['stevemao'],
revert: null
}
```
## Conventional Commit Message Format
A minimum input should contain a raw message.
Each commit message consists of a **merge header**, a **header** (mandatory), a **body** and a **footer**. **Mention** (optional) someone using the `@` notation.
```