You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // Type definitions for semver 6.0
  2. // Project: https://github.com/npm/node-semver
  3. // Definitions by: Bart van der Schoor <https://github.com/Bartvds>
  4. // BendingBender <https://github.com/BendingBender>
  5. // Lucian Buzzo <https://github.com/LucianBuzzo>
  6. // Klaus Meinhardt <https://github.com/ajafff>
  7. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/semver
  8. export const SEMVER_SPEC_VERSION: "2.0.0";
  9. export type ReleaseType = "major" | "premajor" | "minor" | "preminor" | "patch" | "prepatch" | "prerelease";
  10. export interface Options {
  11. loose?: boolean;
  12. includePrerelease?: boolean;
  13. }
  14. /**
  15. * Return the parsed version as a SemVer object, or null if it's not valid.
  16. */
  17. export function parse(v: string | SemVer, optionsOrLoose?: boolean | Options): SemVer | null;
  18. /**
  19. * Return the parsed version, or null if it's not valid.
  20. */
  21. export function valid(v: string | SemVer, optionsOrLoose?: boolean | Options): string | null;
  22. /**
  23. * Returns cleaned (removed leading/trailing whitespace, remove '=v' prefix) and parsed version, or null if version is invalid.
  24. */
  25. export function clean(version: string, optionsOrLoose?: boolean | Options): string | null;
  26. /**
  27. * Return the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid.
  28. */
  29. export function inc(v: string | SemVer, release: ReleaseType, optionsOrLoose?: boolean | Options, identifier?: string): string | null;
  30. export function inc(
  31. v: string | SemVer,
  32. release: ReleaseType,
  33. identifier?: string,
  34. ): string | null;
  35. /**
  36. * Return the major version number.
  37. */
  38. export function major(v: string | SemVer, optionsOrLoose?: boolean | Options): number;
  39. /**
  40. * Return the minor version number.
  41. */
  42. export function minor(v: string | SemVer, optionsOrLoose?: boolean | Options): number;
  43. /**
  44. * Return the patch version number.
  45. */
  46. export function patch(v: string | SemVer, optionsOrLoose?: boolean | Options): number;
  47. /**
  48. * Returns an array of prerelease components, or null if none exist.
  49. */
  50. export function prerelease(v: string | SemVer, optionsOrLoose?: boolean | Options): ReadonlyArray<string> | null;
  51. // Comparison
  52. /**
  53. * v1 > v2
  54. */
  55. export function gt(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): boolean;
  56. /**
  57. * v1 >= v2
  58. */
  59. export function gte(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): boolean;
  60. /**
  61. * v1 < v2
  62. */
  63. export function lt(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): boolean;
  64. /**
  65. * v1 <= v2
  66. */
  67. export function lte(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): boolean;
  68. /**
  69. * 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.
  70. */
  71. export function eq(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): boolean;
  72. /**
  73. * v1 != v2 The opposite of eq.
  74. */
  75. export function neq(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): boolean;
  76. /**
  77. * Pass in a comparison string, and it'll call the corresponding semver comparison function.
  78. * "===" and "!==" do simple string comparison, but are included for completeness.
  79. * Throws if an invalid comparison string is provided.
  80. */
  81. export function cmp(v1: string | SemVer, operator: Operator, v2: string | SemVer, optionsOrLoose?: boolean | Options): boolean;
  82. export type Operator = '===' | '!==' | '' | '=' | '==' | '!=' | '>' | '>=' | '<' | '<=';
  83. /**
  84. * 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().
  85. */
  86. export function compare(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): 1 | 0 | -1;
  87. /**
  88. * The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort().
  89. */
  90. export function rcompare(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): 1 | 0 | -1;
  91. /**
  92. * Compares two identifiers, must be numeric strings or truthy/falsy values. Sorts in ascending order if passed to Array.sort().
  93. */
  94. export function compareIdentifiers(a: string | null, b: string | null): 1 | 0 | -1;
  95. /**
  96. * The reverse of compareIdentifiers. Sorts in descending order when passed to Array.sort().
  97. */
  98. export function rcompareIdentifiers(a: string | null, b: string | null): 1 | 0 | -1;
  99. /**
  100. * Sorts an array of semver entries in ascending order.
  101. */
  102. export function sort<T extends string | SemVer>(list: T[], optionsOrLoose?: boolean | Options): T[];
  103. /**
  104. * Sorts an array of semver entries in descending order.
  105. */
  106. export function rsort<T extends string | SemVer>(list: T[], optionsOrLoose?: boolean | Options): T[];
  107. /**
  108. * 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.
  109. */
  110. export function diff(v1: string | SemVer, v2: string | SemVer, optionsOrLoose?: boolean | Options): ReleaseType | null;
  111. // Ranges
  112. /**
  113. * Return the valid range or null if it's not valid
  114. */
  115. export function validRange(range: string | Range, optionsOrLoose?: boolean | Options): string;
  116. /**
  117. * Return true if the version satisfies the range.
  118. */
  119. export function satisfies(version: string | SemVer, range: string | Range, optionsOrLoose?: boolean | Options): boolean;
  120. /**
  121. * Return the highest version in the list that satisfies the range, or null if none of them do.
  122. */
  123. export function maxSatisfying<T extends string | SemVer>(versions: ReadonlyArray<T>, range: string | Range, optionsOrLoose?: boolean | Options): T | null;
  124. /**
  125. * Return the lowest version in the list that satisfies the range, or null if none of them do.
  126. */
  127. export function minSatisfying<T extends string | SemVer>(versions: ReadonlyArray<T>, range: string | Range, optionsOrLoose?: boolean | Options): T | null;
  128. /**
  129. * Return the lowest version that can possibly match the given range.
  130. */
  131. export function minVersion(range: string | Range, optionsOrLoose?: boolean | Options): SemVer | null;
  132. /**
  133. * Return true if version is greater than all the versions possible in the range.
  134. */
  135. export function gtr(version: string | SemVer, range: string | Range, optionsOrLoose?: boolean | Options): boolean;
  136. /**
  137. * Return true if version is less than all the versions possible in the range.
  138. */
  139. export function ltr(version: string | SemVer, range: string | Range, optionsOrLoose?: boolean | Options): boolean;
  140. /**
  141. * Return true if the version is outside the bounds of the range in either the high or low direction.
  142. * The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.)
  143. */
  144. export function outside(version: string | SemVer, range: string | Range, hilo: '>' | '<', optionsOrLoose?: boolean | Options): boolean;
  145. /**
  146. * Return true if any of the ranges comparators intersect
  147. */
  148. export function intersects(range1: string | Range, range2: string | Range, optionsOrLoose?: boolean | Options): boolean;
  149. // Coercion
  150. /**
  151. * Coerces a string to semver if possible
  152. */
  153. export function coerce(version: string | SemVer): SemVer | null;
  154. export class SemVer {
  155. constructor(version: string | SemVer, optionsOrLoose?: boolean | Options);
  156. raw: string;
  157. loose: boolean;
  158. options: Options;
  159. format(): string;
  160. inspect(): string;
  161. major: number;
  162. minor: number;
  163. patch: number;
  164. version: string;
  165. build: ReadonlyArray<string>;
  166. prerelease: ReadonlyArray<string | number>;
  167. compare(other: string | SemVer): 1 | 0 | -1;
  168. compareMain(other: string | SemVer): 1 | 0 | -1;
  169. comparePre(other: string | SemVer): 1 | 0 | -1;
  170. inc(release: ReleaseType, identifier?: string): SemVer;
  171. }
  172. export class Comparator {
  173. constructor(comp: string | Comparator, optionsOrLoose?: boolean | Options);
  174. semver: SemVer;
  175. operator: '' | '=' | '<' | '>' | '<=' | '>=';
  176. value: string;
  177. loose: boolean;
  178. options: Options;
  179. parse(comp: string): void;
  180. test(version: string | SemVer): boolean;
  181. intersects(comp: Comparator, optionsOrLoose?: boolean | Options): boolean;
  182. }
  183. export class Range {
  184. constructor(range: string | Range, optionsOrLoose?: boolean | Options);
  185. range: string;
  186. raw: string;
  187. loose: boolean;
  188. options: Options;
  189. includePrerelease: boolean;
  190. format(): string;
  191. inspect(): string;
  192. set: ReadonlyArray<ReadonlyArray<Comparator>>;
  193. parseRange(range: string): ReadonlyArray<Comparator>;
  194. test(version: string | SemVer): boolean;
  195. intersects(range: Range, optionsOrLoose?: boolean | Options): boolean;
  196. }