npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keep-a-changelog

v2.5.3

Published

Node package to parse and generate changelogs following the [keepachangelog](https://keepachangelog.com/) format.

Downloads

21,099

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/[email protected]/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/[email protected]/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 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}`;

Custom compare links

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

Available options:

| Option | Description | | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --format | The output format for the generated markdown. It can be markdownlint or compact. The default value is compact. | | --file | The markdown file of the changelog. The default value is CHANGELOG.md. | | --url | The base url used to build the diff urls of the different releases. It is taken from the existing diff urls in the markdown. If no urls are found, try to catch it using the url of the git remote repository. | | --https | Set to false to use http instead https in the url (--https=false). | | --init | Init a new empty changelog file. | | --latest-release | Print the latest release version. | | --release | Updated the latest unreleased version with the current date. Use --release=X.Y.Z to set a number if the version doesn't have it. | | --create | Create a new Unreleased version. Use --create=X.Y.Z to specify a version number or just --create for a version without number. | | --quiet | Do not output error messages | | --head | Customize the head reference |