Merge branch 'v0.10'
[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; | -d &lt;dec&gt;]
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 or decrement options are specified.  In that case, only a single
30 version may 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 v2.0.0 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>The following range styles are supported:</p>
46 <ul>
47 <li><code>1.2.3</code> A specific version.  When nothing else will do.  Note that
48 build metadata is still ignored, so <code>1.2.3+build2012</code> will satisfy
49 this range.</li>
50 <li><code>&gt;1.2.3</code> Greater than a specific version.</li>
51 <li><code>&lt;1.2.3</code> Less than a specific version.  If there is no prerelease
52 tag on the version range, then no prerelease version will be allowed
53 either, even though these are technically &quot;less than&quot;.</li>
54 <li><code>&gt;=1.2.3</code> Greater than or equal to.  Note that prerelease versions
55 are NOT equal to their &quot;normal&quot; equivalents, so <code>1.2.3-beta</code> will
56 not satisfy this range, but <code>2.3.0-beta</code> will.</li>
57 <li><code>&lt;=1.2.3</code> Less than or equal to.  In this case, prerelease versions
58 ARE allowed, so <code>1.2.3-beta</code> would satisfy.</li>
59 <li><code>1.2.3 - 2.3.4</code> := <code>&gt;=1.2.3 &lt;=2.3.4</code></li>
60 <li><code>~1.2.3</code> := <code>&gt;=1.2.3-0 &lt;1.3.0-0</code>  &quot;Reasonably close to 1.2.3&quot;.  When
61 using tilde operators, prerelease versions are supported as well,
62 but a prerelease of the next significant digit will NOT be
63 satisfactory, so <code>1.3.0-beta</code> will not satisfy <code>~1.2.3</code>.</li>
64 <li><code>^1.2.3</code> := <code>&gt;=1.2.3-0 &lt;2.0.0-0</code>  &quot;Compatible with 1.2.3&quot;.  When
65 using caret operators, anything from the specified version (including
66 prerelease) will be supported up to, but not including, the next
67 major version (or its prereleases). <code>1.5.1</code> will satisfy <code>^1.2.3</code>,
68 while <code>1.2.2</code> and <code>2.0.0-beta</code> will not.</li>
69 <li><code>^0.1.3</code> := <code>&gt;=0.1.3-0 &lt;0.2.0-0</code> &quot;Compatible with 0.1.3&quot;. 0.x.x versions are
70 special: the first non-zero component indicates potentially breaking changes,
71 meaning the caret operator matches any version with the same first non-zero
72 component starting at the specified version.</li>
73 <li><code>^0.0.2</code> := <code>=0.0.2</code> &quot;Only the version 0.0.2 is considered compatible&quot;</li>
74 <li><code>~1.2</code> := <code>&gt;=1.2.0-0 &lt;1.3.0-0</code> &quot;Any version starting with 1.2&quot;</li>
75 <li><code>^1.2</code> := <code>&gt;=1.2.0-0 &lt;2.0.0-0</code> &quot;Any version compatible with 1.2&quot;</li>
76 <li><code>1.2.x</code> := <code>&gt;=1.2.0-0 &lt;1.3.0-0</code> &quot;Any version starting with 1.2&quot;</li>
77 <li><code>~1</code> := <code>&gt;=1.0.0-0 &lt;2.0.0-0</code> &quot;Any version starting with 1&quot;</li>
78 <li><code>^1</code> := <code>&gt;=1.0.0-0 &lt;2.0.0-0</code> &quot;Any version compatible with 1&quot;</li>
79 <li><code>1.x</code> := <code>&gt;=1.0.0-0 &lt;2.0.0-0</code> &quot;Any version starting with 1&quot;</li>
80 </ul>
81 <p>Ranges can be joined with either a space (which implies &quot;and&quot;) or a
82 <code>||</code> (which implies &quot;or&quot;).</p>
83 <h2 id="functions">Functions</h2>
84 <p>All methods and classes take a final <code>loose</code> boolean argument that, if
85 true, will be more forgiving about not-quite-valid semver strings.
86 The resulting output will always be 100% strict, of course.</p>
87 <p>Strict-mode Comparators and Ranges will be strict about the SemVer
88 strings that they parse.</p>
89 <ul>
90 <li>valid(v): Return the parsed version, or null if it&#39;s not valid.</li>
91 <li>inc(v, release): Return the version incremented by the release type
92 (major, minor, patch, or prerelease), or null if it&#39;s not valid.</li>
93 </ul>
94 <h3 id="comparison">Comparison</h3>
95 <ul>
96 <li>gt(v1, v2): <code>v1 &gt; v2</code></li>
97 <li>gte(v1, v2): <code>v1 &gt;= v2</code></li>
98 <li>lt(v1, v2): <code>v1 &lt; v2</code></li>
99 <li>lte(v1, v2): <code>v1 &lt;= v2</code></li>
100 <li>eq(v1, v2): <code>v1 == v2</code> This is true if they&#39;re logically equivalent,
101 even if they&#39;re not the exact same string.  You already know how to
102 compare strings.</li>
103 <li>neq(v1, v2): <code>v1 != v2</code> The opposite of eq.</li>
104 <li>cmp(v1, comparator, v2): Pass in a comparison string, and it&#39;ll call
105 the corresponding function above.  <code>&quot;===&quot;</code> and <code>&quot;!==&quot;</code> do simple
106 string comparison, but are included for completeness.  Throws if an
107 invalid comparison string is provided.</li>
108 <li>compare(v1, v2): Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if
109 v2 is greater.  Sorts in ascending order if passed to Array.sort().</li>
110 <li>rcompare(v1, v2): The reverse of compare.  Sorts an array of versions
111 in descending order when passed to Array.sort().</li>
112 </ul>
113 <h3 id="ranges">Ranges</h3>
114 <ul>
115 <li>validRange(range): Return the valid range or null if it&#39;s not valid</li>
116 <li>satisfies(version, range): Return true if the version satisfies the
117 range.</li>
118 <li>maxSatisfying(versions, range): Return the highest version in the list
119 that satisfies the range, or null if none of them do.</li>
120 <li>gtr(version, range): Return true if version is greater than all the
121 versions possible in the range.</li>
122 <li>ltr(version, range): Return true if version is less than all the
123 versions possible in the range.</li>
124 <li>outside(version, range, hilo): Return true if the version is outside
125 the bounds of the range in either the high or low direction.  The
126 <code>hilo</code> argument must be either the string <code>&#39;&gt;&#39;</code> or <code>&#39;&lt;&#39;</code>.  (This is
127 the function called by <code>gtr</code> and <code>ltr</code>.)</li>
128 </ul>
129 <p>Note that, since ranges may be non-contiguous, a version might not be
130 greater than a range, less than a range, <em>or</em> satisfy a range!  For
131 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>
132 until <code>2.0.0</code>, so the version <code>1.2.10</code> would not be greater than the
133 range (because 2.0.1 satisfies, which is higher), nor less than the
134 range (since 1.2.8 satisfies, which is lower), and it also does not
135 satisfy the range.</p>
136 <p>If you want to know if a version satisfies or does not satisfy a
137 range, use the <code>satisfies(version, range)</code> function.</p>
138
139 </div>
140
141 <table border=0 cellspacing=0 cellpadding=0 id=npmlogo>
142 <tr><td style="width:180px;height:10px;background:rgb(237,127,127)" colspan=18>&nbsp;</td></tr>
143 <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>
144 <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>
145 <tr><td style="width:10px;height:10px;background:#fff" rowspan=2>&nbsp;</td></tr>
146 <tr><td style="width:10px;height:10px;background:#fff">&nbsp;</td></tr>
147 <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>
148 <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>
149 </table>
150 <p id="footer">semver &mdash; npm@1.4.10</p>
151