Skip to content

Commit 2d14985

Browse files
Andymhegazy
Andy
authored andcommitted
semver: Lint and convert to external module (DefinitelyTyped#15124)
1 parent 545f81a commit 2d14985

File tree

3 files changed

+195
-289
lines changed

3 files changed

+195
-289
lines changed

semver/index.d.ts

+143-175
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,154 @@
1-
// Type definitions for semver v5.3.0
1+
// Type definitions for semver 5.3
22
// Project: https://github.com/npm/node-semver
33
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/semver
55

6-
declare namespace SemVerModule {
7-
/**
8-
* Return the parsed version, or null if it's not valid.
9-
*/
10-
function valid(v: string, loose?: boolean): string;
11-
/**
12-
* Returns cleaned (removed leading/trailing whitespace, remove '=v' prefix) and parsed version, or null if version is invalid.
13-
*/
14-
function clean(version: string, loose?: boolean): string;
15-
/**
16-
* Return the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid.
17-
*/
18-
function inc(v: string, release: string, loose?: boolean): string;
19-
/**
20-
* Return the major version number.
21-
*/
22-
function major(v: string, loose?: boolean): number;
23-
/**
24-
* Return the minor version number.
25-
*/
26-
function minor(v: string, loose?: boolean): number;
27-
/**
28-
* Return the patch version number.
29-
*/
30-
function patch(v: string, loose?: boolean): number;
31-
/**
32-
* Returns an array of prerelease components, or null if none exist.
33-
*/
34-
function prerelease(v: string, loose?: boolean): string[];
35-
36-
// Comparison
37-
/**
38-
* v1 > v2
39-
*/
40-
function gt(v1: string, v2: string, loose?: boolean): boolean;
41-
/**
42-
* v1 >= v2
43-
*/
44-
function gte(v1: string, v2: string, loose?: boolean): boolean;
45-
/**
46-
* v1 < v2
47-
*/
48-
function lt(v1: string, v2: string, loose?: boolean): boolean;
49-
/**
50-
* v1 <= v2
51-
*/
52-
function lte(v1: string, v2: string, loose?: boolean): boolean;
53-
/**
54-
* v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings.
55-
*/
56-
function eq(v1: string, v2: string, loose?: boolean): boolean;
57-
/**
58-
* v1 != v2 The opposite of eq.
59-
*/
60-
function neq(v1: string, v2: string, loose?: boolean): boolean;
61-
/**
62-
* Pass in a comparison string, and it'll call the corresponding semver comparison function. "===" and "!==" do simple string comparison, but are included for completeness. Throws if an invalid comparison string is provided.
63-
*/
64-
function cmp(v1: string, comparator: any, v2: string, loose?: boolean): boolean;
65-
/**
66-
* Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort().
67-
*/
68-
function compare(v1: string, v2: string, loose?: boolean): number;
69-
/**
70-
* The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort().
71-
*/
72-
function rcompare(v1: string, v2: string, loose?: boolean): number;
73-
/**
74-
* Returns difference between two versions by the release type (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null if the versions are the same.
75-
*/
76-
function diff(v1: string, v2: string, loose?: boolean): string;
77-
78-
// Ranges
79-
/**
80-
* Return the valid range or null if it's not valid
81-
*/
82-
function validRange(range: string, loose?: boolean): string;
83-
/**
84-
* Return true if the version satisfies the range.
85-
*/
86-
function satisfies(version: string, range: string, loose?: boolean): boolean;
87-
/**
88-
* Return the highest version in the list that satisfies the range, or null if none of them do.
89-
*/
90-
function maxSatisfying(versions: string[], range: string, loose?: boolean): string;
91-
/**
92-
* Return the lowest version in the list that satisfies the range, or null if none of them do.
93-
*/
94-
function minSatisfying(versions: string[], range: string, loose?: boolean): string;
95-
/**
96-
* Return true if version is greater than all the versions possible in the range.
97-
*/
98-
function gtr(version: string, range: string, loose?: boolean): boolean;
99-
/**
100-
* Return true if version is less than all the versions possible in the range.
101-
*/
102-
function ltr(version: string, range: string, loose?: boolean): boolean;
103-
/**
104-
* Return true if the version is outside the bounds of the range in either the high or low direction. The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.)
105-
*/
106-
function outside(version: string, range: string, hilo: string, loose?: boolean): boolean;
107-
108-
class SemVerBase {
109-
raw: string;
110-
loose: boolean;
111-
format(): string;
112-
inspect(): string;
113-
toString(): string;
114-
}
115-
116-
class SemVer extends SemVerBase {
117-
constructor(version: string, loose?: boolean);
118-
119-
major: number;
120-
minor: number;
121-
patch: number;
122-
version: string;
123-
build: string[];
124-
prerelease: string[];
125-
126-
compare(other:SemVer): number;
127-
compareMain(other:SemVer): number;
128-
comparePre(other:SemVer): number;
129-
inc(release: string): SemVer;
130-
}
131-
132-
class Comparator extends SemVerBase {
133-
constructor(comp: string, loose?: boolean);
134-
135-
semver: SemVer;
136-
operator: string;
137-
value: boolean;
138-
parse(comp: string): void;
139-
test(version:SemVer): boolean;
140-
}
141-
142-
class Range extends SemVerBase {
143-
constructor(range: string, loose?: boolean);
144-
145-
set: Comparator[][];
146-
parseRange(range: string): Comparator[];
147-
test(version: SemVer): boolean;
148-
}
6+
export const SEMVER_SPEC_VERSION: "2.0.0";
7+
8+
/**
9+
* Return the parsed version, or null if it's not valid.
10+
*/
11+
export function valid(v: string, loose?: boolean): string;
12+
/**
13+
* Returns cleaned (removed leading/trailing whitespace, remove '=v' prefix) and parsed version, or null if version is invalid.
14+
*/
15+
export function clean(version: string, loose?: boolean): string;
16+
/**
17+
* Return the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid.
18+
*/
19+
export function inc(v: string, release: string, loose?: boolean): string;
20+
/**
21+
* Return the major version number.
22+
*/
23+
export function major(v: string, loose?: boolean): number;
24+
/**
25+
* Return the minor version number.
26+
*/
27+
export function minor(v: string, loose?: boolean): number;
28+
/**
29+
* Return the patch version number.
30+
*/
31+
export function patch(v: string, loose?: boolean): number;
32+
/**
33+
* Returns an array of prerelease components, or null if none exist.
34+
*/
35+
export function prerelease(v: string, loose?: boolean): string[];
36+
37+
// Comparison
38+
/**
39+
* v1 > v2
40+
*/
41+
export function gt(v1: string, v2: string, loose?: boolean): boolean;
42+
/**
43+
* v1 >= v2
44+
*/
45+
export function gte(v1: string, v2: string, loose?: boolean): boolean;
46+
/**
47+
* v1 < v2
48+
*/
49+
export function lt(v1: string, v2: string, loose?: boolean): boolean;
50+
/**
51+
* v1 <= v2
52+
*/
53+
export function lte(v1: string, v2: string, loose?: boolean): boolean;
54+
/**
55+
* v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings.
56+
*/
57+
export function eq(v1: string, v2: string, loose?: boolean): boolean;
58+
/**
59+
* v1 != v2 The opposite of eq.
60+
*/
61+
export function neq(v1: string, v2: string, loose?: boolean): boolean;
62+
/**
63+
* Pass in a comparison string, and it'll call the corresponding semver comparison function.
64+
* "===" and "!==" do simple string comparison, but are included for completeness.
65+
* Throws if an invalid comparison string is provided.
66+
*/
67+
export function cmp(v1: string, comparator: any, v2: string, loose?: boolean): boolean;
68+
/**
69+
* Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort().
70+
*/
71+
export function compare(v1: string, v2: string, loose?: boolean): number;
72+
/**
73+
* The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort().
74+
*/
75+
export function rcompare(v1: string, v2: string, loose?: boolean): number;
76+
/**
77+
* Returns difference between two versions by the release type (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null if the versions are the same.
78+
*/
79+
export function diff(v1: string, v2: string, loose?: boolean): string;
80+
81+
// Ranges
82+
/**
83+
* Return the valid range or null if it's not valid
84+
*/
85+
export function validRange(range: string, loose?: boolean): string;
86+
/**
87+
* Return true if the version satisfies the range.
88+
*/
89+
export function satisfies(version: string, range: string, loose?: boolean): boolean;
90+
/**
91+
* Return the highest version in the list that satisfies the range, or null if none of them do.
92+
*/
93+
export function maxSatisfying(versions: string[], range: string, loose?: boolean): string;
94+
/**
95+
* Return the lowest version in the list that satisfies the range, or null if none of them do.
96+
*/
97+
export function minSatisfying(versions: string[], range: string, loose?: boolean): string;
98+
/**
99+
* Return true if version is greater than all the versions possible in the range.
100+
*/
101+
export function gtr(version: string, range: string, loose?: boolean): boolean;
102+
/**
103+
* Return true if version is less than all the versions possible in the range.
104+
*/
105+
export function ltr(version: string, range: string, loose?: boolean): boolean;
106+
/**
107+
* Return true if the version is outside the bounds of the range in either the high or low direction.
108+
* The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.)
109+
*/
110+
export function outside(version: string, range: string, hilo: string, loose?: boolean): boolean;
111+
112+
export class SemVer {
113+
constructor(version: string, loose?: boolean);
114+
115+
raw: string;
116+
loose: boolean;
117+
format(): string;
118+
inspect(): string;
119+
120+
major: number;
121+
minor: number;
122+
patch: number;
123+
version: string;
124+
build: string[];
125+
prerelease: string[];
126+
127+
compare(other: SemVer): number;
128+
compareMain(other: SemVer): number;
129+
comparePre(other: SemVer): number;
130+
inc(release: string): SemVer;
149131
}
150132

151-
interface SemVerStatic {
152-
SemVer(version: string, loose?: boolean): SemVerModule.SemVer;
153-
Comparator(comp: string, loose?: boolean): SemVerModule.Comparator;
154-
Range(range: string, loose?: boolean): SemVerModule.Range;
155-
clean(version: string, loose?: boolean): string;
156-
157-
SEMVER_SPEC_VERSION: string;
133+
export class Comparator {
134+
constructor(comp: string, loose?: boolean);
158135

159-
valid(v: string, loose?: boolean): string;
160-
inc(v: string, release: string, loose?: boolean): string;
161-
major(v: string, loose?: boolean): number;
162-
minor(v: string, loose?: boolean): number;
163-
patch(v: string, loose?: boolean): number;
164-
gt(v1: string, v2: string, loose?: boolean): boolean;
165-
gte(v1: string, v2: string, loose?: boolean): boolean;
166-
lt(v1: string, v2: string, loose?: boolean): boolean;
167-
lte(v1: string, v2: string, loose?: boolean): boolean;
168-
eq(v1: string, v2: string, loose?: boolean): boolean;
169-
neq(v1: string, v2: string, loose?: boolean): boolean;
170-
cmp(v1: string, comparator: any, v2: string, loose?: boolean): boolean;
171-
compare(v1: string, v2: string, loose?: boolean): number;
172-
rcompare(v1: string, v2: string, loose?: boolean): number;
173-
diff(v1: string, v2: string, loose?: boolean): string;
174-
validRange(range: string, loose?: boolean): string;
175-
satisfies(version: string, range: string, loose?: boolean): boolean;
176-
maxSatisfying(versions: string[], range: string, loose?: boolean): string;
177-
gtr(version: string, range: string, loose?: boolean): boolean;
178-
ltr(version: string, range: string, loose?: boolean): boolean;
179-
outside(version: string, range: string, hilo: string, loose?: boolean): boolean;
136+
semver: SemVer;
137+
operator: string;
138+
value: boolean;
139+
parse(comp: string): void;
140+
test(version: SemVer): boolean;
180141
}
181142

182-
declare var semver: SemVerStatic;
143+
export class Range {
144+
constructor(range: string, loose?: boolean);
145+
146+
raw: string;
147+
loose: boolean;
148+
format(): string;
149+
inspect(): string;
183150

184-
declare module "semver" {
185-
export = SemVerModule;
151+
set: Comparator[][];
152+
parseRange(range: string): Comparator[];
153+
test(version: SemVer): boolean;
186154
}

0 commit comments

Comments
 (0)