Ohm-Management - Projektarbeit B-ME
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.

README.md 15KB

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