-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (30 loc) · 1.22 KB
/
index.ts
File metadata and controls
37 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { regEx } from '../../../util/regex.ts';
import type { GenericVersion } from '../generic.ts';
import { GenericVersioningApi } from '../generic.ts';
import type { VersioningApi } from '../types.ts';
export const id = 'redhat';
export const displayName = 'Red Hat';
export const urls = [];
export const supportsRanges = false;
const pattern = regEx(
/^v?(?<major>\d+)(?:\.(?<minor>\d+))?(?:\.(?<patch>\d+))?(\.GA)?(?:-(?<releaseMajor>\d+)(?:\.(?<releaseMinor>\d+))?)?$/,
);
class RedhatVersioningApi extends GenericVersioningApi {
protected _parse(version: string): GenericVersion | null {
const matches = pattern.exec(version)?.groups;
if (!matches) {
return null;
}
const { major, minor, patch, releaseMajor, releaseMinor } = matches;
const release = [
Number.parseInt(major),
typeof minor === 'undefined' ? 0 : Number.parseInt(minor),
typeof patch === 'undefined' ? 0 : Number.parseInt(patch),
typeof releaseMajor === 'undefined' ? 0 : Number.parseInt(releaseMajor),
typeof releaseMinor === 'undefined' ? 0 : Number.parseInt(releaseMinor),
];
return { release, prerelease: '' };
}
}
export const api: VersioningApi = new RedhatVersioningApi();
export default api;