Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
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.

388 lines
14 KiB

  1. semver(7) -- The semantic versioner for npm
  2. ===========================================
  3. ## Install
  4. ```bash
  5. npm install --save semver
  6. ````
  7. ## Usage
  8. As a node module:
  9. ```js
  10. const semver = require('semver')
  11. semver.valid('1.2.3') // '1.2.3'
  12. semver.valid('a.b.c') // null
  13. semver.clean(' =v1.2.3 ') // '1.2.3'
  14. semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
  15. semver.gt('1.2.3', '9.8.7') // false
  16. semver.lt('1.2.3', '9.8.7') // true
  17. semver.valid(semver.coerce('v2')) // '2.0.0'
  18. semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'
  19. ```
  20. As a command-line utility:
  21. ```
  22. $ semver -h
  23. SemVer 5.3.0
  24. A JavaScript implementation of the http://semver.org/ specification
  25. Copyright Isaac Z. Schlueter
  26. Usage: semver [options] <version> [<version> [...]]
  27. Prints valid versions sorted by SemVer precedence
  28. Options:
  29. -r --range <range>
  30. Print versions that match the specified range.
  31. -i --increment [<level>]
  32. Increment a version by the specified level. Level can
  33. be one of: major, minor, patch, premajor, preminor,
  34. prepatch, or prerelease. Default level is 'patch'.
  35. Only one version may be specified.
  36. --preid <identifier>
  37. Identifier to be used to prefix premajor, preminor,
  38. prepatch or prerelease version increments.
  39. -l --loose
  40. Interpret versions and ranges loosely
  41. -c --coerce
  42. Coerce a string into SemVer if possible
  43. (does not imply --loose)
  44. Program exits successfully if any valid version satisfies
  45. all supplied ranges, and prints all satisfying versions.
  46. If no satisfying versions are found, then exits failure.
  47. Versions are printed in ascending order, so supplying
  48. multiple versions to the utility will just sort them.
  49. ```
  50. ## Versions
  51. A "version" is described by the `v2.0.0` specification found at
  52. <http://semver.org/>.
  53. A leading `"="` or `"v"` character is stripped off and ignored.
  54. ## Ranges
  55. A `version range` is a set of `comparators` which specify versions
  56. that satisfy the range.
  57. A `comparator` is composed of an `operator` and a `version`. The set
  58. of primitive `operators` is:
  59. * `<` Less than
  60. * `<=` Less than or equal to
  61. * `>` Greater than
  62. * `>=` Greater than or equal to
  63. * `=` Equal. If no operator is specified, then equality is assumed,
  64. so this operator is optional, but MAY be included.
  65. For example, the comparator `>=1.2.7` would match the versions
  66. `1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6`
  67. or `1.1.0`.
  68. Comparators can be joined by whitespace to form a `comparator set`,
  69. which is satisfied by the **intersection** of all of the comparators
  70. it includes.
  71. A range is composed of one or more comparator sets, joined by `||`. A
  72. version matches a range if and only if every comparator in at least
  73. one of the `||`-separated comparator sets is satisfied by the version.
  74. For example, the range `>=1.2.7 <1.3.0` would match the versions
  75. `1.2.7`, `1.2.8`, and `1.2.99`, but not the versions `1.2.6`, `1.3.0`,
  76. or `1.1.0`.
  77. The range `1.2.7 || >=1.2.9 <2.0.0` would match the versions `1.2.7`,
  78. `1.2.9`, and `1.4.6`, but not the versions `1.2.8` or `2.0.0`.
  79. ### Prerelease Tags
  80. If a version has a prerelease tag (for example, `1.2.3-alpha.3`) then
  81. it will only be allowed to satisfy comparator sets if at least one
  82. comparator with the same `[major, minor, patch]` tuple also has a
  83. prerelease tag.
  84. For example, the range `>1.2.3-alpha.3` would be allowed to match the
  85. version `1.2.3-alpha.7`, but it would *not* be satisfied by
  86. `3.4.5-alpha.9`, even though `3.4.5-alpha.9` is technically "greater
  87. than" `1.2.3-alpha.3` according to the SemVer sort rules. The version
  88. range only accepts prerelease tags on the `1.2.3` version. The
  89. version `3.4.5` *would* satisfy the range, because it does not have a
  90. prerelease flag, and `3.4.5` is greater than `1.2.3-alpha.7`.
  91. The purpose for this behavior is twofold. First, prerelease versions
  92. frequently are updated very quickly, and contain many breaking changes
  93. that are (by the author's design) not yet fit for public consumption.
  94. Therefore, by default, they are excluded from range matching
  95. semantics.
  96. Second, a user who has opted into using a prerelease version has
  97. clearly indicated the intent to use *that specific* set of
  98. alpha/beta/rc versions. By including a prerelease tag in the range,
  99. the user is indicating that they are aware of the risk. However, it
  100. is still not appropriate to assume that they have opted into taking a
  101. similar risk on the *next* set of prerelease versions.
  102. #### Prerelease Identifiers
  103. The method `.inc` takes an additional `identifier` string argument that
  104. will append the value of the string as a prerelease identifier:
  105. ```javascript
  106. semver.inc('1.2.3', 'prerelease', 'beta')
  107. // '1.2.4-beta.0'
  108. ```
  109. command-line example:
  110. ```bash
  111. $ semver 1.2.3 -i prerelease --preid beta
  112. 1.2.4-beta.0
  113. ```
  114. Which then can be used to increment further:
  115. ```bash
  116. $ semver 1.2.4-beta.0 -i prerelease
  117. 1.2.4-beta.1
  118. ```
  119. ### Advanced Range Syntax
  120. Advanced range syntax desugars to primitive comparators in
  121. deterministic ways.
  122. Advanced ranges may be combined in the same way as primitive
  123. comparators using white space or `||`.
  124. #### Hyphen Ranges `X.Y.Z - A.B.C`
  125. Specifies an inclusive set.
  126. * `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4`
  127. If a partial version is provided as the first version in the inclusive
  128. range, then the missing pieces are replaced with zeroes.
  129. * `1.2 - 2.3.4` := `>=1.2.0 <=2.3.4`
  130. If a partial version is provided as the second version in the
  131. inclusive range, then all versions that start with the supplied parts
  132. of the tuple are accepted, but nothing that would be greater than the
  133. provided tuple parts.
  134. * `1.2.3 - 2.3` := `>=1.2.3 <2.4.0`
  135. * `1.2.3 - 2` := `>=1.2.3 <3.0.0`
  136. #### X-Ranges `1.2.x` `1.X` `1.2.*` `*`
  137. Any of `X`, `x`, or `*` may be used to "stand in" for one of the
  138. numeric values in the `[major, minor, patch]` tuple.
  139. * `*` := `>=0.0.0` (Any version satisfies)
  140. * `1.x` := `>=1.0.0 <2.0.0` (Matching major version)
  141. * `1.2.x` := `>=1.2.0 <1.3.0` (Matching major and minor versions)
  142. A partial version range is treated as an X-Range, so the special
  143. character is in fact optional.
  144. * `""` (empty string) := `*` := `>=0.0.0`
  145. * `1` := `1.x.x` := `>=1.0.0 <2.0.0`
  146. * `1.2` := `1.2.x` := `>=1.2.0 <1.3.0`
  147. #### Tilde Ranges `~1.2.3` `~1.2` `~1`
  148. Allows patch-level changes if a minor version is specified on the
  149. comparator. Allows minor-level changes if not.
  150. * `~1.2.3` := `>=1.2.3 <1.(2+1).0` := `>=1.2.3 <1.3.0`
  151. * `~1.2` := `>=1.2.0 <1.(2+1).0` := `>=1.2.0 <1.3.0` (Same as `1.2.x`)
  152. * `~1` := `>=1.0.0 <(1+1).0.0` := `>=1.0.0 <2.0.0` (Same as `1.x`)
  153. * `~0.2.3` := `>=0.2.3 <0.(2+1).0` := `>=0.2.3 <0.3.0`
  154. * `~0.2` := `>=0.2.0 <0.(2+1).0` := `>=0.2.0 <0.3.0` (Same as `0.2.x`)
  155. * `~0` := `>=0.0.0 <(0+1).0.0` := `>=0.0.0 <1.0.0` (Same as `0.x`)
  156. * `~1.2.3-beta.2` := `>=1.2.3-beta.2 <1.3.0` Note that prereleases in
  157. the `1.2.3` version will be allowed, if they are greater than or
  158. equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
  159. `1.2.4-beta.2` would not, because it is a prerelease of a
  160. different `[major, minor, patch]` tuple.
  161. #### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4`
  162. Allows changes that do not modify the left-most non-zero digit in the
  163. `[major, minor, patch]` tuple. In other words, this allows patch and
  164. minor updates for versions `1.0.0` and above, patch updates for
  165. versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`.
  166. Many authors treat a `0.x` version as if the `x` were the major
  167. "breaking-change" indicator.
  168. Caret ranges are ideal when an author may make breaking changes
  169. between `0.2.4` and `0.3.0` releases, which is a common practice.
  170. However, it presumes that there will *not* be breaking changes between
  171. `0.2.4` and `0.2.5`. It allows for changes that are presumed to be
  172. additive (but non-breaking), according to commonly observed practices.
  173. * `^1.2.3` := `>=1.2.3 <2.0.0`
  174. * `^0.2.3` := `>=0.2.3 <0.3.0`
  175. * `^0.0.3` := `>=0.0.3 <0.0.4`
  176. * `^1.2.3-beta.2` := `>=1.2.3-beta.2 <2.0.0` Note that prereleases in
  177. the `1.2.3` version will be allowed, if they are greater than or
  178. equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
  179. `1.2.4-beta.2` would not, because it is a prerelease of a
  180. different `[major, minor, patch]` tuple.
  181. * `^0.0.3-beta` := `>=0.0.3-beta <0.0.4` Note that prereleases in the
  182. `0.0.3` version *only* will be allowed, if they are greater than or
  183. equal to `beta`. So, `0.0.3-pr.2` would be allowed.
  184. When parsing caret ranges, a missing `patch` value desugars to the
  185. number `0`, but will allow flexibility within that value, even if the
  186. major and minor versions are both `0`.
  187. * `^1.2.x` := `>=1.2.0 <2.0.0`
  188. * `^0.0.x` := `>=0.0.0 <0.1.0`
  189. * `^0.0` := `>=0.0.0 <0.1.0`
  190. A missing `minor` and `patch` values will desugar to zero, but also
  191. allow flexibility within those values, even if the major version is
  192. zero.
  193. * `^1.x` := `>=1.0.0 <2.0.0`
  194. * `^0.x` := `>=0.0.0 <1.0.0`
  195. ### Range Grammar
  196. Putting all this together, here is a Backus-Naur grammar for ranges,
  197. for the benefit of parser authors:
  198. ```bnf
  199. range-set ::= range ( logical-or range ) *
  200. logical-or ::= ( ' ' ) * '||' ( ' ' ) *
  201. range ::= hyphen | simple ( ' ' simple ) * | ''
  202. hyphen ::= partial ' - ' partial
  203. simple ::= primitive | partial | tilde | caret
  204. primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | ) partial
  205. partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
  206. xr ::= 'x' | 'X' | '*' | nr
  207. nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
  208. tilde ::= '~' partial
  209. caret ::= '^' partial
  210. qualifier ::= ( '-' pre )? ( '+' build )?
  211. pre ::= parts
  212. build ::= parts
  213. parts ::= part ( '.' part ) *
  214. part ::= nr | [-0-9A-Za-z]+
  215. ```
  216. ## Functions
  217. All methods and classes take a final `loose` boolean argument that, if
  218. true, will be more forgiving about not-quite-valid semver strings.
  219. The resulting output will always be 100% strict, of course.
  220. Strict-mode Comparators and Ranges will be strict about the SemVer
  221. strings that they parse.
  222. * `valid(v)`: Return the parsed version, or null if it's not valid.
  223. * `inc(v, release)`: Return the version incremented by the release
  224. type (`major`, `premajor`, `minor`, `preminor`, `patch`,
  225. `prepatch`, or `prerelease`), or null if it's not valid
  226. * `premajor` in one call will bump the version up to the next major
  227. version and down to a prerelease of that major version.
  228. `preminor`, and `prepatch` work the same way.
  229. * If called from a non-prerelease version, the `prerelease` will work the
  230. same as `prepatch`. It increments the patch version, then makes a
  231. prerelease. If the input version is already a prerelease it simply
  232. increments it.
  233. * `prerelease(v)`: Returns an array of prerelease components, or null
  234. if none exist. Example: `prerelease('1.2.3-alpha.1') -> ['alpha', 1]`
  235. * `major(v)`: Return the major version number.
  236. * `minor(v)`: Return the minor version number.
  237. * `patch(v)`: Return the patch version number.
  238. * `intersects(r1, r2, loose)`: Return true if the two supplied ranges
  239. or comparators intersect.
  240. ### Comparison
  241. * `gt(v1, v2)`: `v1 > v2`
  242. * `gte(v1, v2)`: `v1 >= v2`
  243. * `lt(v1, v2)`: `v1 < v2`
  244. * `lte(v1, v2)`: `v1 <= v2`
  245. * `eq(v1, v2)`: `v1 == v2` This is true if they're logically equivalent,
  246. even if they're not the exact same string. You already know how to
  247. compare strings.
  248. * `neq(v1, v2)`: `v1 != v2` The opposite of `eq`.
  249. * `cmp(v1, comparator, v2)`: Pass in a comparison string, and it'll call
  250. the corresponding function above. `"==="` and `"!=="` do simple
  251. string comparison, but are included for completeness. Throws if an
  252. invalid comparison string is provided.
  253. * `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if
  254. `v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
  255. * `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions
  256. in descending order when passed to `Array.sort()`.
  257. * `diff(v1, v2)`: Returns difference between two versions by the release type
  258. (`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`),
  259. or null if the versions are the same.
  260. ### Comparators
  261. * `intersects(comparator)`: Return true if the comparators intersect
  262. ### Ranges
  263. * `validRange(range)`: Return the valid range or null if it's not valid
  264. * `satisfies(version, range)`: Return true if the version satisfies the
  265. range.
  266. * `maxSatisfying(versions, range)`: Return the highest version in the list
  267. that satisfies the range, or `null` if none of them do.
  268. * `minSatisfying(versions, range)`: Return the lowest version in the list
  269. that satisfies the range, or `null` if none of them do.
  270. * `gtr(version, range)`: Return `true` if version is greater than all the
  271. versions possible in the range.
  272. * `ltr(version, range)`: Return `true` if version is less than all the
  273. versions possible in the range.
  274. * `outside(version, range, hilo)`: Return true if the version is outside
  275. the bounds of the range in either the high or low direction. The
  276. `hilo` argument must be either the string `'>'` or `'<'`. (This is
  277. the function called by `gtr` and `ltr`.)
  278. * `intersects(range)`: Return true if any of the ranges comparators intersect
  279. Note that, since ranges may be non-contiguous, a version might not be
  280. greater than a range, less than a range, *or* satisfy a range! For
  281. example, the range `1.2 <1.2.9 || >2.0.0` would have a hole from `1.2.9`
  282. until `2.0.0`, so the version `1.2.10` would not be greater than the
  283. range (because `2.0.1` satisfies, which is higher), nor less than the
  284. range (since `1.2.8` satisfies, which is lower), and it also does not
  285. satisfy the range.
  286. If you want to know if a version satisfies or does not satisfy a
  287. range, use the `satisfies(version, range)` function.
  288. ### Coercion
  289. * `coerce(version)`: Coerces a string to semver if possible
  290. This aims to provide a very forgiving translation of a non-semver
  291. string to semver. It looks for the first digit in a string, and
  292. consumes all remaining characters which satisfy at least a partial semver
  293. (e.g., `1`, `1.2`, `1.2.3`) up to the max permitted length (256 characters).
  294. Longer versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`).
  295. All surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes `3.4.0`).
  296. Only text which lacks digits will fail coercion (`version one` is not valid).
  297. The maximum length for any semver component considered for coercion is 16 characters;
  298. longer components will be ignored (`10000000000000000.4.7.4` becomes `4.7.4`).
  299. The maximum value for any semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`;
  300. higher value components are invalid (`9999999999999999.4.7.4` is likely invalid).