npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parse-git-commit

v0.1.3

Published

An extensible parser for a single commit message that follows Conventional Commits v1 specification

Downloads

10

Readme

parse-git-commit npm version github release License

An extensible parser for a single commit message that follows Conventional Commits v1 specification

You might also be interested in hela or in the other related projects.

Quality Assurance :100:

bitHound Deps Code Style Standard Linux Build Code Coverage bitHound Score bitHound Deps Dependencies Status

If you have any how-to kind of questions, please read Code of Conduct and join the chat rooms or open an issue.
You may also read the Contributing Guide. There, beside "How to contribute?", we describe everything stated by the badges.

tunnckoCore support Code Format Prettier Node Security Status Conventional Commits Semantic Release Node Version Required Renovate App Status

All Contributors Spec Make A Pull Request Newsletter Subscribe PayPal Author Support Share Love Tweet NPM Downloads Weekly NPM Downloads Monthly NPM Downloads Total

Table of Contents

(TOC generated by verb using markdown-toc)

Install

This project requires Node.js v8 or above. Install it using yarn v1 or above / npm v5 or above.

$ yarn add parse-git-commit

API

Review carefully the provided examples and the working tests.

const parseGitCommit = require('parse-git-commit');

const commitMsg1 = `feat(ng-list): Allow custom separator
bla bla bla

BREAKING CHANGE: some breaking change.
Thanks @foobar
`;

const commit = parseGitCommit(commitMsg1);
console.log(commit);
// => { type: 'feat',
//   scope: 'ng-list',
//   subject: 'Allow custom separator',
//   header: 'feat(ng-list): Allow custom separator',
//   body: 'bla bla bla',
//   footer: 'BREAKING CHANGE: some breaking change.\nThanks @stevemao' }

It is also extensible if you pass function as second argument, so you can add more properties to the end object.

For example adding increment and mentions properties like following. Notice that the increment property here is "major" because it detects "BREAKING CHANGE:" somewhere in the commit.

That's cool and can be combined with the semver's .inc method like semver.inc('1.1.0', commit.increment)

const commit = parseGitCommit(commitMsg1, (commit) => {
  const withIncrement = incrementMapper(commit);
  const withMentions = mentionsMapper(commit);

  return Object.assign({}, commit, withIncrement, withMentions);
});

console.log(commit);
// => { type: 'feat',
//   scope: 'ng-list',
//   subject: 'Allow custom separator',
//   header: 'feat(ng-list): Allow custom separator',
//   body: 'bla bla bla',
//   footer: 'BREAKING CHANGE: some breaking change.\nThanks @stevemao, @foobar',
//   increment: 'major',
//   isBreaking: true,
//   mentions: ['stevemao', 'foobar'] }

detects if commit is patch, minor or major type

function incrementMapper (commit) {
  const isBreaking = isBreakingChange(commit);
  let increment = null;

  if (/fix|bugfix|patch/.test(commit.type)) {
    increment = 'patch';
  }
  if (/feat|feature|minor/.test(commit.type)) {
    increment = 'minor';
  }
  if (/break|breaking|major/.test(commit.type) || isBreaking) {
    increment = 'major';
  }

  return { increment, isBreaking };
}

function isBreakingChange ({ subject, body, footer }) {
  const re = 'BREAKING CHANGE:';
  return subject.includes(re) || body.includes(re) || footer.includes(re);
}

Collects all mentions from subject, body and footer into one single array that will be added to the end "commit" object

const collectMentions = require('collect-mentions');

function mentionsMapper ({ subject, body, footer }) {
  const mentions = []
    .concat(collectMentions(subject))
    .concat(collectMentions(body))
    .concat(collectMentions(footer));

  return { mentions };
}

back to top

Related Projects

Some of these projects are used here or were inspiration for this one, others are just related. So, thanks for your existance!

back to top

Contributing

Please read the Contributing Guide and Code of Conduct documents for advices.
For bugs reports and feature requests, please create an issue or join us at our Flock chat rooms.

Contributors

Thanks to the hard work of these wonderful people this project is alive and it also follows the all-contributors specification.
Pull requests, stars and all kind of contributions are always welcome.

Users

You can see who uses parse-git-commit in the USERS.md file. Please feel free adding this file if it not exists.
If you or your organization are using this project, consider adding yourself to the list of users. Thank You!

License

Copyright (c) 2017-present, Charlike Mike Reagent <[email protected]>.
Released under the Apache-2.0 License.


This file was generated by verb-generate-readme, v0.6.0, on November 14, 2017.
Project scaffolded and managed with hela.