Node & Deno package to parse and generate changelogs
Installations
npm install @slavkojos/keep-a-changelog
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.18.0
NPM Version
8.19.2
Score
73.8
Supply Chain
81.1
Quality
76
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
Spicy-Sparks
Download Statistics
Total Downloads
1,965
Last Day
2
Last Week
9
Last Month
43
Last Year
310
GitHub Statistics
140 Commits
1 Branches
1 Contributors
Bundle Size
42.04 kB
Minified
13.75 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.2
Package Id
@slavkojos/keep-a-changelog@1.1.2
Unpacked Size
103.01 kB
Size
32.55 kB
File Count
29
NPM Version
8.19.2
Node Version
16.18.0
Publised On
28 Mar 2023
Total Downloads
Cumulative downloads
Total Downloads
1,965
Last day
-33.3%
2
Compared to previous day
Last week
-66.7%
9
Compared to previous week
Last month
104.8%
43
Compared to previous month
Last year
-81.3%
310
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
Changelog
Keep a Changelog library for Node & Deno
Deno package to parse and generate changelogs following the keepachangelog format.
Usage in Node
1import { parser } from "keep-a-changelog"; 2import fs from "fs"; 3 4//Parse a changelog file 5const changelog = parser(fs.readFileSync("CHANGELOG.md", "UTF-8")); 6 7//Generate the new changelog string 8console.log(changelog.toString());
Usage in Deno
1import { parser } from "https://deno.land/x/changelog@v2.0.0/mod.ts"; 2 3//Parse a changelog file 4const changelog = parser(await Deno.readTextFile("CHANGELOG.md")); 5 6//Generate the new changelog string 7console.log(changelog.toString());
Create a new changelog
1import { 2 Changelog, 3 Release, 4} from "https://deno.land/x/changelog@v2.0.0/mod.ts"; 5 6const changelog = new Changelog("My project") 7 .addRelease( 8 new Release("0.1.0", "2017-12-06") 9 .added("New awesome feature") 10 .added("New other awesome feature") 11 .fixed("Bug #3") 12 .removed("Drop support for X"), 13 ) 14 .addRelease( 15 new Release("0.2.0", "2017-12-09") 16 .security("Fixed security vulnerability") 17 .deprecated("Feature X is deprecated"), 18 ); 19 20console.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:
1const changelog = new Changelog(); 2changelog.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
:
1const changelog = new Changelog(); 2changelog.tagNameBuilder = (release) => `version-${release.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:
1class CustomRelease extends Release { 2 constructor(version, date, description) { 3 super(version, date, description); 4 // add whatever types you want - in lowercase 5 const newChangeTypes = [ 6 ["maintenance", []], 7 ]; 8 9 this.changes = new Map([...this.changes, ...newChangeTypes]); 10 } 11 // for convenience, add a new method to add change of type 'maintanance' 12 maintenance(change) { 13 return this.addChange("maintenance", change); 14 } 15}
And once you want to use the parser:
1const releaseCreator = (ver, date, desc) => new CustomRelease(ver, date, desc);
2const 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:
1deno install --allow-read --allow-write --name changelog https://deno.land/x/changelog/bin.ts
Node:
1npm install keep-a-changelog -g
Run the script:
1changelog
To use other file name:
1changelog --file=History.md
To generate an empty new CHANGELOG.md file:
1changelog --init
You can release automatically the latest "Unreleased" version:
1changelog --release
And return the latest released version:
1changelog --latest-release 2> 0.3.1
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. |
--quiet | Do not output error messages |
No vulnerabilities found.
No security vulnerabilities found.