deps: upgrade to npm 2.14.2
[platform/upstream/nodejs.git] / deps / npm / html / doc / misc / semver.html
1 <!doctype html>
2 <html>
3   <title>semver</title>
4   <meta http-equiv="content-type" value="text/html;utf-8">
5   <link rel="stylesheet" type="text/css" href="../../static/style.css">
6   <link rel="canonical" href="https://www.npmjs.org/doc/misc/semver.html">
7   <script async=true src="../../static/toc.js"></script>
8
9   <body>
10     <div id="wrapper">
11
12 <h1><a href="../misc/semver.html">semver</a></h1> <p>The semantic versioner for npm</p>
13 <h2 id="usage">Usage</h2>
14 <pre><code>$ npm install semver
15
16 semver.valid(&#39;1.2.3&#39;) // &#39;1.2.3&#39;
17 semver.valid(&#39;a.b.c&#39;) // null
18 semver.clean(&#39;  =v1.2.3   &#39;) // &#39;1.2.3&#39;
19 semver.satisfies(&#39;1.2.3&#39;, &#39;1.x || &gt;=2.5.0 || 5.0.0 - 7.2.3&#39;) // true
20 semver.gt(&#39;1.2.3&#39;, &#39;9.8.7&#39;) // false
21 semver.lt(&#39;1.2.3&#39;, &#39;9.8.7&#39;) // true
22 </code></pre><p>As a command-line utility:</p>
23 <pre><code>$ semver -h
24
25 Usage: semver &lt;version&gt; [&lt;version&gt; [...]] [-r &lt;range&gt; | -i &lt;inc&gt; | --preid &lt;identifier&gt; | -l | -rv]
26 Test if version(s) satisfy the supplied range(s), and sort them.
27
28 Multiple versions or ranges may be supplied, unless increment
29 option is specified.  In that case, only a single version may
30 be used, and it is incremented by the specified level
31
32 Program exits successfully if any valid version satisfies
33 all supplied ranges, and prints all satisfying versions.
34
35 If no versions are valid, or ranges are not satisfied,
36 then exits failure.
37
38 Versions are printed in ascending order, so supplying
39 multiple versions to the utility will just sort them.
40 </code></pre><h2 id="versions">Versions</h2>
41 <p>A &quot;version&quot; is described by the <code>v2.0.0</code> specification found at
42 <a href="http://semver.org/">http://semver.org/</a>.</p>
43 <p>A leading <code>&quot;=&quot;</code> or <code>&quot;v&quot;</code> character is stripped off and ignored.</p>
44 <h2 id="ranges">Ranges</h2>
45 <p>A <code>version range</code> is a set of <code>comparators</code> which specify versions
46 that satisfy the range.</p>
47 <p>A <code>comparator</code> is composed of an <code>operator</code> and a <code>version</code>.  The set
48 of primitive <code>operators</code> is:</p>
49 <ul>
50 <li><code>&lt;</code> Less than</li>
51 <li><code>&lt;=</code> Less than or equal to</li>
52 <li><code>&gt;</code> Greater than</li>
53 <li><code>&gt;=</code> Greater than or equal to</li>
54 <li><code>=</code> Equal.  If no operator is specified, then equality is assumed,
55 so this operator is optional, but MAY be included.</li>
56 </ul>
57 <p>For example, the comparator <code>&gt;=1.2.7</code> would match the versions
58 <code>1.2.7</code>, <code>1.2.8</code>, <code>2.5.3</code>, and <code>1.3.9</code>, but not the versions <code>1.2.6</code>
59 or <code>1.1.0</code>.</p>
60 <p>Comparators can be joined by whitespace to form a <code>comparator set</code>,
61 which is satisfied by the <strong>intersection</strong> of all of the comparators
62 it includes.</p>
63 <p>A range is composed of one or more comparator sets, joined by <code>||</code>.  A
64 version matches a range if and only if every comparator in at least
65 one of the <code>||</code>-separated comparator sets is satisfied by the version.</p>
66 <p>For example, the range <code>&gt;=1.2.7 &lt;1.3.0</code> would match the versions
67 <code>1.2.7</code>, <code>1.2.8</code>, and <code>1.2.99</code>, but not the versions <code>1.2.6</code>, <code>1.3.0</code>,
68 or <code>1.1.0</code>.</p>
69 <p>The range <code>1.2.7 || &gt;=1.2.9 &lt;2.0.0</code> would match the versions <code>1.2.7</code>,
70 <code>1.2.9</code>, and <code>1.4.6</code>, but not the versions <code>1.2.8</code> or <code>2.0.0</code>.</p>
71 <h3 id="prerelease-tags">Prerelease Tags</h3>
72 <p>If a version has a prerelease tag (for example, <code>1.2.3-alpha.3</code>) then
73 it will only be allowed to satisfy comparator sets if at least one
74 comparator with the same <code>[major, minor, patch]</code> tuple also has a
75 prerelease tag.</p>
76 <p>For example, the range <code>&gt;1.2.3-alpha.3</code> would be allowed to match the
77 version <code>1.2.3-alpha.7</code>, but it would <em>not</em> be satisfied by
78 <code>3.4.5-alpha.9</code>, even though <code>3.4.5-alpha.9</code> is technically &quot;greater
79 than&quot; <code>1.2.3-alpha.3</code> according to the SemVer sort rules.  The version
80 range only accepts prerelease tags on the <code>1.2.3</code> version.  The
81 version <code>3.4.5</code> <em>would</em> satisfy the range, because it does not have a
82 prerelease flag, and <code>3.4.5</code> is greater than <code>1.2.3-alpha.7</code>.</p>
83 <p>The purpose for this behavior is twofold.  First, prerelease versions
84 frequently are updated very quickly, and contain many breaking changes
85 that are (by the author&#39;s design) not yet fit for public consumption.
86 Therefore, by default, they are excluded from range matching
87 semantics.</p>
88 <p>Second, a user who has opted into using a prerelease version has
89 clearly indicated the intent to use <em>that specific</em> set of
90 alpha/beta/rc versions.  By including a prerelease tag in the range,
91 the user is indicating that they are aware of the risk.  However, it
92 is still not appropriate to assume that they have opted into taking a
93 similar risk on the <em>next</em> set of prerelease versions.</p>
94 <h4 id="prerelease-identifiers">Prerelease Identifiers</h4>
95 <p>The method <code>.inc</code> takes an additional <code>identifier</code> string argument that
96 will append the value of the string as a prerelease identifier:</p>
97 <pre><code class="lang-javascript">&gt; semver.inc(&#39;1.2.3&#39;, &#39;pre&#39;, &#39;beta&#39;)
98 &#39;1.2.4-beta.0&#39;
99 </code></pre>
100 <p>command-line example:</p>
101 <pre><code class="lang-shell">$ semver 1.2.3 -i prerelease --preid beta
102 1.2.4-beta.0
103 </code></pre>
104 <p>Which then can be used to increment further:</p>
105 <pre><code class="lang-shell">$ semver 1.2.4-beta.0 -i prerelease
106 1.2.4-beta.1
107 </code></pre>
108 <h3 id="advanced-range-syntax">Advanced Range Syntax</h3>
109 <p>Advanced range syntax desugars to primitive comparators in
110 deterministic ways.</p>
111 <p>Advanced ranges may be combined in the same way as primitive
112 comparators using white space or <code>||</code>.</p>
113 <h4 id="hyphen-ranges-x-y-z-a-b-c-">Hyphen Ranges <code>X.Y.Z - A.B.C</code></h4>
114 <p>Specifies an inclusive set.</p>
115 <ul>
116 <li><code>1.2.3 - 2.3.4</code> := <code>&gt;=1.2.3 &lt;=2.3.4</code></li>
117 </ul>
118 <p>If a partial version is provided as the first version in the inclusive
119 range, then the missing pieces are replaced with zeroes.</p>
120 <ul>
121 <li><code>1.2 - 2.3.4</code> := <code>&gt;=1.2.0 &lt;=2.3.4</code></li>
122 </ul>
123 <p>If a partial version is provided as the second version in the
124 inclusive range, then all versions that start with the supplied parts
125 of the tuple are accepted, but nothing that would be greater than the
126 provided tuple parts.</p>
127 <ul>
128 <li><code>1.2.3 - 2.3</code> := <code>&gt;=1.2.3 &lt;2.4.0</code></li>
129 <li><code>1.2.3 - 2</code> := <code>&gt;=1.2.3 &lt;3.0.0</code></li>
130 </ul>
131 <h4 id="x-ranges-1-2-x-1-x-1-2-">X-Ranges <code>1.2.x</code> <code>1.X</code> <code>1.2.*</code> <code>*</code></h4>
132 <p>Any of <code>X</code>, <code>x</code>, or <code>*</code> may be used to &quot;stand in&quot; for one of the
133 numeric values in the <code>[major, minor, patch]</code> tuple.</p>
134 <ul>
135 <li><code>*</code> := <code>&gt;=0.0.0</code> (Any version satisfies)</li>
136 <li><code>1.x</code> := <code>&gt;=1.0.0 &lt;2.0.0</code> (Matching major version)</li>
137 <li><code>1.2.x</code> := <code>&gt;=1.2.0 &lt;1.3.0</code> (Matching major and minor versions)</li>
138 </ul>
139 <p>A partial version range is treated as an X-Range, so the special
140 character is in fact optional.</p>
141 <ul>
142 <li><code>&quot;&quot;</code> (empty string) := <code>*</code> := <code>&gt;=0.0.0</code></li>
143 <li><code>1</code> := <code>1.x.x</code> := <code>&gt;=1.0.0 &lt;2.0.0</code></li>
144 <li><code>1.2</code> := <code>1.2.x</code> := <code>&gt;=1.2.0 &lt;1.3.0</code></li>
145 </ul>
146 <h4 id="tilde-ranges-1-2-3-1-2-1-">Tilde Ranges <code>~1.2.3</code> <code>~1.2</code> <code>~1</code></h4>
147 <p>Allows patch-level changes if a minor version is specified on the
148 comparator.  Allows minor-level changes if not.</p>
149 <ul>
150 <li><code>~1.2.3</code> := <code>&gt;=1.2.3 &lt;1.(2+1).0</code> := <code>&gt;=1.2.3 &lt;1.3.0</code></li>
151 <li><code>~1.2</code> := <code>&gt;=1.2.0 &lt;1.(2+1).0</code> := <code>&gt;=1.2.0 &lt;1.3.0</code> (Same as <code>1.2.x</code>)</li>
152 <li><code>~1</code> := <code>&gt;=1.0.0 &lt;(1+1).0.0</code> := <code>&gt;=1.0.0 &lt;2.0.0</code> (Same as <code>1.x</code>)</li>
153 <li><code>~0.2.3</code> := <code>&gt;=0.2.3 &lt;0.(2+1).0</code> := <code>&gt;=0.2.3 &lt;0.3.0</code></li>
154 <li><code>~0.2</code> := <code>&gt;=0.2.0 &lt;0.(2+1).0</code> := <code>&gt;=0.2.0 &lt;0.3.0</code> (Same as <code>0.2.x</code>)</li>
155 <li><code>~0</code> := <code>&gt;=0.0.0 &lt;(0+1).0.0</code> := <code>&gt;=0.0.0 &lt;1.0.0</code> (Same as <code>0.x</code>)</li>
156 <li><code>~1.2.3-beta.2</code> := <code>&gt;=1.2.3-beta.2 &lt;1.3.0</code> Note that prereleases in
157 the <code>1.2.3</code> version will be allowed, if they are greater than or
158 equal to <code>beta.2</code>.  So, <code>1.2.3-beta.4</code> would be allowed, but
159 <code>1.2.4-beta.2</code> would not, because it is a prerelease of a
160 different <code>[major, minor, patch]</code> tuple.</li>
161 </ul>
162 <h4 id="caret-ranges-1-2-3-0-2-5-0-0-4-">Caret Ranges <code>^1.2.3</code> <code>^0.2.5</code> <code>^0.0.4</code></h4>
163 <p>Allows changes that do not modify the left-most non-zero digit in the
164 <code>[major, minor, patch]</code> tuple.  In other words, this allows patch and
165 minor updates for versions <code>1.0.0</code> and above, patch updates for
166 versions <code>0.X &gt;=0.1.0</code>, and <em>no</em> updates for versions <code>0.0.X</code>.</p>
167 <p>Many authors treat a <code>0.x</code> version as if the <code>x</code> were the major
168 &quot;breaking-change&quot; indicator.</p>
169 <p>Caret ranges are ideal when an author may make breaking changes
170 between <code>0.2.4</code> and <code>0.3.0</code> releases, which is a common practice.
171 However, it presumes that there will <em>not</em> be breaking changes between
172 <code>0.2.4</code> and <code>0.2.5</code>.  It allows for changes that are presumed to be
173 additive (but non-breaking), according to commonly observed practices.</p>
174 <ul>
175 <li><code>^1.2.3</code> := <code>&gt;=1.2.3 &lt;2.0.0</code></li>
176 <li><code>^0.2.3</code> := <code>&gt;=0.2.3 &lt;0.3.0</code></li>
177 <li><code>^0.0.3</code> := <code>&gt;=0.0.3 &lt;0.0.4</code></li>
178 <li><code>^1.2.3-beta.2</code> := <code>&gt;=1.2.3-beta.2 &lt;2.0.0</code> Note that prereleases in
179 the <code>1.2.3</code> version will be allowed, if they are greater than or
180 equal to <code>beta.2</code>.  So, <code>1.2.3-beta.4</code> would be allowed, but
181 <code>1.2.4-beta.2</code> would not, because it is a prerelease of a
182 different <code>[major, minor, patch]</code> tuple.</li>
183 <li><code>^0.0.3-beta</code> := <code>&gt;=0.0.3-beta &lt;0.0.4</code>  Note that prereleases in the
184 <code>0.0.3</code> version <em>only</em> will be allowed, if they are greater than or
185 equal to <code>beta</code>.  So, <code>0.0.3-pr.2</code> would be allowed.</li>
186 </ul>
187 <p>When parsing caret ranges, a missing <code>patch</code> value desugars to the
188 number <code>0</code>, but will allow flexibility within that value, even if the
189 major and minor versions are both <code>0</code>.</p>
190 <ul>
191 <li><code>^1.2.x</code> := <code>&gt;=1.2.0 &lt;2.0.0</code></li>
192 <li><code>^0.0.x</code> := <code>&gt;=0.0.0 &lt;0.1.0</code></li>
193 <li><code>^0.0</code> := <code>&gt;=0.0.0 &lt;0.1.0</code></li>
194 </ul>
195 <p>A missing <code>minor</code> and <code>patch</code> values will desugar to zero, but also
196 allow flexibility within those values, even if the major version is
197 zero.</p>
198 <ul>
199 <li><code>^1.x</code> := <code>&gt;=1.0.0 &lt;2.0.0</code></li>
200 <li><code>^0.x</code> := <code>&gt;=0.0.0 &lt;1.0.0</code></li>
201 </ul>
202 <h2 id="functions">Functions</h2>
203 <p>All methods and classes take a final <code>loose</code> boolean argument that, if
204 true, will be more forgiving about not-quite-valid semver strings.
205 The resulting output will always be 100% strict, of course.</p>
206 <p>Strict-mode Comparators and Ranges will be strict about the SemVer
207 strings that they parse.</p>
208 <ul>
209 <li><code>valid(v)</code>: Return the parsed version, or null if it&#39;s not valid.</li>
210 <li><code>inc(v, release)</code>: Return the version incremented by the release
211 type (<code>major</code>,   <code>premajor</code>, <code>minor</code>, <code>preminor</code>, <code>patch</code>,
212 <code>prepatch</code>, or <code>prerelease</code>), or null if it&#39;s not valid<ul>
213 <li><code>premajor</code> in one call will bump the version up to the next major
214 version and down to a prerelease of that major version.
215 <code>preminor</code>, and <code>prepatch</code> work the same way.</li>
216 <li>If called from a non-prerelease version, the <code>prerelease</code> will work the
217 same as <code>prepatch</code>. It increments the patch version, then makes a
218 prerelease. If the input version is already a prerelease it simply
219 increments it.</li>
220 </ul>
221 </li>
222 <li><code>major(v)</code>: Return the major version number.</li>
223 <li><code>minor(v)</code>: Return the minor version number.</li>
224 <li><code>patch(v)</code>: Return the patch version number.</li>
225 </ul>
226 <h3 id="comparison">Comparison</h3>
227 <ul>
228 <li><code>gt(v1, v2)</code>: <code>v1 &gt; v2</code></li>
229 <li><code>gte(v1, v2)</code>: <code>v1 &gt;= v2</code></li>
230 <li><code>lt(v1, v2)</code>: <code>v1 &lt; v2</code></li>
231 <li><code>lte(v1, v2)</code>: <code>v1 &lt;= v2</code></li>
232 <li><code>eq(v1, v2)</code>: <code>v1 == v2</code> This is true if they&#39;re logically equivalent,
233 even if they&#39;re not the exact same string.  You already know how to
234 compare strings.</li>
235 <li><code>neq(v1, v2)</code>: <code>v1 != v2</code> The opposite of <code>eq</code>.</li>
236 <li><code>cmp(v1, comparator, v2)</code>: Pass in a comparison string, and it&#39;ll call
237 the corresponding function above.  <code>&quot;===&quot;</code> and <code>&quot;!==&quot;</code> do simple
238 string comparison, but are included for completeness.  Throws if an
239 invalid comparison string is provided.</li>
240 <li><code>compare(v1, v2)</code>: Return <code>0</code> if <code>v1 == v2</code>, or <code>1</code> if <code>v1</code> is greater, or <code>-1</code> if
241 <code>v2</code> is greater.  Sorts in ascending order if passed to <code>Array.sort()</code>.</li>
242 <li><code>rcompare(v1, v2)</code>: The reverse of compare.  Sorts an array of versions
243 in descending order when passed to <code>Array.sort()</code>.</li>
244 <li><code>diff(v1, v2)</code>: Returns difference between two versions by the release type
245 (<code>major</code>, <code>premajor</code>, <code>minor</code>, <code>preminor</code>, <code>patch</code>, <code>prepatch</code>, or <code>prerelease</code>),
246 or null if the versions are the same.</li>
247 </ul>
248 <h3 id="ranges">Ranges</h3>
249 <ul>
250 <li><code>validRange(range)</code>: Return the valid range or null if it&#39;s not valid</li>
251 <li><code>satisfies(version, range)</code>: Return true if the version satisfies the
252 range.</li>
253 <li><code>maxSatisfying(versions, range)</code>: Return the highest version in the list
254 that satisfies the range, or <code>null</code> if none of them do.</li>
255 <li><code>gtr(version, range)</code>: Return <code>true</code> if version is greater than all the
256 versions possible in the range.</li>
257 <li><code>ltr(version, range)</code>: Return <code>true</code> if version is less than all the
258 versions possible in the range.</li>
259 <li><code>outside(version, range, hilo)</code>: Return true if the version is outside
260 the bounds of the range in either the high or low direction.  The
261 <code>hilo</code> argument must be either the string <code>&#39;&gt;&#39;</code> or <code>&#39;&lt;&#39;</code>.  (This is
262 the function called by <code>gtr</code> and <code>ltr</code>.)</li>
263 </ul>
264 <p>Note that, since ranges may be non-contiguous, a version might not be
265 greater than a range, less than a range, <em>or</em> satisfy a range!  For
266 example, the range <code>1.2 &lt;1.2.9 || &gt;2.0.0</code> would have a hole from <code>1.2.9</code>
267 until <code>2.0.0</code>, so the version <code>1.2.10</code> would not be greater than the
268 range (because <code>2.0.1</code> satisfies, which is higher), nor less than the
269 range (since <code>1.2.8</code> satisfies, which is lower), and it also does not
270 satisfy the range.</p>
271 <p>If you want to know if a version satisfies or does not satisfy a
272 range, use the <code>satisfies(version, range)</code> function.</p>
273
274 </div>
275
276 <table border=0 cellspacing=0 cellpadding=0 id=npmlogo>
277 <tr><td style="width:180px;height:10px;background:rgb(237,127,127)" colspan=18>&nbsp;</td></tr>
278 <tr><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td colspan=6 style="width:60px;height:10px;background:#fff">&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td></tr>
279 <tr><td colspan=2 style="width:20px;height:30px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=4 colspan=2>&nbsp;</td><td style="width:10px;height:20px;background:rgb(237,127,127)" rowspan=2>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=3 colspan=2>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td></tr>
280 <tr><td style="width:10px;height:10px;background:#fff" rowspan=2>&nbsp;</td></tr>
281 <tr><td style="width:10px;height:10px;background:#fff">&nbsp;</td></tr>
282 <tr><td style="width:60px;height:10px;background:rgb(237,127,127)" colspan=6>&nbsp;</td><td colspan=10 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td></tr>
283 <tr><td colspan=5 style="width:50px;height:10px;background:#fff">&nbsp;</td><td style="width:40px;height:10px;background:rgb(237,127,127)" colspan=4>&nbsp;</td><td style="width:90px;height:10px;background:#fff" colspan=9>&nbsp;</td></tr>
284 </table>
285 <p id="footer">semver &mdash; npm@2.14.2</p>
286