|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2022 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Semantic Version |
| 22 | + |
| 23 | +> [Regular expression][regexp] to match a [semantic version][semantic-version] string. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var reSemVer = require( '@stdlib/regexp/semver' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### reSemVer() |
| 34 | + |
| 35 | +Return a [regular expression][regexp] to match a [semantic version][semantic-version] string. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var RE_SEMVER = reSemVer(); |
| 39 | +// returns <RegExp> |
| 40 | + |
| 41 | +var parts = RE_SEMVER.exec( '1.0.0' ); |
| 42 | +/* returns |
| 43 | + [ |
| 44 | + '1.0.0', |
| 45 | + '1', |
| 46 | + '0', |
| 47 | + '0', |
| 48 | + undefined, |
| 49 | + undefined, |
| 50 | + index: 0, |
| 51 | + input: '1.0.0', |
| 52 | + groups: undefined |
| 53 | + ] |
| 54 | +*/ |
| 55 | + |
| 56 | +parts = RE_SEMVER.exec( '1.0.0-alpha.1' ); |
| 57 | +/* returns |
| 58 | + [ |
| 59 | + '1.0.0-alpha.1', |
| 60 | + '1', |
| 61 | + '0', |
| 62 | + '0', |
| 63 | + 'alpha', |
| 64 | + '1', |
| 65 | + index: 0, |
| 66 | + input: '1.0.0-alpha.1', |
| 67 | + groups: undefined |
| 68 | + ] |
| 69 | +*/ |
| 70 | +``` |
| 71 | + |
| 72 | +#### reSemVer.REGEXP |
| 73 | + |
| 74 | +[Regular expression][regexp] to match a [semantic version][semantic-version] string. |
| 75 | + |
| 76 | +```javascript |
| 77 | +var parts = reSemVer.REGEXP.exec( '0.2.3' ); |
| 78 | +/* returns |
| 79 | + [ |
| 80 | + '0.2.3', |
| 81 | + '0', |
| 82 | + '2', |
| 83 | + '3', |
| 84 | + undefined, |
| 85 | + undefined, |
| 86 | + index: 0, |
| 87 | + input: '0.2.3', |
| 88 | + groups: undefined |
| 89 | + ] |
| 90 | +*/ |
| 91 | +``` |
| 92 | + |
| 93 | +</section> |
| 94 | + |
| 95 | +<!-- /.usage --> |
| 96 | + |
| 97 | +<section class="examples"> |
| 98 | + |
| 99 | +## Examples |
| 100 | + |
| 101 | +<!-- eslint no-undef: "error" --> |
| 102 | + |
| 103 | +```javascript |
| 104 | +var reSemVer = require( '@stdlib/regexp/semver' ); |
| 105 | + |
| 106 | +var RE_SEMVER = reSemVer(); |
| 107 | +var version = '1.0.0'; |
| 108 | +var bool = RE_SEMVER.test( version ); |
| 109 | +// returns true |
| 110 | + |
| 111 | +version = '1.0.0-alpha.1'; |
| 112 | +bool = RE_SEMVER.test( version ); |
| 113 | +// returns true |
| 114 | + |
| 115 | +version = '1.0.0-alpha.1+build.1'; |
| 116 | +bool = RE_SEMVER.test( version ); |
| 117 | +// returns true |
| 118 | + |
| 119 | +version = '1.0.0-alpha.1+build.1.2.b8f12d7'; |
| 120 | +bool = RE_SEMVER.test( version ); |
| 121 | +// returns true |
| 122 | + |
| 123 | +version = '1.2'; |
| 124 | +bool = RE_SEMVER.test( version ); |
| 125 | +// returns false |
| 126 | + |
| 127 | +version = '-1.2.3'; |
| 128 | +bool = RE_SEMVER.test( version ); |
| 129 | +// returns false |
| 130 | + |
| 131 | +version = 'a.b.c'; |
| 132 | +bool = RE_SEMVER.test( version ); |
| 133 | +// returns false |
| 134 | +``` |
| 135 | + |
| 136 | +</section> |
| 137 | + |
| 138 | +<!-- /.examples --> |
| 139 | + |
| 140 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 141 | + |
| 142 | +<section class="related"> |
| 143 | + |
| 144 | +</section> |
| 145 | + |
| 146 | +<!-- /.related --> |
| 147 | + |
| 148 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 149 | + |
| 150 | +<section class="links"> |
| 151 | + |
| 152 | +[regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions |
| 153 | + |
| 154 | +[semantic-version]: https://semver.org/ |
| 155 | + |
| 156 | +<!-- <related-links> --> |
| 157 | + |
| 158 | +<!-- </related-links> --> |
| 159 | + |
| 160 | +</section> |
| 161 | + |
| 162 | +<!-- /.links --> |
0 commit comments