Skip to content

Commit cf849e4

Browse files
committed
feat: add assert/has-is-concat-spreadable-symbol-support
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: passed - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent b893587 commit cf849e4

File tree

14 files changed

+768
-0
lines changed

14 files changed

+768
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# Concat Spreadable Symbol Support
22+
23+
> Detect native [`Symbol.isConcatSpreadable`][mdn-is-concat-spreadable-symbol] support.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
<!-- eslint-disable id-length -->
30+
31+
```javascript
32+
var hasIsConcatSpreadableSymbolSupport = require( '@stdlib/assert/has-is-concat-spreadable-symbol-support' );
33+
```
34+
35+
#### hasIsConcatSpreadableSymbolSupport()
36+
37+
Detects if a runtime environment supports [`Symbol.isConcatSpreadable`][mdn-is-concat-spreadable-symbol].
38+
39+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
var bool = hasIsConcatSpreadableSymbolSupport();
43+
// returns <boolean>
44+
```
45+
46+
</section>
47+
48+
<!-- /.usage -->
49+
50+
<section class="examples">
51+
52+
## Examples
53+
54+
<!-- eslint-disable id-length -->
55+
56+
<!-- eslint no-undef: "error" -->
57+
58+
```javascript
59+
var hasIsConcatSpreadableSymbolSupport = require( '@stdlib/assert/has-is-concat-spreadable-symbol-support' );
60+
61+
var bool = hasIsConcatSpreadableSymbolSupport();
62+
if ( bool ) {
63+
console.log( 'Environment has Symbol.isConcatSpreadable support.' );
64+
} else {
65+
console.log( 'Environment lacks Symbol.isConcatSpreadable support.' );
66+
}
67+
```
68+
69+
</section>
70+
71+
<!-- /.examples -->
72+
73+
* * *
74+
75+
<section class="cli">
76+
77+
## CLI
78+
79+
<section class="usage">
80+
81+
### Usage
82+
83+
```text
84+
Usage: has-is-concat-spreadable-symbol-support [options]
85+
86+
Options:
87+
88+
-h, --help Print this message.
89+
-V, --version Print the package version.
90+
```
91+
92+
</section>
93+
94+
<!-- /.usage -->
95+
96+
<section class="examples">
97+
98+
### Examples
99+
100+
```bash
101+
$ has-is-concat-spreadable-symbol-support
102+
<boolean>
103+
```
104+
105+
</section>
106+
107+
<!-- /.examples -->
108+
109+
</section>
110+
111+
<!-- /.cli -->
112+
113+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
114+
115+
<section class="related">
116+
117+
</section>
118+
119+
<!-- /.related -->
120+
121+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
122+
123+
<section class="links">
124+
125+
[mdn-is-concat-spreadable-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol.isConcatSpreadable
126+
127+
</section>
128+
129+
<!-- /.links -->
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) 2025 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var hasIsConcatSpreadableSymbolSupport = require( './../lib' ); // eslint-disable-line id-length
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var bool;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
// Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear.
38+
bool = hasIsConcatSpreadableSymbolSupport();
39+
if ( typeof bool !== 'boolean' ) {
40+
b.fail( 'should return a boolean' );
41+
}
42+
}
43+
b.toc();
44+
if ( !isBoolean( bool ) ) {
45+
b.fail( 'should return a boolean' );
46+
}
47+
b.pass( 'benchmark finished' );
48+
b.end();
49+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2025 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var resolve = require( 'path' ).resolve;
26+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
27+
var CLI = require( '@stdlib/cli/ctor' );
28+
var detect = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
/**
34+
* Main execution sequence.
35+
*
36+
* @private
37+
*/
38+
function main() {
39+
var flags;
40+
var cli;
41+
42+
// Create a command-line interface:
43+
cli = new CLI({
44+
'pkg': require( './../package.json' ),
45+
'options': require( './../etc/cli_opts.json' ),
46+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
47+
'encoding': 'utf8'
48+
})
49+
});
50+
51+
// Get any provided command-line options:
52+
flags = cli.flags();
53+
if ( flags.help || flags.version ) {
54+
return;
55+
}
56+
57+
console.log( detect() ); // eslint-disable-line no-console
58+
}
59+
60+
main();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
{{alias}}()
3+
Tests for native `Symbol.isConcatSpreadable` support.
4+
5+
Returns
6+
-------
7+
bool: boolean
8+
Boolean indicating if an environment has native
9+
`Symbol.isConcatSpreadable` support.
10+
11+
Examples
12+
--------
13+
> var bool = {{alias}}()
14+
<boolean>
15+
16+
See Also
17+
--------
18+
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) 2025 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: 4.1
20+
21+
/**
22+
* Tests for native `Symbol.isConcatSpreadable` support.
23+
*
24+
* @returns boolean indicating if an environment has `Symbol.isConcatSpreadable` support
25+
*
26+
* @example
27+
* var bool = hasIsConcatSpreadableSymbolSupport();
28+
* // returns <boolean>
29+
*/
30+
declare function hasIsConcatSpreadableSymbolSupport(): boolean;
31+
32+
33+
// EXPORTS //
34+
35+
export = hasIsConcatSpreadableSymbolSupport;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 hasIsConcatSpreadableSymbolSupport = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
hasIsConcatSpreadableSymbolSupport(); // $ExpectType boolean
27+
}
28+
29+
// The compiler throws an error if the function is provided arguments...
30+
{
31+
hasIsConcatSpreadableSymbolSupport( true ); // $ExpectError
32+
hasIsConcatSpreadableSymbolSupport( [], 123 ); // $ExpectError
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
Usage: has-is-concat-spreadable-symbol-support [options]
3+
4+
Options:
5+
6+
-h, --help Print this message.
7+
-V, --version Print the package version.
8+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"boolean": [
3+
"help",
4+
"version"
5+
],
6+
"alias": {
7+
"help": [
8+
"h"
9+
],
10+
"version": [
11+
"V"
12+
]
13+
}
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
var hasIsConcatSpreadableSymbolSupport = require( './../lib' ); // eslint-disable-line id-length
22+
23+
var bool = hasIsConcatSpreadableSymbolSupport();
24+
if ( bool ) {
25+
console.log( 'Environment has Symbol.isConcatSpreadable support.' );
26+
} else {
27+
console.log( 'Environment lacks Symbol.isConcatSpreadable support.' );
28+
}

0 commit comments

Comments
 (0)