Package Exports
- parse-commit-message
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-commit-message) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
parse-commit-message

Extensible parser for git commit messages following Conventional Commits Specification
Please consider following this project's author, Charlike Mike Reagent, and ⭐ the project to show your ❤️ and support.
If you have any how-to kind of questions, please read the Contributing Guide and Code of Conduct documents.
For bugs reports and feature requests, please create an issue or ping
@tunnckoCore at Twitter.
Project is semantically & automatically published with new-release on CircleCI and released by New Release GitHub App.
Table of Contents
- Install
- Type definitions
- API
- See Also
- Contributing
- License
(TOC generated by verb using markdown-toc)
Install
This project requires Node.js ^8.11.0 || >=10.13.0. Install it using
yarn or npm.
We highly recommend to use Yarn when you think to contribute to this project.
$ yarn add parse-commit-messageType definitions
For TypeScript support, please consider sending a PR here (adding src/index.d.ts)
or inform us when you PR to the DefinitelyTyped.
For FlowType support, PR adding .js.flow files in the src/ for every respective file.
Header
type Header = {
type: string;
scope?: string | null;
subject: string;
};The scope may exist or not. When exist it should be non-empty string.
Commit
type Commit = {
header: Header;
body?: string | null;
footer?: string | null;
increment?: string;
isBreaking?: boolean;
mentions?: Array<Mention>;
};Note: It may also include properties set by the plugins - the isBreaking, increment and mentions
are such. They are there when you apply the increment and mentions plugins.
See .applyPlugins and .plugins.
Mention
type Mention = {
handle: string;
mention: string;
index: number;
};See collect-mentions for more.
API
Generated using docks.
src/commit.js
.parseCommit
Receives a full commit message string and parses it into an Commit object
and returns it.
The parse* methods are not doing any checking and validation,
so you may want to pass the result to validateHeader or checkHeader,
or to validateHeader with ret option set to true.
Params
commit{string} a message like'fix(foo): bar baz\n\nSome awesome body!'
Returns
Commita standard object like{ header: Header, body?, footer? }
.stringifyCommit
Receives a Commit object, validates it using validateCommit,
builds a "commit" string and returns it.
Params
header{Commit} aCommitobject like{ header: Header, body?, footer? }
Returns
stringa commit nessage stirng like'fix(foo): bar baz'
.validateCommit
Validates given Commit object and returns boolean.
You may want to set ret to true return an object instead of throwing.
Params
header{Commit} aCommitlike{ header: Header, body?, footer? }[ret]{boolean} to return result instead of throwing, defaultfalse
Returns
undefinedifretistruethen returns{ value, error }object, wherevalueisCommitanderrora standardError
.checkCommit
Receives a Commit and checks if it is valid.
Params
header{Commit} aCommitlike{ header: Header, body?, footer? }
Returns
Commitreturns the same as given if no problems, otherwise it will throw.
src/header.js
.parseHeader
Parses given header string into an header object.
The parse* methods are not doing any checking and validation,
so you may want to pass the result to validateHeader or checkHeader,
or to validateHeader with ret option set to true.
Params
header{string} a header stirng like'fix(foo): bar baz'
Returns
HeaderaHeaderobject like{ type, scope?, subject }
.stringifyHeader
Receives a header object, validates it using validateHeader,
builds a "header" string and returns it.
Params
header{Header} aHeaderobject like{ type, scope?, subject }
Returns
stringa header stirng like'fix(foo): bar baz'
.validateHeader
Validates given header object and returns boolean.
You may want to pass ret to return an object instead of throwing.
Params
header{Header} aHeaderobject like{ type, scope?, subject }[ret]{boolean} to return result instead of throwing, defaultfalse
Returns
undefinedifretistruethen returns{ value, error }object, wherevalueisHeaderanderrora standardError
.checkHeader
Receives a Header and checks if it is valid.
Params
header{Header} aHeaderobject like{ type, scope?, subject }
Returns
Headerreturns the same as given if no problems, otherwise it will throw.
src/index.js
.applyPlugins
Apply a set of plugins over all of the given commits.
A plugin is a simple function passed with Commit object,
which may be returned to modify and set additional properties
to the Commit object.
The commits should be coming from parse, validate (with ret option)
or the check methods. It does not do checking and validation.
Params
plugins{Array<Function>} a simple function like(commit) => {}commits{string|object|array} a value which should already be gone throughparse
Returns
Array<Commit>plus the modified or added properties from each function inplugins
.plugins
An array which includes mentions and increment built-in plugins.
The mentions is an array of objects. Basically what's returned from
the collect-mentions package.
Examples
import { plugins, applyPlugins, parse } from 'parse-commit-message';
console.log(plugins); // => [mentions, increment]
console.log(plugins[0]); // => [Function mentions]
console.log(plugins[0]); // => [Function increment]
const cmts = parse([
'fix: foo @bar @qux haha',
'feat(cli): awesome @tunnckoCore feature\n\nSuper duper baz!'
'fix: ooh\n\nBREAKING CHANGE: some awful api change'
]);
const commits = applyPlugins(plugins, cmts);
console.log(commits);
// => [
// {
// header: { type: 'fix', scope: '', subject: 'foo bar baz' },
// body: '',
// footer: '',
// increment: 'patch',
// isBreaking: false,
// mentions: [
// { handle: '@bar', mention: 'bar', index: 8 },
// { handle: '@qux', mention: 'qux', index: 13 },
// ]
// },
// {
// header: { type: 'feat', scope: 'cli', subject: 'awesome feature' },
// body: 'Super duper baz!',
// footer: '',
// increment: 'minor',
// isBreaking: false,
// mentions: [
// { handle: '@tunnckoCore', mention: 'tunnckoCore', index: 18 },
// ]
// },
// {
// header: { type: 'fix', scope: '', subject: 'ooh' },
// body: 'BREAKING CHANGE: some awful api change',
// footer: '',
// increment: 'major',
// isBreaking: true,
// mentions: [],
// },
// ].mappers
An object (named set) which includes mentions and increment built-in plugins.
Examples
import { mappers, applyPlugins, parse } from 'parse-commit-message';
console.log(mappers); // => { mentions, increment }
console.log(mappers.mentions); // => [Function mentions]
console.log(mappers.increment); // => [Function increment]
const flat = true;
const parsed = parse('fix: bar', flat);
console.log(parsed);
// => {
// header: { type: 'feat', scope: 'cli', subject: 'awesome feature' },
// body: 'Super duper baz!',
// footer: '',
// }
const commit = applyPlugins([mappers.increment], parsed);
console.log(commit)
// => [{
// header: { type: 'feat', scope: 'cli', subject: 'awesome feature' },
// body: 'Super duper baz!',
// footer: '',
// increment: 'patch',
// }]src/main.js
.parse
Receives and parses a single or multiple commit message(s) in form of string, object, array of strings, array of objects or mixed.
Params
commits{string|object|array} a value to be parsed into an object likeCommittype[flat]{boolean} if the returned result length is 1, then returns the first item
Returns
Array<Commit>ifflat: true, returns aCommit
.stringify
Receives a Commit object, validates it using validate,
builds a "commit" message string and returns it.
This method does checking and validation too, so if you pass a string, it will be parsed and validated, and after that turned again to string.
Params
commit{string|object|array} aCommitobject, or anything that can be passed tocheck[flat]{boolean} if the returned result length is 1, then returns the first item
Returns
Array<string>an array of commit strings like'fix(foo): bar baz', ifflat: true, returns astring
.validate
Validates a single or multiple commit message(s) in form of string,
object, array of strings, array of objects or mixed.
You may want to pass ret to return an object instead of throwing.
Params
commits{string|object|array} a value to be parsed & validated into an object likeCommittype[ret]{boolean} to return result instead of throwing, defaultfalse
Returns
undefinedifretistruethen returns{ value, error }object, wherevalueisCommit|Array<Commit>anderrora standardError
.check
Receives a single or multiple commit message(s) in form of string, object, array of strings, array of objects or mixed.
Params
commits{string|object|array} a value to be parsed & validated into an object likeCommittype[flat]{boolean} if the returned result length is 1, then returns the first item
Returns
Array<Commit>returns the same as given if no problems, otherwise it will throw; ifflat: true, returns aCommit
src/plugins/increment.js
increment
A plugin that adds increment and isBreaking properties
to the commit. It is already included in the plugins named export,
and in mappers named export.
See the .plugins and .mappers examples.
Params
commit{Commit} a standardCommitobject
Returns
Commitplus{ increment: string, isBreaking: boolean }
src/plugins/mentions.js
mentions
A plugin that adds mentions array property to the commit.
It is already included in the plugins named export,
and in mappers named export.
Basically each entry in that array is an object,
directly returned from the collect-mentions.
See the .plugins and .mappers examples.
Params
commit{Commit} a standardCommitobject
Returns
Commitplus{ mentions: Array<Mention> }
See Also
Some of these projects are used here or were inspiration for this one, others are just related. So, thanks for your existance!
- @tunnckocore/config: All the configs for all the tools, in one place | homepage
- @tunnckocore/create-project: Create and scaffold a new project, its GitHub repository and contents | homepage
- @tunnckocore/execa: Thin layer on top of execa that allows executing multiple commands in… more | homepage
- @tunnckocore/scripts: Universal and minimalist scripts & tasks runner. | homepage
- @tunnckocore/update: Update a repository with latest templates from
charlike. | homepage - asia: Blazingly fast, magical and minimalist testing framework, for Today and Tomorrow | homepage
- charlike: Small, fast and streaming project scaffolder with support for hundreds of template… more | homepage
- docks: Extensible system for parsing and generating documentation. It just freaking works! | homepage
- gitcommit: Lightweight and joyful
git commitreplacement. Conventional Commits compliant. | homepage
Contributing
Follow the Guidelines
Please read the Contributing Guide and Code of Conduct documents for advices.
For bugs reports and feature requests, please create an issue or ping
@tunnckoCore at Twitter.
Support the project
Become a Partner or Sponsor? 💵 Check the Partner, Sponsor or Omega-level tiers! 🎉 You can get your company logo, link & name on this file. It's also rendered on package page in npmjs.com and yarnpkg.com sites too! 🚀
Not financial support? Okey! Pull requests, stars and all kind of contributions are always welcome. ✨
OPEN Open Source
This project is following OPEN Open Source model
Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is built on collective efforts and it's not strongly guarded by its founders.
There are a few basic ground-rules for its contributors
- Any significant modifications must be subject to a pull request to get feedback from other contributors.
- Pull requests to get feedback are encouraged for any other trivial contributions, but are not required.
- Contributors should attempt to adhere to the prevailing code-style and development workflow.
Wonderful Contributors
Thanks to the hard work of these wonderful people this project is alive! It follows the
all-contributors specification.
Don't hesitate to add yourself to that list if you have made any contribution! ;) See how,
here.
Charlike Mike Reagent 💻 📖 💬 👀 🔍 |
|---|
Consider showing your support to them. 💖
License
Copyright (c) 2017-present, Charlike Mike Reagent <mameto2011@gmail.com> & contributors.
Released under the Apache-2.0 License.