GitLint Parser for Node.js

1.1.0 · maintenance · verified Sun Apr 19

Gitlint is a widely used linter for Git commit messages, originally implemented in Python, that enforces conventions such as the Conventional Commits specification, ensuring consistent and readable commit history across projects. The `gitlint-parser-node` package is a JavaScript library designed to parse these commit messages specifically within a Node.js environment, adhering to the core parsing logic and conventions used by gitlint. This enables Node.js applications and tooling to programmatically process, analyze, and extract structured information from git commit messages in a compatible manner, without needing to invoke the Python-based gitlint CLI directly. It supports parsing the various components of a commit message, such as type, scope, subject, body, and footers. The current stable version is 1.1.0. Given its focused utility and version history, it appears to be in a maintenance phase, providing a stable foundation for projects requiring gitlint-compatible commit message parsing in JavaScript.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `parse` function to extract structured data from a conventional git commit message.

import { parse } from 'gitlint-parser-node';

const commitMessage = `feat(parser): add commit message parsing logic\n\nThis commit introduces the initial parsing functionality for git commit messages, adhering to conventional commit guidelines.\n\n- Parses type, scope, subject\n- Extracts body and footers\n\nBREAKING CHANGE: The initial API might change in future minor versions.\nCloses #123, #456`;

try {
  const parsedCommit = parse(commitMessage);
  console.log('Parsed Commit Message:');
  console.log(`Type: ${parsedCommit.type}`);
  console.log(`Scope: ${parsedCommit.scope}`);
  console.log(`Subject: ${parsedCommit.subject}`);
  console.log(`Header: ${parsedCommit.header}`);
  console.log(`Body: ${parsedCommit.body}`);
  console.log('Footers:');
  parsedCommit.footers.forEach(footer => {
    console.log(`  ${footer.token}: ${footer.value}`);
  });
} catch (error) {
  console.error('Failed to parse commit message:', error.message);
}

view raw JSON →