commit-parser
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

commit-parser

npm version npm downloads

A tiny parser for conventional commits that extracts metadata like type, scope, breaking changes and references.

Installation

npm install commit-parser

Usage

import { getCommits, parseCommit, parseRawCommit } from "commit-parser";

// get and parse all commits between two git references
const commits = getCommits("v1.0.0", "v2.0.0");
// or get commits up to a specific reference
const recentCommits = getCommits(undefined, "main");

// parse a raw git commit string
const rawCommit = "abc123|feat: add new feature|John Doe|john@example.com|1609459200";
const parsedRawCommit = parseRawCommit(rawCommit);
// {
//   shortHash: "abc123",
//   message: "feat: add new feature",
//   author: {
//     name: "John Doe",
//     email: "john@example.com"
//   },
//   data: "1609459200",
//   body: ""
// }

// parse with additional conventional commit metadata
const parsedCommit = parseCommit(parsedRawCommit);
// {
//   shortHash: "abc123",
//   message: "feat: add new feature",
//   authors: [{
//     name: "John Doe",
//     email: "john@example.com"
//   }],
//   data: "1609459200",
//   body: "",
//   type: "feat",
//   scope: "",
//   description: "add new feature",
//   isBreaking: false,
//   isConventional: true,
//   references: []
// }

// handles breaking changes
const breakingCommit = parseRawCommit("def456|feat!: breaking change|Jane Doe|jane@example.com|1609459200");
const parsedBreaking = parseCommit(breakingCommit);
// isBreaking will be true

// extracts PR and issue references
const commitWithRefs = parseRawCommit("ghi789|fix: resolve crash, closes #123 (#456)|Dev User|dev@example.com|1609459200");
const parsedRefs = parseCommit(commitWithRefs);
// references will contain [{ type: "pull-request", value: "#456" }, { type: "issue", value: "#123" }]

// handles co-authors
const coAuthoredCommit = parseRawCommit("jkl012|feat: collaborative feature|Main Author|main@example.com|1609459200|Some description\n\nCo-authored-by: Contributor One <contrib1@example.com>");
const parsedCoAuthored = parseCommit(coAuthoredCommit);
// authors will contain both the main author and co-author

📄 License

Published under MIT License.

Acknowledgements

This project is using code from unjs/changelogen, which is licensed under the [MIT License](

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.4.0
7latest

Version History

VersionDownloads (Last 7 Days)Published
0.4.0
7
0.3.1
0
0.3.0
0
0.2.0
0
0.1.0
0

Package Sidebar

Install

npm i commit-parser

Weekly Downloads

7

Version

0.4.0

License

MIT

Unpacked Size

11.4 kB

Total Files

5

Last publish

Collaborators

  • luxass