-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathindex.ts
More file actions
50 lines (37 loc) · 1.26 KB
/
index.ts
File metadata and controls
50 lines (37 loc) · 1.26 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
38
39
40
41
42
43
44
45
46
47
48
49
50
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 = 'azure-rest-api';
export const displayName = 'azure-rest-api';
export const urls = [
'https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#api-versioning',
];
export const supportsRanges = false;
const AZURE_REST_API_VERSION_REGEX = regEx(
/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})(?<prerelease>-[a-z]+)?$/,
);
class AzureRestApiVersioningApi extends GenericVersioningApi {
protected _parse(version: string): GenericVersion | null {
if (!version) {
return null;
}
const matchGroups = AZURE_REST_API_VERSION_REGEX.exec(version)?.groups;
if (!matchGroups) {
return null;
}
const { year, month, day, prerelease } = matchGroups;
return {
release: [parseInt(`${year}${month}${day}`, 10), 0, 0],
prerelease,
};
}
protected override _compare(_version: string, _other: string): number {
if (_version === _other) {
return 0;
}
return _version > _other ? 1 : -1;
}
}
export const api: VersioningApi = new AzureRestApiVersioningApi();
export default api;