Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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 17KB

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