Skip to content

Commit 89c1936

Browse files
committed
Refactor as function
1 parent dc4419d commit 89c1936

File tree

13 files changed

+424
-78
lines changed

13 files changed

+424
-78
lines changed

lib/node_modules/@stdlib/regexp/utf16-surrogate-pair/README.md

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

2929
```javascript
30-
var RE_UTF16_SURROGATE_PAIR = require( '@stdlib/regexp/utf16-surrogate-pair' );
30+
var reUtf16SurrogatePair = require( '@stdlib/regexp/utf16-surrogate-pair' );
3131
```
3232

33-
#### RE_UTF16_SURROGATE_PAIR
33+
#### reUtf16SurrogatePair()
3434

35-
[Regular expression][mdn-regexp] to match a [UTF-16][utf-16] surrogate pair.
35+
Returns a [regular expression][mdn-regexp] to match a [UTF-16][utf-16] surrogate pair.
3636

3737
```javascript
38+
var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
39+
3840
var bool = RE_UTF16_SURROGATE_PAIR.test( 'abc\uD800\uDC00def' );
3941
// returns true
4042
```
4143

44+
#### reUtf16SurrogatePair.REGEXP
45+
46+
[Regular expression][mdn-regexp] to match a [UTF-16][utf-16] surrogate pair.
47+
48+
```javascript
49+
var bool = reUtf16SurrogatePair.REGEXP.test( 'abc\uD800\uDC00def' );
50+
// returns true
51+
```
52+
4253
</section>
4354

4455
<!-- /.usage -->
@@ -50,7 +61,9 @@ var bool = RE_UTF16_SURROGATE_PAIR.test( 'abc\uD800\uDC00def' );
5061
<!-- eslint no-undef: "error" -->
5162

