Skip to content

Commit 461c48e

Browse files
committed
Refactor as factory functions
1 parent e55458e commit 461c48e

File tree

29 files changed

+1028
-348
lines changed

29 files changed

+1028
-348
lines changed

lib/node_modules/@stdlib/namespace/lib/namespace/r.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -940,28 +940,6 @@ ns.push({
940940
]
941941
});
942942

943-
ns.push({
944-
'alias': 'RE_BASENAME_POSIX',
945-
'path': '@stdlib/regexp/basename-posix',
946-
'value': require( '@stdlib/regexp/basename-posix' ),
947-
'type': 'RegExp',
948-
'related': [
949-
'@stdlib/regexp/basename',
950-
'@stdlib/regexp/basename-windows'
951-
]
952-
});
953-
954-
ns.push({
955-
'alias': 'RE_BASENAME_WINDOWS',
956-
'path': '@stdlib/regexp/basename-windows',
957-
'value': require( '@stdlib/regexp/basename-windows' ),
958-
'type': 'RegExp',
959-
'related': [
960-
'@stdlib/regexp/basename',
961-
'@stdlib/regexp/basename-posix'
962-
]
963-
});
964-
965943
ns.push({
966944
'alias': 'RE_COLOR_HEXADECIMAL',
967945
'path': '@stdlib/regexp/color-hexadecimal',
@@ -1202,6 +1180,28 @@ ns.push({
12021180
]
12031181
});
12041182

1183+
ns.push({
1184+
'alias': 'reBasenamePosix',
1185+
'path': '@stdlib/regexp/basename-posix',
1186+
'value': require( '@stdlib/regexp/basename-posix' ),
1187+
'type': 'Function',
1188+
'related': [
1189+
'@stdlib/regexp/basename',
1190+
'@stdlib/regexp/basename-windows'
1191+
]
1192+
});
1193+
1194+
ns.push({
1195+
'alias': 'reBasenameWindows',
1196+
'path': '@stdlib/regexp/basename-windows',
1197+
'value': require( '@stdlib/regexp/basename-windows' ),
1198+
'type': 'Function',
1199+
'related': [
1200+
'@stdlib/regexp/basename',
1201+
'@stdlib/regexp/basename-posix'
1202+
]
1203+
});
1204+
12051205
ns.push({
12061206
'alias': 'reDecimalNumber',
12071207
'path': '@stdlib/regexp/decimal-number',

lib/node_modules/@stdlib/regexp/basename-posix/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,28 @@ limitations under the License.
2727
## Usage
2828

2929
```javascript
30-
var RE_BASENAME_POSIX = require( '@stdlib/regexp/basename-posix' );
30+
var reBasenamePosix = require( '@stdlib/regexp/basename-posix' );
3131
```
3232

33-
#### RE_BASENAME_POSIX
33+
#### reBasenamePosix()
3434

35-
[Regular expression][regexp] to capture the last part of a [POSIX][posix] path.
35+
Returns a [regular expression][regexp] to capture the last part of a [POSIX][posix] path.
3636

3737
```javascript
38+
var RE_BASENAME_POSIX = reBasenamePosix();
3839
var base = RE_BASENAME_POSIX.exec( 'foo/bar/index.js' )[ 1 ];
3940
// returns 'index.js'
4041
```
4142

43+
#### reBasenamePosix.REGEXP
44+
45+
[Regular expression][regexp] to capture the last part of a [POSIX][posix] path.
46+
47+
```javascript
48+
var base = reBasenamePosix.REGEXP.exec( 'foo/bar/index.js' )[ 1 ];
49+
// returns 'index.js'
50+
```
51+
4252
</section>
4353

4454
<!-- /.usage -->
@@ -50,8 +60,9 @@ var base = RE_BASENAME_POSIX.exec( 'foo/bar/index.js' )[ 1 ];
5060
<!-- eslint no-undef: "error" -->
5161

5262
```javascript
53-
var RE_BASENAME_POSIX = require( '@stdlib/regexp/basename-posix' );
63+
var reBasenamePosix = require( '@stdlib/regexp/basename-posix' );
5464

65+
var RE_BASENAME_POSIX = reBasenamePosix();
5566
var base = RE_BASENAME_POSIX.exec( 'index.js' )[ 1 ];
5667
// returns 'index.js'
5768

lib/node_modules/@stdlib/regexp/basename-posix/benchmark/benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ var bench = require( '@stdlib/bench' );
2424
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2525
var fromCodePoint = require( '@stdlib/string/from-code-point' );
2626
var pkg = require( './../package.json' ).name;
27-
var RE_BASENAME_POSIX = require( './../lib' );
27+
var reBasenamePosix = require( './../lib' );
2828

2929

3030
// MAIN //
3131

3232
bench( pkg, function benchmark( b ) {
33+
var RE_BASENAME_POSIX;
3334
var out;
3435
var str;
3536
var i;
3637

38+
RE_BASENAME_POSIX = reBasenamePosix();
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
3941
str = '/foo/bar/beep/boop'+fromCodePoint( 97 + (i%26) )+'.js';
Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11

2-
{{alias}}
3-
Regular expression to capture the last part of a POSIX path.
2+
{{alias}}()
3+
Returns a regular expression to capture the last part of a POSIX path.
4+
5+
Returns
6+
-------
7+
re: RegExp
8+
Regular expression.
49

510
Examples
611
--------
7-
> var base = {{alias}}.exec( '/foo/bar/index.js' )[ 1 ]
12+
> var RE_BASENAME_POSIX = {{alias}}();
13+
> var base = RE_BASENAME_POSIX.exec( '/foo/bar/index.js' )[ 1 ]
814
'index.js'
9-
> base = {{alias}}.exec( './foo/bar/.gitignore' )[ 1 ]
15+
> base = RE_BASENAME_POSIX.exec( './foo/bar/.gitignore' )[ 1 ]
1016
'.gitignore'
11-
> base = {{alias}}.exec( 'foo/file.pdf' )[ 1 ]
17+
> base = RE_BASENAME_POSIX.exec( 'foo/file.pdf' )[ 1 ]
1218
'file.pdf'
13-
> base = {{alias}}.exec( '/foo/bar/file' )[ 1 ]
19+
> base = RE_BASENAME_POSIX.exec( '/foo/bar/file' )[ 1 ]
1420
'file'
15-
> base = {{alias}}.exec( 'index.js' )[ 1 ]
21+
> base = RE_BASENAME_POSIX.exec( 'index.js' )[ 1 ]
1622
'index.js'
17-
> base = {{alias}}.exec( '.' )[ 1 ]
23+
> base = RE_BASENAME_POSIX.exec( '.' )[ 1 ]
1824
'.'
19-
> base = {{alias}}.exec( './' )[ 1 ]
25+
> base = RE_BASENAME_POSIX.exec( './' )[ 1 ]
2026
'.'
21-
> base = {{alias}}.exec( '' )[ 1 ]
27+
> base = RE_BASENAME_POSIX.exec( '' )[ 1 ]
2228
''
2329

30+
31+
{{alias}}.REGEXP
32+
Regular expression to capture the last part of a POSIX path.
33+
34+
Examples
35+
--------
36+
> var base = {{alias}}.REGEXP.exec( 'foo/bar/index.js' )[ 1 ]
37+
'index.js'
38+
2439
See Also
2540
--------
2641

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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 capture the last part of a POSIX path.
23+
*/
24+
interface ReBasenamePosix {
25+
/**
26+
* Returns a regular expression to capture the last part of a POSIX path.
27+
*
28+
* @returns regular expression
29+
*
30+
* @example
31+
* var RE_BASENAME_POSIX = reBasenamePosix();
32+
* var base = RE_BASENAME_POSIX.exec( 'foo/bar/index.js' )[ 1 ];
33+
* // returns 'index.js'
34+
*/
35+
(): RegExp;
36+
37+
/**
38+
* Regular expression to capture the last part of a POSIX path.
39+
*
40+
* @example
41+
* var base = reBasenamePosix.REGEXP.exec( 'foo/bar/index.js' )[ 1 ]
42+
* // returns 'index.js'
43+
*/
44+
REGEXP: RegExp;
45+
}
46+
47+
/**
48+
* Returns a regular expression to capture the last part of a POSIX path.
49+
*
50+
* @returns regular expression
51+
*
52+
* @example
53+
* var RE_BASENAME_POSIX = reBasenamePosix();
54+
* var base = RE_BASENAME_POSIX.exec( 'foo/bar/index.js' )[ 1 ];
55+
* // returns 'index.js'
56+
*
57+
* @example
58+
* var base = reBasenamePosix.REGEXP.exec( 'foo/bar/index.js' )[ 1 ]
59+
* // returns 'index.js'
60+
*/
61+
declare var reBasenamePosix: ReBasenamePosix;
62+
63+
64+
// EXPORTS //
65+
66+
export = reBasenamePosix;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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 reBasenamePosix = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a regular expression...
25+
{
26+
reBasenamePosix(); // $ExpectType RegExp
27+
}
28+
29+
// The compiler throws an error if the function is provided any arguments...
30+
{
31+
reBasenamePosix( 2 ); // $ExpectError
32+
}
33+
34+
// Attached to main export is a `REGEXP` property that is a regular expression...
35+
{
36+
// tslint:disable-next-line:no-unused-expression
37+
reBasenamePosix.REGEXP; // $ExpectType RegExp
38+
}

lib/node_modules/@stdlib/regexp/basename-posix/examples/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
'use strict';
2020

21-
var RE_BASENAME_POSIX = require( './../lib' );
21+
var reBasenamePosix = require( './../lib' );
2222

23+
var RE_BASENAME_POSIX = reBasenamePosix();
2324
var base = RE_BASENAME_POSIX.exec( 'index.js' )[ 1 ];
2425
console.log( base );
2526
// => 'index.js'

0 commit comments

Comments
 (0)