Skip to content

Commit c42e1bc

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 14c67aa + 24163c0 commit c42e1bc

File tree

26 files changed

+1580
-0
lines changed

26 files changed

+1580
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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 -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pkg = require( './../package.json' ).name;
25+
var reSemVer = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg, function benchmark( b ) {
31+
var values;
32+
var out;
33+
var str;
34+
var i;
35+
36+
values = [
37+
'1.2.3',
38+
'1.0.0-alpha',
39+
'1.0.0-alpha.1',
40+
'1.0.0-0.3.7',
41+
'1.0.0-x.7.z.92',
42+
'1.0.0-alpha+001',
43+
'1.0.0+20130313144700',
44+
'1.0.0-beta+exp.sha.5',
45+
'1.0.0+21AF26D3--117B344092BD',
46+
'1.0.0+exp.sha.5114f85',
47+
'1.0.0+21AF26D3--117B344092BD',
48+
'1.0.0+exp.sha.5114f85',
49+
'1.2',
50+
'-1.2.3',
51+
'1.2.3-',
52+
'1.2.3-+',
53+
'1.2.3-+001',
54+
'1.2.3-01',
55+
'1.2.3-0123',
56+
'1.2.3-0123.0123',
57+
'1.2.3-0123.0123.0123'
58+
];
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
str = values[ i % values.length ];
63+
out = reSemVer.REGEXP.exec( str );
64+
if ( !out || !out.length ) {
65+
b.fail( 'should match a semantic version string' );
66+
}
67+
}
68+
b.toc();
69+
if ( !out || !out.length ) {
70+
b.fail( 'should match a semantic version string' );
71+
}
72+
b.pass( 'benchmark finished' );
73+
b.end();
74+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{alias}}()
2+
Returns a regular expression to match a semantic version string.
3+
4+
Returns
5+
-------
6+
out: RegExp
7+
Regular expression.
8+
9+
Examples
10+
--------
11+
> var RE_SEMVER = {{alias}}()
12+
<RegExp>
13+
> var bool = RE_SEMVER.test( '1.0.0' )
14+
true
15+
> bool = RE_SEMVER.test( '1.0.0-alpha.1' )
16+
true
17+
> bool = RE_SEMVER.test( 'abc' )
18+
false
19+
> bool = RE_SEMVER.test( '1.0.0-alpha.1+build.1' )
20+
true
21+
22+
23+
{{alias}}.REGEXP
24+
Regular expression to match a semantic version string.
25+
26+
Examples
27+
--------
28+
> var bool = {{alias}}.REGEXP.test( '1.0.0' )
29+
true
30+
> bool = {{alias}}.REGEXP.test( '-1.0.0-alpha.1' )
31+
false
32+
33+
34+
See Also
35+
--------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/**
22+
* Interface for a regular expression to match semantic version strings.
23+
*/
24+
interface ReSemVer {
25+
/**
26+
* Returns a regular expression to match a semantic version string.
27+
*
28+
* @returns regular expression
29+
*
30+
* @example
31+
* var RE_SEMVER = reSemVer();
32+
* // returns <RegExp>
33+
*
34+
* var bool = RE_SEMVER.test( '1.0.0' );
35+
* // returns true
36+
*
37+
* bool = RE_SEMVER.test( '1.0.0-alpha.1' );
38+
* // returns true
39+
*
40+
* bool = RE_SEMVER.test( 'abc' );
41+
* // returns false
42+
*
43+
* bool = RE_SEMVER.test( '1.0.0-alpha.1+build.1' );
44+
* // returns true
45+
*/
46+
(): RegExp;
47+
48+
/**
49+
* Regular expression to match a semantic version string.
50+
*
51+
* @example
52+
* var bool = reSemVer.REGEXP.test( '1.0.0' );
53+
* // returns true
54+
*/
55+
REGEXP: RegExp;
56+
}
57+
58+
/**
59+
* Returns a regular expression to match a semantic version string.
60+
*
61+
* @returns regular expression
62+
*
63+
* @example
64+
* var RE_SEMVER = reSemVer();
65+
* // returns <RegExp>
66+
*
67+
* var bool = RE_SEMVER.test( '1.0.0' );
68+
* // returns true
69+
*
70+
* bool = RE_SEMVER.test( '1.0.0-alpha.1' );
71+
* // returns true
72+
*
73+
* bool = RE_SEMVER.test( 'abc' );
74+
* // returns false
75+
*
76+
* bool = RE_SEMVER.test( '1.0.0-alpha.1+build.1' );
77+
* // returns true
78+
*/
79+
declare var reSemVer: ReSemVer;
80+
81+
82+
// EXPORTS //
83+
84+
export = reSemVer;
85+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import reSemVer = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a regular expression...
25+
{
26+
reSemVer(); // $ExpectType RegExp
27+
}
28+
29+
// The compiler throws an error if the function is provided arguments...
30+
{
31+
reSemVer( true ); // $ExpectError
32+
reSemVer( [], 123 ); // $ExpectError
33+
}
34+
35+
// Attached to main export is a `REGEXP` property that is a regular expression...
36+
{
37+
// tslint:disable-next-line:no-unused-expression
38+
reSemVer.REGEXP; // $ExpectType RegExp
39+
}

0 commit comments

Comments
 (0)