@hyperfrontend/versioning/commits/parseparse
Conventional-commit message parser: header, body, and footers parsed without regex.
parseConventionalCommit is the main entry point — given a raw commit message it returns a ConventionalCommit (or throws if the format is invalid). isConventionalCommit is the non-throwing predicate for guard checks. The lower-level helpers (parseHeader, parseBody, parseFooters) are exposed for callers that need to operate on individual sections of a message; each returns a focused ParsedHeader / ParsedBody / ParsedFooters shape. All parsing is character-by-character with explicit state transitions, giving O(n) behavior and no catastrophic-backtracking risk; input length is capped at 10 KB.
API Reference
ƒ Functions
Parameters
| Name | Type | Description |
|---|---|---|
§message | string | The commit message to check |
Returns
booleanExample
Checking if a message is a conventional commit
isConventionalCommit('feat(auth): add OAuth login')
// => true
isConventionalCommit('WIP: still working on this')
// => false
isConventionalCommit('fix: resolve bug')
// => trueThe body starts after the first blank line and continues until we encounter a footer (key: value or key #value pattern) or end of message.
Parameters
Returns
ParsedBodyExample
Parsing commit body
const lines = [
'feat: add login',
'',
'Implements OAuth flow.',
'',
'Refs: #123'
]
const result = parseBody(lines, 1)
// => { body: 'Implements OAuth flow.', endIndex: 4 }Parameters
| Name | Type | Description |
|---|---|---|
§message | string | The complete commit message |
Returns
ConventionalCommitExample
Parsing a complete conventional commit message
parseConventionalCommit('feat(auth): add login\n\nImplements OAuth.\n\nRefs: #123')
// => {
// type: 'feat',
// scope: ['auth'],
// subject: 'add login',
// body: 'Implements OAuth.',
// footers: [{ key: 'Refs', value: '#123', separator: ':' }],
// breaking: false,
// raw: '...'
// }Supports comma-separated multi-scope headers such as
feat(a,b): x which produce a multi-element scope array. Single-scope headers produce a one-element array, and scopeless headers produce an empty array.Parameters
| Name | Type | Description |
|---|---|---|
§line | string | The first line of the commit message |
Returns
ParsedHeaderExample
Parsing conventional commit headers
parseHeader('feat(auth): add OAuth login')
// => { type: 'feat', scope: ['auth'], subject: 'add OAuth login', breaking: false }
parseHeader('fix!: critical security patch')
// => { type: 'fix', scope: [], subject: 'critical security patch', breaking: true }
parseHeader('feat(versioning,questions): add searchable select')
// => { type: 'feat', scope: ['versioning', 'questions'], subject: 'add searchable select', breaking: false }