Skip to content

Commit 201cb87

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents a1caddc + 7457a6a commit 201cb87

31 files changed

Lines changed: 1325 additions & 29 deletions

File tree

docs/links/database.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,17 @@
710710
"rate limit"
711711
]
712712
},
713+
"https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Generator": {
714+
"id": "mdn-generator-object",
715+
"description": "Mozilla Developer Network (MDN) documentation for ECMAScript 2015 generator objects.",
716+
"short_url": "",
717+
"keywords": [
718+
"generator",
719+
" object",
720+
" javascript",
721+
" ecmascript"
722+
]
723+
},
713724
"https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency": {
714725
"id": "hardware-concurrency",
715726
"description": "Mozilla Developer Network (MDN) documentation for the hardware concurrency API to retrieve the number of logical processors on the computer.",

lib/node_modules/@stdlib/assert/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ The remaining functions of the `assert` namespace are:
333333
- <span class="signature">[`isEven( value )`][@stdlib/assert/is-even]</span><span class="delimiter">: </span><span class="description">test if a value is an even number.</span>
334334
- <span class="signature">[`isFalsy( value )`][@stdlib/assert/is-falsy]</span><span class="delimiter">: </span><span class="description">test if a value is falsy.</span>
335335
- <span class="signature">[`isFinite( value )`][@stdlib/assert/is-finite]</span><span class="delimiter">: </span><span class="description">test if a value is a finite number.</span>
336+
- <span class="signature">[`isGeneratorObjectLike( value )`][@stdlib/assert/is-generator-object-like]</span><span class="delimiter">: </span><span class="description">test if a value is `generator` object-like.</span>
337+
- <span class="signature">[`isGeneratorObject( value )`][@stdlib/assert/is-generator-object]</span><span class="delimiter">: </span><span class="description">test if a value is a `generator` object.</span>
336338
- <span class="signature">[`isHexString( value )`][@stdlib/assert/is-hex-string]</span><span class="delimiter">: </span><span class="description">test whether a string contains only hexadecimal digits.</span>
337339
- <span class="signature">[`isInfinite( value )`][@stdlib/assert/is-infinite]</span><span class="delimiter">: </span><span class="description">test if a value is an infinite number.</span>
338340
- <span class="signature">[`isJSON( value )`][@stdlib/assert/is-json]</span><span class="delimiter">: </span><span class="description">test if a value is a parseable JSON string.</span>
@@ -454,6 +456,10 @@ console.log( getKeys( assert ) );
454456

455457
[@stdlib/assert/is-finite]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-finite
456458

459+
[@stdlib/assert/is-generator-object-like]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-generator-object-like
460+
461+
[@stdlib/assert/is-generator-object]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-generator-object
462+
457463
[@stdlib/assert/is-hex-string]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-hex-string
458464

459465
[@stdlib/assert/is-infinite]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-infinite
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# isGeneratorObjectLike
22+
23+
> Test if a value is [`generator`][mdn-generator-object] object-like.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isGeneratorObjectLike = require( '@stdlib/assert/is-generator-object-like' );
31+
```
32+
33+
#### isGeneratorObjectLike( value )
34+
35+
Tests if a `value` is [`generator`][mdn-generator-object] object-like.
36+
37+
<!-- eslint-disable no-restricted-syntax, no-plusplus -->
38+
39+
```javascript
40+
function* generateID() {
41+
var idx = 0;
42+
while ( idx < idx+1 ) {
43+
yield idx++;
44+
}
45+
}
46+
47+
var bool = isGeneratorObjectLike( generateID() );
48+
// returns true
49+
50+
bool = isGeneratorObjectLike( generateID );
51+
// returns false
52+
53+
bool = isGeneratorObjectLike( {} );
54+
// returns false
55+
```
56+
57+
</section>
58+
59+
<!-- /.usage -->
60+
61+
<section class="examples">
62+
63+
## Examples
64+
65+
<!-- eslint-disable no-restricted-syntax -->
66+
67+
<!-- eslint no-undef: "error" -->
68+
69+
```javascript
70+
var isGeneratorObjectLike = require( '@stdlib/assert/is-generator-object-like' );
71+
var noop = require( '@stdlib/utils/noop' );
72+
73+
function* generator() {
74+
while ( true ) {
75+
yield 1.0;
76+
}
77+
}
78+
79+
var bool = isGeneratorObjectLike( generator() );
80+
// returns true
81+
82+
var obj = {
83+
'next': noop,
84+
'return': noop,
85+
'throw': noop
86+
};
87+
bool = isGeneratorObjectLike( obj );
88+
// returns true
89+
90+
bool = isGeneratorObjectLike( {} );
91+
// returns false
92+
93+
bool = isGeneratorObjectLike( [] );
94+
// returns false
95+
96+
bool = isGeneratorObjectLike( null );
97+
// returns false
98+
```
99+
100+
</section>
101+
102+
<!-- /.examples -->
103+
104+
<section class="links">
105+
106+
[mdn-generator-object]: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Generator
107+
108+
</section>
109+
110+
<!-- /.links -->
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
/* eslint-disable no-empty-function */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var bench = require( '@stdlib/bench' );
26+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
27+
var hasGeneratorsSupport = require( '@stdlib/assert/has-generator-support' );
28+
var pkg = require( './../package.json' ).name;
29+
var isGeneratorObjectLike = require( './../lib' );
30+
31+
32+
// VARIABLES //
33+
34+
var generator;
35+
36+
37+
// FUNCTIONS //
38+
39+
function createGenerator() {
40+
var str = 'generator = function* generator() {';
41+
str += ' while ( true ) {';
42+
str += ' yield 1.0;';
43+
str += ' }';
44+
str += '}';
45+
eval( str ); // eslint-disable-line no-eval
46+
}
47+
48+
49+
// MAIN //
50+
51+
bench( pkg, function benchmark( b ) {
52+
var values;
53+
var bool;
54+
var i;
55+
56+
values = [
57+
'5',
58+
5,
59+
NaN,
60+
true,
61+
false,
62+
null,
63+
void 0,
64+
[],
65+
{},
66+
function noop() {},
67+
{
68+
'next': function noop() {},
69+
'return': function noop() {},
70+
'throw': function noop() {}
71+
}
72+
];
73+
74+
if ( hasGeneratorsSupport() ) {
75+
createGenerator();
76+
values.push( generator() );
77+
}
78+
79+
b.tic();
80+
for ( i = 0; i < b.iterations; i++ ) {
81+
bool = isGeneratorObjectLike( values[ i%values.length ] );
82+
if ( !isBoolean( bool ) ) {
83+
b.fail( 'should return a boolean' );
84+
}
85+
}
86+
b.toc();
87+
if ( !isBoolean( bool ) ) {
88+
b.fail( 'should return a boolean' );
89+
}
90+
b.pass( 'benchmark finished' );
91+
b.end();
92+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
{{alias}}( value )
3+
Tests if a value is generator object-like.
4+
5+
Parameters
6+
----------
7+
value: any
8+
Value to test.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating whether value is generator object-like
14+
15+
Examples
16+
--------
17+
> function* generateID() {
18+
... var idx = 0;
19+
... while ( idx < idx+1 ) {
20+
... yield idx++; // eslint-disable-line no-plusplus
21+
... }
22+
... }
23+
> var bool = {{alias}}( generateID() )
24+
true
25+
> var obj = {
26+
... 'next': function noop() {},
27+
... 'return': function noop() {},
28+
... 'throw': function noop() {}
29+
... };
30+
> bool = {{alias}}( obj )
31+
true
32+
> bool = {{alias}}( generateID )
33+
false
34+
> bool = {{alias}}( {} )
35+
false
36+
> bool = {{alias}}( null )
37+
false
38+
39+
See Also
40+
--------
41+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
var hasGeneratorsSupport = require( '@stdlib/assert/has-generator-support' );
22+
var noop = require( '@stdlib/utils/noop' );
23+
var isGeneratorObjectLike = require( './../lib' );
24+
25+
var generator;
26+
27+
function createGenerator() {
28+
var str = 'generator = function* generator() {';
29+
str += ' while ( true ) {';
30+
str += ' yield 1.0;';
31+
str += ' }';
32+
str += '}';
33+
eval( str ); // eslint-disable-line no-eval
34+
}
35+
36+
if ( hasGeneratorsSupport() ) {
37+
createGenerator();
38+
console.log( isGeneratorObjectLike( generator() ) );
39+
// => true
40+
}
41+
42+
var obj = {
43+
'next': noop,
44+
'return': noop,
45+
'throw': noop
46+
};
47+
console.log( isGeneratorObjectLike( obj ) );
48+
// => true
49+
50+
console.log( isGeneratorObjectLike( {} ) );
51+
// => false
52+
53+
console.log( isGeneratorObjectLike( [] ) );
54+
// => false
55+
56+
console.log( isGeneratorObjectLike( null ) );
57+
// => false
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
/**
22+
* Test if a value is generator object-like.
23+
*
24+
* @module @stdlib/assert/is-generator-object-like
25+
*
26+
* @example
27+
* var isGeneratorObjectLike = require( '@stdlib/assert/is-generator-object-like' );
28+
*
29+
* function* generateID() {
30+
* var idx = 0;
31+
* while ( idx < idx+1 ) {
32+
* yield idx++; // eslint-disable-line no-plusplus
33+
* }
34+
* }
35+
*
36+
* var bool = isGeneratorObjectLike( generateID() );
37+
* // returns true
38+
*
39+
* bool = isGeneratorObjectLike( generateID );
40+
* // returns false
41+
*
42+
* bool = isGeneratorObjectLike( {} );
43+
* // returns false
44+
*/
45+
46+
// MODULES //
47+
48+
var isGeneratorObject = require( './main.js' );
49+
50+
51+
// EXPORTS //
52+
53+
module.exports = isGeneratorObject;

0 commit comments

Comments
 (0)