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