Skip to content

Commit fda5e64

Browse files
committed
Add async iterator symbol
1 parent 5a721a5 commit fda5e64

File tree

7 files changed

+339
-0
lines changed

7 files changed

+339
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
# Async Iterator Symbol
22+
23+
> Async iterator [symbol][mdn-symbol] which specifies the default async iterator for an object.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var AsyncIteratorSymbol = require( '@stdlib/symbol/async-iterator' );
41+
```
42+
43+
#### AsyncIteratorSymbol
44+
45+
Async iterator [`symbol`][mdn-symbol] which specifies the default async iterator for an object.
46+
47+
```javascript
48+
var s = typeof AsyncIteratorSymbol;
49+
// e.g., returns 'symbol'
50+
```
51+
52+
</section>
53+
54+
<!-- /.usage -->
55+
56+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
57+
58+
<section class="notes">
59+
60+
## Notes
61+
62+
- The [symbol][mdn-symbol] is only supported in environments which support [symbols][mdn-symbol] and async iterators. In non-supporting environments, the value is `null`.
63+
64+
</section>
65+
66+
<!-- /.notes -->
67+
68+
<!-- Package usage examples. -->
69+
70+
<section class="examples">
71+
72+
## Examples
73+
74+
<!-- TODO: async iteration example -->
75+
76+
<!-- eslint no-undef: "error" -->
77+
78+
```javascript
79+
var AsyncIteratorSymbol = require( '@stdlib/symbol/async-iterator' );
80+
81+
console.log( AsyncIteratorSymbol );
82+
```
83+
84+
</section>
85+
86+
<!-- /.examples -->
87+
88+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
89+
90+
<section class="references">
91+
92+
</section>
93+
94+
<!-- /.references -->
95+
96+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
97+
98+
<section class="links">
99+
100+
[mdn-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
101+
102+
</section>
103+
104+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
{{alias}}
3+
Async iterator symbol.
4+
5+
This symbol specifies the default async iterator for an object.
6+
7+
The symbol is only supported in ES2018+ environments. For non-supporting
8+
environments, the value is `null`.
9+
10+
Examples
11+
--------
12+
> var s = {{alias}}
13+
14+
See Also
15+
--------
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 AsyncIteratorSymbol = require( './../lib' );
22+
23+
// TODO: async iterator symbol example!
24+
console.log( AsyncIteratorSymbol );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
* Async iterator symbol.
23+
*
24+
* @module @stdlib/symbol/async-iterator
25+
*
26+
* @example
27+
* var AsyncIteratorSymbol = require( '@stdlib/symbol/async-iterator' );
28+
*
29+
* // TODO: example
30+
*/
31+
32+
// MAIN //
33+
34+
var AsyncIteratorSymbol = require( './main.js' );
35+
36+
37+
// EXPORTS //
38+
39+
module.exports = AsyncIteratorSymbol;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 hasAsyncIteratorSymbolSupport = require( '@stdlib/assert/has-async-iterator-symbol-support' ); // eslint-disable-line id-length
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Async iterator symbol.
30+
*
31+
* @name AsyncIteratorSymbol
32+
* @constant
33+
* @type {(symbol|null)}
34+
*
35+
* @example
36+
* // TODO: example
37+
*/
38+
var AsyncIteratorSymbol = ( hasAsyncIteratorSymbolSupport() ) ? Symbol.asyncIterator : null; // eslint-disable-line max-len
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = AsyncIteratorSymbol;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "@stdlib/symbol/async-iterator",
3+
"version": "0.0.0",
4+
"description": "Async iterator symbol.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"benchmark": "./benchmark",
19+
"doc": "./docs",
20+
"example": "./examples",
21+
"lib": "./lib",
22+
"test": "./test"
23+
},
24+
"scripts": {},
25+
"homepage": "https://github.com/stdlib-js/stdlib",
26+
"repository": {
27+
"type": "git",
28+
"url": "git://github.com/stdlib-js/stdlib.git"
29+
},
30+
"bugs": {
31+
"url": "https://github.com/stdlib-js/stdlib/issues"
32+
},
33+
"dependencies": {},
34+
"devDependencies": {},
35+
"engines": {
36+
"node": ">=0.10.0",
37+
"npm": ">2.7.0"
38+
},
39+
"os": [
40+
"aix",
41+
"darwin",
42+
"freebsd",
43+
"linux",
44+
"macos",
45+
"openbsd",
46+
"sunos",
47+
"win32",
48+
"windows"
49+
],
50+
"keywords": [
51+
"stdlib",
52+
"symbol",
53+
"sym",
54+
"iterator",
55+
"iteration",
56+
"iterate",
57+
"for-of",
58+
"await",
59+
"async"
60+
]
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 tape = require( 'tape' );
24+
var hasAsyncIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); // eslint-disable-line id-length
25+
var isSymbol = require( '@stdlib/assert/is-symbol' );
26+
var Sym = require( './../lib' );
27+
28+
29+
// VARIABLES //
30+
31+
var opts = {
32+
'skip': !hasAsyncIteratorSymbolSupport()
33+
};
34+
35+
36+
// TESTS //
37+
38+
tape( 'main export is a symbol in supporting environments (ES2018+) or otherwise null', function test( t ) {
39+
t.ok( true, __filename );
40+
if ( opts.skip ) {
41+
t.strictEqual( Sym, null, 'main export is null' );
42+
} else {
43+
t.strictEqual( typeof Sym, 'symbol', 'main export is a symbol' );
44+
t.strictEqual( isSymbol( Sym ), true, 'main export is a symbol' );
45+
}
46+
t.end();
47+
});
48+
49+
tape( 'the main export is an alias for `Symbol.asyncIterator`', opts, function test( t ) {
50+
t.strictEqual( Sym, Symbol.asyncIterator, 'is an alias' );
51+
t.end();
52+
});

0 commit comments

Comments
 (0)