Skip to content

Commit 189280f

Browse files
committed
Refactor as function
1 parent 8400dff commit 189280f

File tree

13 files changed

+404
-90
lines changed

13 files changed

+404
-90
lines changed

lib/node_modules/@stdlib/regexp/extended-length-path/README.md

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

2929
```javascript
30-
var RE_EXTENDED_LENGTH_PATH = require( '@stdlib/regexp/extended-length-path' );
30+
var reExtendedLengthPath = require( '@stdlib/regexp/extended-length-path' );
3131
```
3232

33-
#### RE_EXTENDED_LENGTH_PATH
33+
#### reExtendedLengthPath()
3434

35-
[Regular expression][regexp] to detect an [extended-length path][extended-length-path] (i.e., a Windows path which begins with the characters `\\?\`).
35+
Returns a [regular expression][regexp] to detect an [extended-length path][extended-length-path] (i.e., a Windows path which begins with the characters `\\?\`).
3636

3737
```javascript
38-
var bool = RE_EXTENDED_LENGTH_PATH.test( '\\\\?\\C:\\foo\\bar' );
38+
var RE = reExtendedLengthPath();
39+
var bool = RE.test( '\\\\?\\C:\\foo\\bar' );
3940
// returns true
4041
```
4142

@@ -50,8 +51,9 @@ var bool = RE_EXTENDED_LENGTH_PATH.test( '\\\\?\\C:\\foo\\bar' );
5051
<!-- eslint no-undef: "error" -->
5152

5253
```javascript
53-
var RE_EXTENDED_LENGTH_PATH = require( '@stdlib/regexp/extended-length-path' );
54+
var reExtendedLengthPath = require( '@stdlib/regexp/extended-length-path' );
5455

56+
var RE_EXTENDED_LENGTH_PATH = reExtendedLengthPath();
5557
var bool;
5658
var path;
5759

lib/node_modules/@stdlib/regexp/extended-length-path/benchmark/benchmark.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var bench = require( '@stdlib/bench' );
2424
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var fromCodePoint = require( '@stdlib/string/from-code-point' );
2626
var pkg = require( './../package.json' ).name;
27-
var RE_EXTENDED_LENGTH_PATH = require( './../lib' );
27+
var reExtendedLengthPath = require( './../lib' );
2828

2929

3030
// MAIN //
@@ -37,7 +37,7 @@ bench( pkg, function benchmark( b ) {
3737
b.tic();
3838
for ( i = 0; i < b.iterations; i++ ) {
3939
str = '\\\\?\\C:\\foo\\bar\\'+fromCodePoint( 97 + (i%26) )+'.js';
40-
bool = RE_EXTENDED_LENGTH_PATH.test( str );
40+
bool = reExtendedLengthPath.REGEXP.test( str );
4141
if ( !isBoolean( bool ) ) {
4242
b.fail( 'should return a boolean' );
4343
}

lib/node_modules/@stdlib/regexp/extended-length-path/docs/repl.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11

2-
{{alias}}
3-
Regular expression to test if a string is an extended-length path.
2+
{{alias}}()
3+
Returns a regular expression to test if a string is an extended-length path.
44

55
Extended-length paths are Windows paths which begin with `\\?\`.
66

77
Examples
88
--------
9+
> var RE = {{alias}}();
910
> var path = '\\\\?\\C:\\foo\\bar';
10-
> var bool = {{alias}}.test( path )
11+
> var bool = RE.test( path )
1112
true
1213
> path = '\\\\?\\UNC\\server\\share';
13-
> bool = {{alias}}.test( path )
14+
> bool = RE.test( path )
1415
true
1516
> path = 'C:\\foo\\bar';
16-
> bool = {{alias}}.test( path )
17+
> bool = RE.test( path )
1718
false
1819
> path = '/c/foo/bar';
19-
> bool = {{alias}}.test( path )
20+
> bool = RE.test( path )
2021
false
2122
> path = '/foo/bar';
22-
> bool = {{alias}}.test( path )
23+
> bool = RE.test( path )
2324
false
2425

2526
See Also
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 test if a string is an extended-length path.
23+
*/
24+
interface ReExtendedLengthPath {
25+
/**
26+
* Returns a regular expression to test if a string is an extended-length path.
27+
*
28+
* @returns regular expression
29+
*
30+
* @example
31+
* var RE_EXTENDED_LENGTH_PATH = reExtendedLengthPath();
32+
*
33+
* var bool = RE_EXTENDED_LENGTH_PATH.test( '\\\\?\\C:\\foo\\bar' );
34+
* // returns true
35+
*/
36+
(): RegExp;
37+
38+
/**
39+
* Regular expression to test if a string is an extended-length path.
40+
*
41+
* @example
42+
* var bool = reExtendedLengthPath.REGEXP.test( 'C:\\foo\\bar' );
43+
* // returns false
44+
*/
45+
REGEXP: RegExp;
46+
}
47+
48+
/**
49+
* Returns a regular expression to test if a string is an extended-length path.
50+
*
51+
* @returns regular expression
52+
*
53+
* @example
54+
* var RE_EXTENDED_LENGTH_PATH = reExtendedLengthPath();
55+
*
56+
* var bool = RE_EXTENDED_LENGTH_PATH.test( '\\\\?\\C:\\foo\\bar' );
57+
* // returns true
58+
*
59+
* @example
60+
* var bool = reExtendedLengthPath.REGEXP.test( 'C:\\foo\\bar' );
61+
* // returns false
62+
*/
63+
declare var reExtendedLengthPath: ReExtendedLengthPath;
64+
65+
66+
// EXPORTS //
67+
68+
export = reExtendedLengthPath;
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 reExtendedLengthPath = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a regular expression...
25+
{
26+
reExtendedLengthPath(); // $ExpectType RegExp
27+
}
28+
29+
// The compiler throws an error if the function is provided any arguments...
30+
{
31+
reExtendedLengthPath( 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+
reExtendedLengthPath.REGEXP; // $ExpectType RegExp
38+
}

lib/node_modules/@stdlib/regexp/extended-length-path/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_EXTENDED_LENGTH_PATH = require( './../lib' );
21+
var reExtendedLengthPath = require( './../lib' );
2222

23+
var RE_EXTENDED_LENGTH_PATH = reExtendedLengthPath();
2324
var bool;
2425
var path;
2526

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2021 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,13 +19,13 @@
1919
'use strict';
2020

2121
/**
22-
* Regular expression to test if a string is an extended-length path.
22+
* Return a regular expression to test if a string is an extended-length path.
2323
*
2424
* @module @stdlib/regexp/extended-length-path
25-
* @type {RegExp}
2625
*
2726
* @example
28-
* var RE_EXTENDED_LENGTH_PATH = require( '@stdlib/regexp/extended-length-path' );
27+
* var reExtendedLengthPath = require( '@stdlib/regexp/extended-length-path' );
28+
* var RE_EXTENDED_LENGTH_PATH = reExtendedLengthPath();
2929
*
3030
* var bool = RE_EXTENDED_LENGTH_PATH.test( '\\\\?\\C:\\foo\\bar' );
3131
* // returns true
@@ -34,28 +34,18 @@
3434
* // returns false
3535
*/
3636

37+
// MODULES //
38+
39+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
40+
var reExtendedLengthPath = require( './main.js' );
41+
var REGEXP = require( './regexp.js' );
42+
3743

3844
// MAIN //
3945

40-
/**
41-
* Matches an extended-length path.
42-
*
43-
* Regular Expression: `/^\\\\\?\\.+/`
44-
*
45-
* - `/^\\\\?\\`
46-
* - match a string that begins with two backward slashes `\\\\` followed by a `?` and then a backward slash `\\`
47-
*
48-
* - `.+`
49-
* - match any character which occurs one or more times
50-
*
51-
* @constant
52-
* @type {RegExp}
53-
* @default /^\\\\\?\\.+/
54-
* @see [MSDN]{@link https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx}
55-
*/
56-
var RE_EXTENDED_LENGTH_PATH = /^\\\\\?\\.+/;
46+
setReadOnly( reExtendedLengthPath, 'REGEXP', REGEXP );
5747

5848

5949
// EXPORTS //
6050

61-
module.exports = RE_EXTENDED_LENGTH_PATH;
51+
module.exports = reExtendedLengthPath;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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+
// MAIN //
22+
23+
/**
24+
* Returns a regular expression that matches an extended-length path.
25+
*
26+
* @returns {RegExp} regular expression
27+
*/
28+
function reExtendedLengthPath() {
29+
return /^\\\\\?\\.+/;
30+
}
31+
32+
33+
// EXPORTS //
34+
35+
module.exports = reExtendedLengthPath;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 reExtendedLengthPath = require( './main.js' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Matches an extended-length path.
30+
*
31+
* Regular Expression: `/^\\\\\?\\.+/`
32+
*
33+
* - `/^\\\\?\\`
34+
* - match a string that begins with two backward slashes `\\\\` followed by a `?` and then a backward slash `\\`
35+
*
36+
* - `.+`
37+
* - match any character which occurs one or more times
38+
*
39+
* @constant
40+
* @type {RegExp}
41+
* @default /^\\\\\?\\.+/
42+
* @see [MSDN]{@link https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx}
43+
*/
44+
var REGEXP = reExtendedLengthPath();
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = REGEXP;

lib/node_modules/@stdlib/regexp/extended-length-path/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/regexp/extended-length-path",
33
"version": "0.0.0",
4-
"description": "Regular expression to detected an extended-length path.",
4+
"description": "Regular expression to detect an extended-length path.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

0 commit comments

Comments
 (0)