semver.7 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. .TH "SEMVER" "7" "August 2021" "" ""
  2. .SH "NAME"
  3. \fBsemver\fR \- The semantic versioner for npm
  4. .SH Install
  5. .P
  6. .RS 2
  7. .nf
  8. npm install \-\-save semver
  9. .fi
  10. .RE
  11. .SH Usage
  12. .P
  13. As a node module:
  14. .P
  15. .RS 2
  16. .nf
  17. const semver = require('semver')
  18. semver\.valid('1\.2\.3') // '1\.2\.3'
  19. semver\.valid('a\.b\.c') // null
  20. semver\.clean(' =v1\.2\.3 ') // '1\.2\.3'
  21. semver\.satisfies('1\.2\.3', '1\.x || >=2\.5\.0 || 5\.0\.0 \- 7\.2\.3') // true
  22. semver\.gt('1\.2\.3', '9\.8\.7') // false
  23. semver\.lt('1\.2\.3', '9\.8\.7') // true
  24. semver\.minVersion('>=1\.0\.0') // '1\.0\.0'
  25. semver\.valid(semver\.coerce('v2')) // '2\.0\.0'
  26. semver\.valid(semver\.coerce('42\.6\.7\.9\.3\-alpha')) // '42\.6\.7'
  27. .fi
  28. .RE
  29. .P
  30. As a command\-line utility:
  31. .P
  32. .RS 2
  33. .nf
  34. $ semver \-h
  35. A JavaScript implementation of the https://semver\.org/ specification
  36. Copyright Isaac Z\. Schlueter
  37. Usage: semver [options] <version> [<version> [\.\.\.]]
  38. Prints valid versions sorted by SemVer precedence
  39. Options:
  40. \-r \-\-range <range>
  41. Print versions that match the specified range\.
  42. \-i \-\-increment [<level>]
  43. Increment a version by the specified level\. Level can
  44. be one of: major, minor, patch, premajor, preminor,
  45. prepatch, or prerelease\. Default level is 'patch'\.
  46. Only one version may be specified\.
  47. \-\-preid <identifier>
  48. Identifier to be used to prefix premajor, preminor,
  49. prepatch or prerelease version increments\.
  50. \-l \-\-loose
  51. Interpret versions and ranges loosely
  52. \-p \-\-include\-prerelease
  53. Always include prerelease versions in range matching
  54. \-c \-\-coerce
  55. Coerce a string into SemVer if possible
  56. (does not imply \-\-loose)
  57. Program exits successfully if any valid version satisfies
  58. all supplied ranges, and prints all satisfying versions\.
  59. If no satisfying versions are found, then exits failure\.
  60. Versions are printed in ascending order, so supplying
  61. multiple versions to the utility will just sort them\.
  62. .fi
  63. .RE
  64. .SH Versions
  65. .P
  66. A "version" is described by the \fBv2\.0\.0\fP specification found at
  67. https://semver\.org/\|\.
  68. .P
  69. A leading \fB"="\fP or \fB"v"\fP character is stripped off and ignored\.
  70. .SH Ranges
  71. .P
  72. A \fBversion range\fP is a set of \fBcomparators\fP which specify versions
  73. that satisfy the range\.
  74. .P
  75. A \fBcomparator\fP is composed of an \fBoperator\fP and a \fBversion\fP\|\. The set
  76. of primitive \fBoperators\fP is:
  77. .RS 0
  78. .IP \(bu 2
  79. \fB<\fP Less than
  80. .IP \(bu 2
  81. \fB<=\fP Less than or equal to
  82. .IP \(bu 2
  83. \fB>\fP Greater than
  84. .IP \(bu 2
  85. \fB>=\fP Greater than or equal to
  86. .IP \(bu 2
  87. \fB=\fP Equal\. If no operator is specified, then equality is assumed,
  88. so this operator is optional, but MAY be included\.
  89. .RE
  90. .P
  91. For example, the comparator \fB>=1\.2\.7\fP would match the versions
  92. \fB1\.2\.7\fP, \fB1\.2\.8\fP, \fB2\.5\.3\fP, and \fB1\.3\.9\fP, but not the versions \fB1\.2\.6\fP
  93. or \fB1\.1\.0\fP\|\.
  94. .P
  95. Comparators can be joined by whitespace to form a \fBcomparator set\fP,
  96. which is satisfied by the \fBintersection\fR of all of the comparators
  97. it includes\.
  98. .P
  99. A range is composed of one or more comparator sets, joined by \fB||\fP\|\. A
  100. version matches a range if and only if every comparator in at least
  101. one of the \fB||\fP\-separated comparator sets is satisfied by the version\.
  102. .P
  103. For example, the range \fB>=1\.2\.7 <1\.3\.0\fP would match the versions
  104. \fB1\.2\.7\fP, \fB1\.2\.8\fP, and \fB1\.2\.99\fP, but not the versions \fB1\.2\.6\fP, \fB1\.3\.0\fP,
  105. or \fB1\.1\.0\fP\|\.
  106. .P
  107. The range \fB1\.2\.7 || >=1\.2\.9 <2\.0\.0\fP would match the versions \fB1\.2\.7\fP,
  108. \fB1\.2\.9\fP, and \fB1\.4\.6\fP, but not the versions \fB1\.2\.8\fP or \fB2\.0\.0\fP\|\.
  109. .SS Prerelease Tags
  110. .P
  111. If a version has a prerelease tag (for example, \fB1\.2\.3\-alpha\.3\fP) then
  112. it will only be allowed to satisfy comparator sets if at least one
  113. comparator with the same \fB[major, minor, patch]\fP tuple also has a
  114. prerelease tag\.
  115. .P
  116. For example, the range \fB>1\.2\.3\-alpha\.3\fP would be allowed to match the
  117. version \fB1\.2\.3\-alpha\.7\fP, but it would \fInot\fR be satisfied by
  118. \fB3\.4\.5\-alpha\.9\fP, even though \fB3\.4\.5\-alpha\.9\fP is technically "greater
  119. than" \fB1\.2\.3\-alpha\.3\fP according to the SemVer sort rules\. The version
  120. range only accepts prerelease tags on the \fB1\.2\.3\fP version\. The
  121. version \fB3\.4\.5\fP \fIwould\fR satisfy the range, because it does not have a
  122. prerelease flag, and \fB3\.4\.5\fP is greater than \fB1\.2\.3\-alpha\.7\fP\|\.
  123. .P
  124. The purpose for this behavior is twofold\. First, prerelease versions
  125. frequently are updated very quickly, and contain many breaking changes
  126. that are (by the author's design) not yet fit for public consumption\.
  127. Therefore, by default, they are excluded from range matching
  128. semantics\.
  129. .P
  130. Second, a user who has opted into using a prerelease version has
  131. clearly indicated the intent to use \fIthat specific\fR set of
  132. alpha/beta/rc versions\. By including a prerelease tag in the range,
  133. the user is indicating that they are aware of the risk\. However, it
  134. is still not appropriate to assume that they have opted into taking a
  135. similar risk on the \fInext\fR set of prerelease versions\.
  136. .P
  137. Note that this behavior can be suppressed (treating all prerelease
  138. versions as if they were normal versions, for the purpose of range
  139. matching) by setting the \fBincludePrerelease\fP flag on the options
  140. object to any
  141. functions \fIhttps://github\.com/npm/node\-semver#functions\fR that do
  142. range matching\.
  143. .SS Prerelease Identifiers
  144. .P
  145. The method \fB\|\.inc\fP takes an additional \fBidentifier\fP string argument that
  146. will append the value of the string as a prerelease identifier:
  147. .P
  148. .RS 2
  149. .nf
  150. semver\.inc('1\.2\.3', 'prerelease', 'beta')
  151. // '1\.2\.4\-beta\.0'
  152. .fi
  153. .RE
  154. .P
  155. command\-line example:
  156. .P
  157. .RS 2
  158. .nf
  159. $ semver 1\.2\.3 \-i prerelease \-\-preid beta
  160. 1\.2\.4\-beta\.0
  161. .fi
  162. .RE
  163. .P
  164. Which then can be used to increment further:
  165. .P
  166. .RS 2
  167. .nf
  168. $ semver 1\.2\.4\-beta\.0 \-i prerelease
  169. 1\.2\.4\-beta\.1
  170. .fi
  171. .RE
  172. .SS Advanced Range Syntax
  173. .P
  174. Advanced range syntax desugars to primitive comparators in
  175. deterministic ways\.
  176. .P
  177. Advanced ranges may be combined in the same way as primitive
  178. comparators using white space or \fB||\fP\|\.
  179. .SS Hyphen Ranges \fBX\.Y\.Z \- A\.B\.C\fP
  180. .P
  181. Specifies an inclusive set\.
  182. .RS 0
  183. .IP \(bu 2
  184. \fB1\.2\.3 \- 2\.3\.4\fP := \fB>=1\.2\.3 <=2\.3\.4\fP
  185. .RE
  186. .P
  187. If a partial version is provided as the first version in the inclusive
  188. range, then the missing pieces are replaced with zeroes\.
  189. .RS 0
  190. .IP \(bu 2
  191. \fB1\.2 \- 2\.3\.4\fP := \fB>=1\.2\.0 <=2\.3\.4\fP
  192. .RE
  193. .P
  194. If a partial version is provided as the second version in the
  195. inclusive range, then all versions that start with the supplied parts
  196. of the tuple are accepted, but nothing that would be greater than the
  197. provided tuple parts\.
  198. .RS 0
  199. .IP \(bu 2
  200. \fB1\.2\.3 \- 2\.3\fP := \fB>=1\.2\.3 <2\.4\.0\fP
  201. .IP \(bu 2
  202. \fB1\.2\.3 \- 2\fP := \fB>=1\.2\.3 <3\.0\.0\fP
  203. .RE
  204. .SS X\-Ranges \fB1\.2\.x\fP \fB1\.X\fP \fB1\.2\.*\fP \fB*\fP
  205. .P
  206. Any of \fBX\fP, \fBx\fP, or \fB*\fP may be used to "stand in" for one of the
  207. numeric values in the \fB[major, minor, patch]\fP tuple\.
  208. .RS 0
  209. .IP \(bu 2
  210. \fB*\fP := \fB>=0\.0\.0\fP (Any version satisfies)
  211. .IP \(bu 2
  212. \fB1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP (Matching major version)
  213. .IP \(bu 2
  214. \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP (Matching major and minor versions)
  215. .RE
  216. .P
  217. A partial version range is treated as an X\-Range, so the special
  218. character is in fact optional\.
  219. .RS 0
  220. .IP \(bu 2
  221. \fB""\fP (empty string) := \fB*\fP := \fB>=0\.0\.0\fP
  222. .IP \(bu 2
  223. \fB1\fP := \fB1\.x\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP
  224. .IP \(bu 2
  225. \fB1\.2\fP := \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP
  226. .RE
  227. .SS Tilde Ranges \fB~1\.2\.3\fP \fB~1\.2\fP \fB~1\fP
  228. .P
  229. Allows patch\-level changes if a minor version is specified on the
  230. comparator\. Allows minor\-level changes if not\.
  231. .RS 0
  232. .IP \(bu 2
  233. \fB~1\.2\.3\fP := \fB>=1\.2\.3 <1\.(2+1)\.0\fP := \fB>=1\.2\.3 <1\.3\.0\fP
  234. .IP \(bu 2
  235. \fB~1\.2\fP := \fB>=1\.2\.0 <1\.(2+1)\.0\fP := \fB>=1\.2\.0 <1\.3\.0\fP (Same as \fB1\.2\.x\fP)
  236. .IP \(bu 2
  237. \fB~1\fP := \fB>=1\.0\.0 <(1+1)\.0\.0\fP := \fB>=1\.0\.0 <2\.0\.0\fP (Same as \fB1\.x\fP)
  238. .IP \(bu 2
  239. \fB~0\.2\.3\fP := \fB>=0\.2\.3 <0\.(2+1)\.0\fP := \fB>=0\.2\.3 <0\.3\.0\fP
  240. .IP \(bu 2
  241. \fB~0\.2\fP := \fB>=0\.2\.0 <0\.(2+1)\.0\fP := \fB>=0\.2\.0 <0\.3\.0\fP (Same as \fB0\.2\.x\fP)
  242. .IP \(bu 2
  243. \fB~0\fP := \fB>=0\.0\.0 <(0+1)\.0\.0\fP := \fB>=0\.0\.0 <1\.0\.0\fP (Same as \fB0\.x\fP)
  244. .IP \(bu 2
  245. \fB~1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <1\.3\.0\fP Note that prereleases in
  246. the \fB1\.2\.3\fP version will be allowed, if they are greater than or
  247. equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but
  248. \fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a
  249. different \fB[major, minor, patch]\fP tuple\.
  250. .RE
  251. .SS Caret Ranges \fB^1\.2\.3\fP \fB^0\.2\.5\fP \fB^0\.0\.4\fP
  252. .P
  253. Allows changes that do not modify the left\-most non\-zero digit in the
  254. \fB[major, minor, patch]\fP tuple\. In other words, this allows patch and
  255. minor updates for versions \fB1\.0\.0\fP and above, patch updates for
  256. versions \fB0\.X >=0\.1\.0\fP, and \fIno\fR updates for versions \fB0\.0\.X\fP\|\.
  257. .P
  258. Many authors treat a \fB0\.x\fP version as if the \fBx\fP were the major
  259. "breaking\-change" indicator\.
  260. .P
  261. Caret ranges are ideal when an author may make breaking changes
  262. between \fB0\.2\.4\fP and \fB0\.3\.0\fP releases, which is a common practice\.
  263. However, it presumes that there will \fInot\fR be breaking changes between
  264. \fB0\.2\.4\fP and \fB0\.2\.5\fP\|\. It allows for changes that are presumed to be
  265. additive (but non\-breaking), according to commonly observed practices\.
  266. .RS 0
  267. .IP \(bu 2
  268. \fB^1\.2\.3\fP := \fB>=1\.2\.3 <2\.0\.0\fP
  269. .IP \(bu 2
  270. \fB^0\.2\.3\fP := \fB>=0\.2\.3 <0\.3\.0\fP
  271. .IP \(bu 2
  272. \fB^0\.0\.3\fP := \fB>=0\.0\.3 <0\.0\.4\fP
  273. .IP \(bu 2
  274. \fB^1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <2\.0\.0\fP Note that prereleases in
  275. the \fB1\.2\.3\fP version will be allowed, if they are greater than or
  276. equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but
  277. \fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a
  278. different \fB[major, minor, patch]\fP tuple\.
  279. .IP \(bu 2
  280. \fB^0\.0\.3\-beta\fP := \fB>=0\.0\.3\-beta <0\.0\.4\fP Note that prereleases in the
  281. \fB0\.0\.3\fP version \fIonly\fR will be allowed, if they are greater than or
  282. equal to \fBbeta\fP\|\. So, \fB0\.0\.3\-pr\.2\fP would be allowed\.
  283. .RE
  284. .P
  285. When parsing caret ranges, a missing \fBpatch\fP value desugars to the
  286. number \fB0\fP, but will allow flexibility within that value, even if the
  287. major and minor versions are both \fB0\fP\|\.
  288. .RS 0
  289. .IP \(bu 2
  290. \fB^1\.2\.x\fP := \fB>=1\.2\.0 <2\.0\.0\fP
  291. .IP \(bu 2
  292. \fB^0\.0\.x\fP := \fB>=0\.0\.0 <0\.1\.0\fP
  293. .IP \(bu 2
  294. \fB^0\.0\fP := \fB>=0\.0\.0 <0\.1\.0\fP
  295. .RE
  296. .P
  297. A missing \fBminor\fP and \fBpatch\fP values will desugar to zero, but also
  298. allow flexibility within those values, even if the major version is
  299. zero\.
  300. .RS 0
  301. .IP \(bu 2
  302. \fB^1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP
  303. .IP \(bu 2
  304. \fB^0\.x\fP := \fB>=0\.0\.0 <1\.0\.0\fP
  305. .RE
  306. .SS Range Grammar
  307. .P
  308. Putting all this together, here is a Backus\-Naur grammar for ranges,
  309. for the benefit of parser authors:
  310. .P
  311. .RS 2
  312. .nf
  313. range\-set ::= range ( logical\-or range ) *
  314. logical\-or ::= ( ' ' ) * '||' ( ' ' ) *
  315. range ::= hyphen | simple ( ' ' simple ) * | ''
  316. hyphen ::= partial ' \- ' partial
  317. simple ::= primitive | partial | tilde | caret
  318. primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
  319. partial ::= xr ( '\.' xr ( '\.' xr qualifier ? )? )?
  320. xr ::= 'x' | 'X' | '*' | nr
  321. nr ::= '0' | ['1'\-'9'] ( ['0'\-'9'] ) *
  322. tilde ::= '~' partial
  323. caret ::= '^' partial
  324. qualifier ::= ( '\-' pre )? ( '+' build )?
  325. pre ::= parts
  326. build ::= parts
  327. parts ::= part ( '\.' part ) *
  328. part ::= nr | [\-0\-9A\-Za\-z]+
  329. .fi
  330. .RE
  331. .SH Functions
  332. .P
  333. All methods and classes take a final \fBoptions\fP object argument\. All
  334. options in this object are \fBfalse\fP by default\. The options supported
  335. are:
  336. .RS 0
  337. .IP \(bu 2
  338. \fBloose\fP Be more forgiving about not\-quite\-valid semver strings\.
  339. (Any resulting output will always be 100% strict compliant, of
  340. course\.) For backwards compatibility reasons, if the \fBoptions\fP
  341. argument is a boolean value instead of an object, it is interpreted
  342. to be the \fBloose\fP param\.
  343. .IP \(bu 2
  344. \fBincludePrerelease\fP Set to suppress the default
  345. behavior \fIhttps://github\.com/npm/node\-semver#prerelease\-tags\fR of
  346. excluding prerelease tagged versions from ranges unless they are
  347. explicitly opted into\.
  348. .RE
  349. .P
  350. Strict\-mode Comparators and Ranges will be strict about the SemVer
  351. strings that they parse\.
  352. .RS 0
  353. .IP \(bu 2
  354. \fBvalid(v)\fP: Return the parsed version, or null if it's not valid\.
  355. .IP \(bu 2
  356. \fBinc(v, release)\fP: Return the version incremented by the release
  357. type (\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP,
  358. \fBprepatch\fP, or \fBprerelease\fP), or null if it's not valid
  359. .RS
  360. .IP \(bu 2
  361. \fBpremajor\fP in one call will bump the version up to the next major
  362. version and down to a prerelease of that major version\.
  363. \fBpreminor\fP, and \fBprepatch\fP work the same way\.
  364. .IP \(bu 2
  365. If called from a non\-prerelease version, the \fBprerelease\fP will work the
  366. same as \fBprepatch\fP\|\. It increments the patch version, then makes a
  367. prerelease\. If the input version is already a prerelease it simply
  368. increments it\.
  369. .RE
  370. .IP \(bu 2
  371. \fBprerelease(v)\fP: Returns an array of prerelease components, or null
  372. if none exist\. Example: \fBprerelease('1\.2\.3\-alpha\.1') \-> ['alpha', 1]\fP
  373. .IP \(bu 2
  374. \fBmajor(v)\fP: Return the major version number\.
  375. .IP \(bu 2
  376. \fBminor(v)\fP: Return the minor version number\.
  377. .IP \(bu 2
  378. \fBpatch(v)\fP: Return the patch version number\.
  379. .IP \(bu 2
  380. \fBintersects(r1, r2, loose)\fP: Return true if the two supplied ranges
  381. or comparators intersect\.
  382. .IP \(bu 2
  383. \fBparse(v)\fP: Attempt to parse a string as a semantic version, returning either
  384. a \fBSemVer\fP object or \fBnull\fP\|\.
  385. .RE
  386. .SS Comparison
  387. .RS 0
  388. .IP \(bu 2
  389. \fBgt(v1, v2)\fP: \fBv1 > v2\fP
  390. .IP \(bu 2
  391. \fBgte(v1, v2)\fP: \fBv1 >= v2\fP
  392. .IP \(bu 2
  393. \fBlt(v1, v2)\fP: \fBv1 < v2\fP
  394. .IP \(bu 2
  395. \fBlte(v1, v2)\fP: \fBv1 <= v2\fP
  396. .IP \(bu 2
  397. \fBeq(v1, v2)\fP: \fBv1 == v2\fP This is true if they're logically equivalent,
  398. even if they're not the exact same string\. You already know how to
  399. compare strings\.
  400. .IP \(bu 2
  401. \fBneq(v1, v2)\fP: \fBv1 != v2\fP The opposite of \fBeq\fP\|\.
  402. .IP \(bu 2
  403. \fBcmp(v1, comparator, v2)\fP: Pass in a comparison string, and it'll call
  404. the corresponding function above\. \fB"==="\fP and \fB"!=="\fP do simple
  405. string comparison, but are included for completeness\. Throws if an
  406. invalid comparison string is provided\.
  407. .IP \(bu 2
  408. \fBcompare(v1, v2)\fP: Return \fB0\fP if \fBv1 == v2\fP, or \fB1\fP if \fBv1\fP is greater, or \fB\-1\fP if
  409. \fBv2\fP is greater\. Sorts in ascending order if passed to \fBArray\.sort()\fP\|\.
  410. .IP \(bu 2
  411. \fBrcompare(v1, v2)\fP: The reverse of compare\. Sorts an array of versions
  412. in descending order when passed to \fBArray\.sort()\fP\|\.
  413. .IP \(bu 2
  414. \fBdiff(v1, v2)\fP: Returns difference between two versions by the release type
  415. (\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP, \fBprepatch\fP, or \fBprerelease\fP),
  416. or null if the versions are the same\.
  417. .RE
  418. .SS Comparators
  419. .RS 0
  420. .IP \(bu 2
  421. \fBintersects(comparator)\fP: Return true if the comparators intersect
  422. .RE
  423. .SS Ranges
  424. .RS 0
  425. .IP \(bu 2
  426. \fBvalidRange(range)\fP: Return the valid range or null if it's not valid
  427. .IP \(bu 2
  428. \fBsatisfies(version, range)\fP: Return true if the version satisfies the
  429. range\.
  430. .IP \(bu 2
  431. \fBmaxSatisfying(versions, range)\fP: Return the highest version in the list
  432. that satisfies the range, or \fBnull\fP if none of them do\.
  433. .IP \(bu 2
  434. \fBminSatisfying(versions, range)\fP: Return the lowest version in the list
  435. that satisfies the range, or \fBnull\fP if none of them do\.
  436. .IP \(bu 2
  437. \fBminVersion(range)\fP: Return the lowest version that can possibly match
  438. the given range\.
  439. .IP \(bu 2
  440. \fBgtr(version, range)\fP: Return \fBtrue\fP if version is greater than all the
  441. versions possible in the range\.
  442. .IP \(bu 2
  443. \fBltr(version, range)\fP: Return \fBtrue\fP if version is less than all the
  444. versions possible in the range\.
  445. .IP \(bu 2
  446. \fBoutside(version, range, hilo)\fP: Return true if the version is outside
  447. the bounds of the range in either the high or low direction\. The
  448. \fBhilo\fP argument must be either the string \fB\|'>'\fP or \fB\|'<'\fP\|\. (This is
  449. the function called by \fBgtr\fP and \fBltr\fP\|\.)
  450. .IP \(bu 2
  451. \fBintersects(range)\fP: Return true if any of the ranges comparators intersect
  452. .RE
  453. .P
  454. Note that, since ranges may be non\-contiguous, a version might not be
  455. greater than a range, less than a range, \fIor\fR satisfy a range! For
  456. example, the range \fB1\.2 <1\.2\.9 || >2\.0\.0\fP would have a hole from \fB1\.2\.9\fP
  457. until \fB2\.0\.0\fP, so the version \fB1\.2\.10\fP would not be greater than the
  458. range (because \fB2\.0\.1\fP satisfies, which is higher), nor less than the
  459. range (since \fB1\.2\.8\fP satisfies, which is lower), and it also does not
  460. satisfy the range\.
  461. .P
  462. If you want to know if a version satisfies or does not satisfy a
  463. range, use the \fBsatisfies(version, range)\fP function\.
  464. .SS Coercion
  465. .RS 0
  466. .IP \(bu 2
  467. \fBcoerce(version)\fP: Coerces a string to semver if possible
  468. .RE
  469. .P
  470. This aims to provide a very forgiving translation of a non\-semver string to
  471. semver\. It looks for the first digit in a string, and consumes all
  472. remaining characters which satisfy at least a partial semver (e\.g\., \fB1\fP,
  473. \fB1\.2\fP, \fB1\.2\.3\fP) up to the max permitted length (256 characters)\. Longer
  474. versions are simply truncated (\fB4\.6\.3\.9\.2\-alpha2\fP becomes \fB4\.6\.3\fP)\. All
  475. surrounding text is simply ignored (\fBv3\.4 replaces v3\.3\.1\fP becomes
  476. \fB3\.4\.0\fP)\. Only text which lacks digits will fail coercion (\fBversion one\fP
  477. is not valid)\. The maximum length for any semver component considered for
  478. coercion is 16 characters; longer components will be ignored
  479. (\fB10000000000000000\.4\.7\.4\fP becomes \fB4\.7\.4\fP)\. The maximum value for any
  480. semver component is \fBNumber\.MAX_SAFE_INTEGER || (2**53 \- 1)\fP; higher value
  481. components are invalid (\fB9999999999999999\.4\.7\.4\fP is likely invalid)\.