JavaScript / ECMAScript

Semantic Commit Message in JS

Validate Conventional Commits format: type(scope)!: description.

Try it in the JS tester →

Pattern

regexJS
^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9\-]+\))?(!)?:\s.+   (flags: i)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\\([a-z0-9\\-]+\\))?(!)?:\\s.+", "i");
const input = "feat(auth): add OAuth2 login";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

The first group captures the commit type from the allowed list. (\([a-z0-9\-]+\))? optionally captures a scope in parentheses. (!)? captures a breaking change marker. :\s requires a colon and space before the description. The i flag makes types case-insensitive.

Examples

Input

feat(auth): add OAuth2 login

Matches

  • feat(auth): add OAuth2 login

Input

fix!: correct null pointer in parser

Matches

  • fix!: correct null pointer in parser

Input

random commit message

No match

Same pattern, other engines

← Back to Semantic Commit Message overview (all engines)