Skip to content

isConventionalCommit

Checks whether a commit message’s subject line follows the Conventional Commits format constrained by the given options.

Only the first line is inspected — body and footer are ignored.

Available since v2.0.0

import { isConventionalCommit } from '@helpers4/commit';
isConventionalCommit(message: string, options?: ConventionalCommitOptions): boolean
ParameterTypeDescription
messagestringFull commit message or just its subject line.
optionsConventionalCommitOptionsOptional constraints (allowed types/scopes, scope requirement). (optional)

boolean — true when the subject line matches; false otherwise.

Returns true when the first line follows the Conventional Commits format.

isConventionalCommit('feat(api): add endpoint') // => true
isConventionalCommit('hello world') // => false

Reject any commit whose type is not in the supplied allowlist.

isConventionalCommit('chore: x', { types: ['feat', 'fix'] }) // => false
isConventionalCommit('feat: x', { types: ['feat', 'fix'] }) // => true

Options shared by buildConventionalCommitRegex, parseConventionalCommit, and isConventionalCommit to constrain the accepted commit format.

interface ConventionalCommitOptions {
  requireScope?: boolean;
  scopes?: readonly string[];
  types?: readonly string[];
}

View source on GitHub