The Node.js® Website
1import semVer from 'semver';
2
3/**
4 * Returns the URL of the Node.js changelog for the specified version.
5 *
6 * @param version The version of Node.js to get the changelog for.
7 * @returns The URL of the Node.js changelog for the specified version.
8 */
9export const getNodejsChangelog = (version: string): string => {
10 const changelogsUrl =
11 'https://github.com/nodejs/node/blob/main/doc/changelogs';
12
13 // Parse the version string and get the major and minor versions
14 const cleanVersion = semVer.clean(version) as string;
15 const majorVersion = semVer.major(cleanVersion);
16 const minorVersion = semVer.minor(cleanVersion);
17
18 // Determine the URL of the changelog based on the version
19 if (majorVersion >= 4) {
20 return `${changelogsUrl}/CHANGELOG_V${majorVersion}.md#${cleanVersion}`;
21 }
22
23 if (majorVersion >= 1) {
24 return `${changelogsUrl}/CHANGELOG_IOJS.md#${cleanVersion}`;
25 }
26
27 if (minorVersion === 12 || minorVersion === 10) {
28 return `${changelogsUrl}/CHANGELOG_V${majorVersion}${minorVersion}.md#${cleanVersion}`;
29 }
30
31 return `https://github.com/nodejs/node-v0.x-archive/blob/${version}/ChangeLog`;
32};