5263
```javascript
53-
var RE_UTF16_SURROGATE_PAIR = require( '@stdlib/regexp/utf16-surrogate-pair' );
64+
var reUtf16SurrogatePair = require( '@stdlib/regexp/utf16-surrogate-pair' );
65+
66+
var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
5467

5568
var bool = RE_UTF16_SURROGATE_PAIR.test( '\uD800\uDC00' );
5669
// returns true

lib/node_modules/@stdlib/regexp/utf16-surrogate-pair/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_UTF16_SURROGATE_PAIR = require( './../lib' );
27+
var reUtf16SurrogatePair = 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 = 'beep boop\r\n'+fromCodePoint( 97 + (i%26) )+'\r\nfoo bar';
40-
bool = RE_UTF16_SURROGATE_PAIR.test( str );
40+
bool = reUtf16SurrogatePair.REGEXP.test( str );
4141
if ( !isBoolean( bool ) ) {
4242
b.fail( 'should return a boolean' );
4343
}

lib/node_modules/@stdlib/regexp/utf16-surrogate-pair/docs/repl.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
21
{{alias}}
2+
Returns a regular expression to match a UTF-16 surrogate pair.
3+
4+
Examples
5+
--------
6+
> var RE = {{alias}}();
7+
> var bool = RE.test( 'abc\uD800\uDC00def' )
8+
true
9+
> bool = RE.test( 'abcdef' )
10+
false
11+
12+
13+
{{alias}}.REGEXP
314
Regular expression to match a UTF-16 surrogate pair.
415

516
Examples
617
--------
7-
> var bool = {{alias}}.test( 'abc\uD800\uDC00def' )
18+
> var RE = {{alias}}.REGEXP;
19+
> var bool = RE.test( 'abc\uD800\uDC00def' )
820
true
9-
> bool = {{alias}}.test( 'abcdef' )
21+
> bool = RE.test( 'abcdef' )
1022
false
1123

1224
See Also
1325
--------
14-
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 match a UTF-16 surrogate pair.
23+
*/
24+
interface ReUtf16SurrogatePair {
25+
/**
26+
* Returns a regular expression to match a UTF-16 surrogate pair.
27+
*
28+
* @returns regular expression
29+
*
30+
* @example
31+
* var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
32+
*
33+
* var bool = RE_UTF16_SURROGATE_PAIR.test( '\uD800\uDC00' );
34+
* // returns true
35+
*
36+
* bool = RE_UTF16_SURROGATE_PAIR.test( 'abc\uD800\uDC00def' );
37+
* // returns true
38+
*
39+
* bool = RE_UTF16_SURROGATE_PAIR.test( 'abc' );
40+
* // returns false
41+
*/
42+
(): RegExp;
43+
44+
/**
45+
* Regular expression to match a UTF-16 surrogate pair.
46+
*
47+
* @example
48+
* var bool = reUtf16SurrogatePair.REGEXP.test( 'abc' );
49+
* // returns false
50+
*/
51+
REGEXP: RegExp;
52+
}
53+
54+
/**
55+
* Returns a regular expression to match a UTF-16 surrogate pair.
56+
*
57+
* @returns regular expression
58+
*
59+
* @example
60+
* var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
61+
*
62+
* var bool = RE_UTF16_SURROGATE_PAIR.test( '\uD800\uDC00' );
63+
* // returns true
64+
*
65+
* bool = RE_UTF16_SURROGATE_PAIR.test( 'abc\uD800\uDC00def' );
66+
* // returns true
67+
*
68+
* bool = RE_UTF16_SURROGATE_PAIR.test( 'abc' );
69+
* // returns false
70+
*/
71+
declare var reUtf16SurrogatePair: ReUtf16SurrogatePair;
72+
73+
74+
// EXPORTS //
75+
76+
export = reUtf16SurrogatePair;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 reUtf16SurrogatePair = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a regular expression...
25+
{
26+
reUtf16SurrogatePair(); // $ExpectType RegExp
27+
}
28+
29+
// The compiler throws an error if the function is provided an unsupported number of arguments...
30+
{
31+
reUtf16SurrogatePair( 1 ); // $ExpectError
32+
reUtf16SurrogatePair( 1, 2 ); // $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+
reUtf16SurrogatePair.REGEXP; // $ExpectType RegExp
39+
}

lib/node_modules/@stdlib/regexp/utf16-surrogate-pair/examples/index.js

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

1919
'use strict';
2020

21-
var RE_UTF16_SURROGATE_PAIR = require( './../lib' );
21+
var reUtf16SurrogatePair = require( './../lib' );
22+
23+
var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
2224

2325
console.log( RE_UTF16_SURROGATE_PAIR.test( '\uD800\uDC00' ) );
2426
// => true
Lines changed: 13 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,14 @@
1919
'use strict';
2020

2121
/**
22-
* Regular expression to match a UTF-16 surrogate pair.
22+
* Return a regular expression to match a UTF-16 surrogate pair.
2323
*
2424
* @module @stdlib/regexp/utf16-surrogate-pair
25-
* @type {RegExp}
2625
*
2726
* @example
28-
* var RE_UTF16_SURROGATE_PAIR = require( '@stdlib/regexp/utf16-surrogate-pair' );
27+
* var reUtf16SurrogatePair = require( '@stdlib/regexp/utf16-surrogate-pair' );
28+
*
29+
* var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
2930
*
3031
* var bool = RE_UTF16_SURROGATE_PAIR.test( '\uD800\uDC00' );
3132
* // returns true
@@ -37,28 +38,18 @@
3738
* // returns false
3839
*/
3940

41+
// MODULES //
42+
43+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
44+
var reUtf16SurrogatePair = require( './main.js' );
45+
var REGEXP = require( './regexp.js' );
46+
4047

4148
// MAIN //
4249

43-
/**
44-
* Matches a UTF-16 surrogate pair.
45-
*
46-
* Regular expression: `/[\uD800-\uDBFF][\uDC00-\uDFFF]/`
47-
*
48-
* - `[\uD800-\uDBFF]`
49-
* - match a high surrogate
50-
*
51-
* - `[\uDC00-\uDFFF]`
52-
* - match a low surrogate
53-
*
54-
*
55-
* @constant
56-
* @type {RegExp}
57-
* @default /[\uD800-\uDBFF][\uDC00-\uDFFF]/
58-
*/
59-
var RE_UTF16_SURROGATE_PAIR = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
50+
setReadOnly( reUtf16SurrogatePair, 'REGEXP', REGEXP );
6051

6152

6253
// EXPORTS //
6354

64-
module.exports = RE_UTF16_SURROGATE_PAIR;
55+
module.exports = reUtf16SurrogatePair;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Returns a regular expression to match a UTF-16 surrogate pair.
25+
*
26+
* @returns {RegExp} regular expression
27+
*
28+
* @example
29+
* var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
30+
*
31+
* var bool = RE_UTF16_SURROGATE_PAIR.test( '\uD800\uDC00' );
32+
* // returns true
33+
*
34+
* bool = RE_UTF16_SURROGATE_PAIR.test( 'abc\uD800\uDC00def' );
35+
* // returns true
36+
*
37+
* bool = RE_UTF16_SURROGATE_PAIR.test( 'abc' );
38+
* // returns false
39+
*/
40+
function reUtf16SurrogatePair() {
41+
return /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
42+
}
43+
44+
45+
// EXPORTS //
46+
47+
module.exports = reUtf16SurrogatePair;
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) 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+
'use strict';
20+
21+
// MODULES //
22+
23+
var reUtf16SurrogatePair = require( './main.js' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Matches a UTF-16 surrogate pair.
30+
*
31+
* Regular expression: `/[\uD800-\uDBFF][\uDC00-\uDFFF]/`
32+
*
33+
* - `[\uD800-\uDBFF]`
34+
* - match a high surrogate
35+
*
36+
* - `[\uDC00-\uDFFF]`
37+
* - match a low surrogate
38+
*
39+
*
40+
* @constant
41+
* @type {RegExp}
42+
* @default /[\uD800-\uDBFF][\uDC00-\uDFFF]/
43+
*/
44+
var RE_UTF16_SURROGATE_PAIR = reUtf16SurrogatePair();
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = RE_UTF16_SURROGATE_PAIR;

lib/node_modules/@stdlib/regexp/utf16-surrogate-pair/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/utf16-surrogate-pair",
33
"version": "0.0.0",
4-
"description": "Regular expression to match a UTF-16 surrogate pair.",
4+
"description": "Return a regular expression to match a UTF-16 surrogate pair.",
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)