Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

keep-a-changelog

oscarotero32.7kMIT2.6.1TypeScript support: included

Node package to parse and generate changelogs following the keepachangelog format.

changelog, keepachangelog, parser

readme

Changelog

Keep a Changelog library for Node & Deno

Deno package to parse and generate changelogs following the keepachangelog format.

Usage in Node

import { parser } from "keep-a-changelog";
import fs from "fs";

//Parse a changelog file
const changelog = parser(fs.readFileSync("CHANGELOG.md", "UTF-8"));

//Generate the new changelog string
console.log(changelog.toString());

Usage in Deno

import { parser } from "https://deno.land/x/changelog@v2.2.1/mod.ts";

//Parse a changelog file
const changelog = parser(await Deno.readTextFile("CHANGELOG.md"));

//Generate the new changelog string
console.log(changelog.toString());

Create a new changelog

import {
  Changelog,
  Release,
} from "https://deno.land/x/changelog@v2.2.1/mod.ts";

const changelog = new Changelog("My project")
  .addRelease(
    new Release("0.1.0", "2017-12-06")
      .added("New awesome feature")
      .added("New other awesome feature")
      .fixed("Bug #3")
      .removed("Drop support for X"),
  )
  .addRelease(
    new Release("0.2.0", "2017-12-09")
      .security("Fixed security vulnerability")
      .deprecated("Feature X is deprecated"),
  );

console.log(changelog.toString());

Custom output format

By default, the output format of the markdown is "compact", that removes the space after the headings. You can change it to follow the markdownlint rules:

const changelog = new Changelog();
changelog.format = "markdownlint";

Custom bullet style

By default, the bullet style of the markdown is "-". You can change it to use other styles of bullet points:

const changelog = new Changelog();
changelog.bulletStyle = "*";

Custom tag names

By default, the tag names are v + version number. For example, the tag for the version 2.4.9 is v2.4.9. To change this behavior, set a new tagNameBuilder:

const changelog = new Changelog();
changelog.tagNameBuilder = (release) => `version-${release.version}`;

By default, compare links are build compliant with GitHub format. To change this behavior, set a new compareLinkBuilder:

const changelog = new Changelog();
changelog.url = "https://bitbucket.org/oscarotero/keep-a-changelog";
changelog.compareLinkBuilder = (previous, release) =>
  `${this.url}/branches/compare/${release.version}%0D${previous.version}`;

Custom Change Types

By default and according to the keepachangelog format, the change types are Added, Changed, Deprecated, Removed, Fixed, and Security.

In case you'd like add another type, you need to extend the Release class to support new types. Additionally, you have to tell the parser that it should create instances of your new extended Release in order to parse your changelog correctly.

For example, we would like to add a type Maintenance. Extend the provided Release class:

class CustomRelease extends Release {
  constructor(version, date, description) {
    super(version, date, description);
    // add whatever types you want - in lowercase
    const newChangeTypes = [
      ["maintenance", []],
    ];

    this.changes = new Map([...this.changes, ...newChangeTypes]);
  }
  // for convenience, add a new method to add change of type 'maintanance'
  maintenance(change) {
    return this.addChange("maintenance", change);
  }
}

And once you want to use the parser:

const releaseCreator = (ver, date, desc) => new CustomRelease(ver, date, desc);
const changelog = parser(changelogTextContent, { releaseCreator });

Cli

This library provides the changelog command to normalize the changelog format. It reads the CHANGELOG.md file and override it with the new format:

Install the library as script

Deno:

deno install --allow-read --allow-write -fr --name changelog https://deno.land/x/changelog/bin.ts

Node:

npm install keep-a-changelog -g

Run the script:

changelog

To use other file name:

changelog --file=History.md

To generate an empty new CHANGELOG.md file:

changelog --init

You can release automatically the latest "Unreleased" version:

changelog --release

If your "Unreleased" section has no version, you can specify it as an argument:

changelog --release 2.0.0

And return the latest released version:

changelog --latest-release
> 2.0.0

See available options:

changelog --help

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

2.6.1 - 2025-02-24

Fixed

2.6.0 - 2025-02-22

Added

  • New option --no-v-prefix to generate the tag names without prepending v #43
  • New option --no-sort-releases to disable sorting of releases #51
  • New option --bullet-style for customizing the bullet point character used in unordered lists #48
  • Add Azure DevOps URL support #49
  • New option --combine to combine changes with the same version #50
  • --help, -h flag #45.

Fixed

  • Updated dependencies
  • Skip release creation if it already exists #47

2.5.3 - 2023-11-19

Fixed

  • Improve URL normalization in CLI #42

2.5.2 - 2023-11-09

Fixed

  • Url regex for gitlab links #41

2.5.1 - 2023-11-08

Fixed

  • Url parser for gitlab links #40

2.5.0 - 2023-11-07

Added

  • Automatic detection of github and gitlab urls and build the links accordingly #35
  • New option --head to set the HEAD name #37

Changed

  • Deprecated function compareLinkBuilder, use tagLinkBuilder instead

Fixed

  • Trailing slash of the remote url is now removed #36
  • Updated dependencies

2.4.1 - 2023-10-10

Fixed

  • Breaking changes after updating semver package

2.4.0 - 2023-10-10

Added

  • New function compareLinkBuilder #33.

Fixed

  • Updated dependencies

2.3.0 - 2023-05-25

Added

  • New option --create, to create unreleased versions #31.

Fixed

  • Allow empty values for --release option
  • Updated dependencies

2.2.1 - 2023-01-25

Fixed

  • Allow list elements in the descriptions of releases and changelogs #30.

2.2.0 - 2023-01-18

Added

  • New option format to configure the output option #28.
  • Release.setYanked function #26.

Fixed

  • Removed unnecessary new line after the title #27.

2.1.0 - 2022-04-03

Added

  • Support for [YANKED] releases #25

Fixed

  • Updated dependencies

2.0.1 - 2022-01-09

Fixed

  • Updated deps.
  • release and latest-release args #23.

2.0.0 - 2021-12-08

New version merging Deno and Node code using Deno's dnt package.

Changed

  • Code converted to TypeScript.
  • Added the link of the first version #21.