Skip to content

Commit cc2dbf2

Browse files
committed
Auto-generated commit
1 parent 84bb8db commit cc2dbf2

File tree

21 files changed

+1357
-1
lines changed

21 files changed

+1357
-1
lines changed

.github/workflows/test_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ jobs:
7272
env:
7373
webhook_url: ${{ secrets.STDLIB_COVERAGE_URL }}
7474
webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }}
75-
data: '${{ steps.extract-coverage.outputs.coverage }}'
75+
data: '{ "coverage": ${{ steps.extract-coverage.outputs.coverage }}, "run_id": "${{ github.run_id }}" }'
7676
if: ${{ false }}

is-empty-array-like-object/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 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+
# isEmptyArrayLikeObject
22+
23+
> Test if a value is an empty array-like object.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isEmptyArrayLikeObject = require( '@stdlib/assert/is-empty-array-like-object' );
31+
```
32+
33+
#### isEmptyArrayLikeObject( value )
34+
35+
Tests if a value is an empty [array-like][array-like] `object`.
36+
37+
<!-- eslint-disable object-curly-newline -->
38+
39+
```javascript
40+
var bool = isEmptyArrayLikeObject( [] );
41+
// returns true
42+
43+
bool = isEmptyArrayLikeObject( { 'length': 0 } );
44+
// returns true
45+
```
46+
47+
If provided a `string`, the function returns `false`.
48+
49+
```javascript
50+
var bool = isEmptyArrayLikeObject( '' );
51+
// returns false
52+
```
53+
54+
</section>
55+
56+
<!-- /.usage -->
57+
58+
<section class="examples">
59+
60+
## Examples
61+
62+
<!-- eslint-disable object-curly-newline, object-curly-spacing, no-empty-function, no-restricted-syntax -->
63+
64+
<!-- eslint no-undef: "error" -->
65+
66+
```javascript
67+
var Float64Array = require( '@stdlib/array/float64' );
68+
var isEmptyArrayLikeObject = require( '@stdlib/assert/is-empty-array-like-object' );
69+
70+
var bool = isEmptyArrayLikeObject( { 'length': 0 } );
71+
// returns true
72+
73+
bool = isEmptyArrayLikeObject( [] );
74+
// returns true
75+
76+
bool = isEmptyArrayLikeObject( new Float64Array( 0 ) );
77+
// returns true
78+
79+
bool = isEmptyArrayLikeObject( 'beep' );
80+
// returns false
81+
82+
bool = isEmptyArrayLikeObject( null );
83+
// returns false
84+
85+
bool = isEmptyArrayLikeObject( void 0 );
86+
// returns false
87+
88+
bool = isEmptyArrayLikeObject( 5 );
89+
// returns false
90+
91+
bool = isEmptyArrayLikeObject( true );
92+
// returns false
93+
94+
bool = isEmptyArrayLikeObject( {} );
95+
// returns false
96+
97+
bool = isEmptyArrayLikeObject( function noop() {} );
98+
// returns false
99+
```
100+
101+
</section>
102+
103+
<!-- /.examples -->
104+
105+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
106+
107+
<section class="related">
108+
109+
</section>
110+
111+
<!-- /.related -->
112+
113+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
114+
115+
<section class="links">
116+
117+
[array-like]: http://www.2ality.com/2013/05/quirk-array-like-objects.html
118+
119+
<!-- <related-links> -->
120+
121+
<!-- </related-links> -->
122+
123+
</section>
124+
125+
<!-- /.links -->
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 bench = require( '@stdlib/bench' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var isBoolean = require( './../../is-boolean' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var isEmptyArrayLikeObject = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg+'::array', function benchmark( b ) {
33+
var bool;
34+
var obj;
35+
var i;
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
obj = [ i, i+1 ];
40+
bool = isEmptyArrayLikeObject( obj );
41+
if ( typeof bool !== 'boolean' ) {
42+
b.fail( 'should return a boolean' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBoolean( bool ) ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});
52+
53+
bench( pkg+'::typed_array', function benchmark( b ) {
54+
var values;
55+
var bool;
56+
var obj;
57+
var N;
58+
var i;
59+
60+
values = [
61+
new Float64Array( [ 1.0, 2.0 ] ),
62+
new Float64Array( [] )
63+
];
64+
N = values.length;
65+
66+
b.tic();
67+
for ( i = 0; i < b.iterations; i++ ) {
68+
obj = values[ i%N ];
69+
bool = isEmptyArrayLikeObject( obj );
70+
if ( typeof bool !== 'boolean' ) {
71+
b.fail( 'should return a boolean' );
72+
}
73+
}
74+
b.toc();
75+
if ( !isBoolean( bool ) ) {
76+
b.fail( 'should return a boolean' );
77+
}
78+
b.pass( 'benchmark finished' );
79+
b.end();
80+
});
81+
82+
bench( pkg+'::array_like_object', function benchmark( b ) {
83+
var bool;
84+
var obj;
85+
var i;
86+
87+
b.tic();
88+
for ( i = 0; i < b.iterations; i++ ) {
89+
obj = {
90+
'length': 2,
91+
'0': i,
92+
'1': i + 1
93+
};
94+
bool = isEmptyArrayLikeObject( obj );
95+
if ( typeof bool !== 'boolean' ) {
96+
b.fail( 'should return a boolean' );
97+
}
98+
}
99+
b.toc();
100+
if ( !isBoolean( bool ) ) {
101+
b.fail( 'should return a boolean' );
102+
}
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
{{alias}}( value )
3+
Tests if a value is an empty array-like object.
4+
5+
If provided a string, the function returns `false`.
6+
7+
Parameters
8+
----------
9+
value: any
10+
Value to test.
11+
12+
Returns
13+
-------
14+
bool: boolean
15+
Boolean indicating whether a value is an empty array-like object.
16+
17+
Examples
18+
--------
19+
> var bool = {{alias}}( [] )
20+
true
21+
> bool = {{alias}}( { 'length': 0 } )
22+
true
23+
> bool = {{alias}}( '' )
24+
false
25+
26+
See Also
27+
--------
28+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
* Tests if a value is an empty array-like object.
23+
*
24+
* ## Notes
25+
*
26+
* - If provided a string, the function returns `false`.
27+
*
28+
* @param value - value to test
29+
* @returns boolean indicating if a value is an empty array-like object
30+
*
31+
* @example
32+
* var bool = isEmptyArrayLikeObject( [] );
33+
* // returns true
34+
*
35+
* @example
36+
* var bool = isEmptyArrayLikeObject( { 'length': 0 } );
37+
* // returns true
38+
*
39+
* @example
40+
* var bool = isEmptyArrayLikeObject( '' );
41+
* // returns false
42+
*/
43+
declare function isEmptyArrayLikeObject( value: any ): boolean;
44+
45+
46+
// EXPORTS //
47+
48+
export = isEmptyArrayLikeObject;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 isEmptyArrayLikeObject = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isEmptyArrayLikeObject( [] ); // $ExpectType boolean
27+
isEmptyArrayLikeObject( '' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isEmptyArrayLikeObject(); // $ExpectError
33+
isEmptyArrayLikeObject( [], 123 ); // $ExpectError
34+
}

0 commit comments

Comments
 (0)