Skip to content

Commit e2f2623

Browse files
committed
Expose symbol namespace
1 parent 43b9037 commit e2f2623

File tree

7 files changed

+308
-8
lines changed

7 files changed

+308
-8
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
# Symbol
22+
23+
> Symbol namespace.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var ns = require( '@stdlib/symbol' );
31+
```
32+
33+
#### ns
34+
35+
Symbol namespace.
36+
37+
```javascript
38+
var o = ns;
39+
// returns {...}
40+
```
41+
42+
The namespace contains the following:
43+
44+
<!-- <toc pattern="*"> -->
45+
46+
<div class="namespace-toc">
47+
48+
- <span class="signature">[`AsyncIteratorSymbol`][@stdlib/symbol/async-iterator]</span><span class="delimiter">: </span><span class="description">async iterator symbol which specifies the default async iterator for an object.</span>
49+
- <span class="signature">[`Symbol( [description] )`][@stdlib/symbol/ctor]</span><span class="delimiter">: </span><span class="description">symbol factory.</span>
50+
- <span class="signature">[`IteratorSymbol`][@stdlib/symbol/iterator]</span><span class="delimiter">: </span><span class="description">iterator symbol which specifies the default iterator for an object.</span>
51+
52+
</div>
53+
54+
<!-- </toc> -->
55+
56+
</section>
57+
58+
<!-- /.usage -->
59+
60+
<section class="examples">
61+
62+
## Examples
63+
64+
<!-- TODO: better examples -->
65+
66+
<!-- eslint no-undef: "error" -->
67+
68+
```javascript
69+
var objectKeys = require( '@stdlib/utils/keys' );
70+
var ns = require( '@stdlib/symbol' );
71+
72+
console.log( objectKeys( ns ) );
73+
```
74+
75+
</section>
76+
77+
<!-- /.examples -->
78+
79+
<section class="links">
80+
81+
<!-- <toc-links> -->
82+
83+
[@stdlib/symbol/async-iterator]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/symbol/async-iterator
84+
85+
[@stdlib/symbol/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/symbol/ctor
86+
87+
[@stdlib/symbol/iterator]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/symbol/iterator
88+
89+
<!-- </toc-links> -->
90+
91+
</section>
92+
93+
<!-- /.links -->
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
/* tslint:disable:max-line-length */
22+
/* tslint:disable:max-file-line-count */
23+
24+
import AsyncIteratorSymbol = require( '@stdlib/symbol/async-iterator' );
25+
import Symbol = require( '@stdlib/symbol/ctor' );
26+
import IteratorSymbol = require( '@stdlib/symbol/iterator' );
27+
28+
/**
29+
* Interface describing the `symbol` namespace.
30+
*/
31+
interface Namespace {
32+
/**
33+
* Async iterator symbol.
34+
*
35+
* ## Notes
36+
*
37+
* - This symbol specifies the default async iterator for an object.
38+
* - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
39+
*/
40+
AsyncIteratorSymbol: typeof AsyncIteratorSymbol;
41+
42+
/**
43+
* Returns a symbol.
44+
*
45+
* ## Notes
46+
*
47+
* - Unlike conventional constructors, this function does **not** support the `new` keyword.
48+
* - This function is only supported in environments which support symbols.
49+
*
50+
* @param description - symbol description which can be used for debugging but not to access the symbol itself
51+
* @returns symbol
52+
*/
53+
Symbol: typeof Symbol;
54+
55+
/**
56+
* Iterator symbol.
57+
*
58+
* ## Notes
59+
*
60+
* - This symbol specifies the default iterator for an object.
61+
* - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
62+
*/
63+
IteratorSymbol: typeof IteratorSymbol;
64+
}
65+
66+
/**
67+
* Symbol.
68+
*/
69+
declare var ns: Namespace;
70+
71+
72+
// EXPORTS //
73+
74+
export = ns;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
/* tslint:disable:no-unused-expression */
20+
21+
import symbol = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The exported value is the expected interface...
27+
{
28+
symbol; // $ExpectType Namespace
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
var objectKeys = require( '@stdlib/utils/keys' );
22+
var ns = require( './../lib' );
23+
24+
console.log( objectKeys( ns ) );

lib/node_modules/@stdlib/symbol/lib/index.js

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2019 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.
@@ -18,15 +18,52 @@
1818

1919
'use strict';
2020

21+
/*
22+
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
23+
*/
24+
25+
// MODULES //
26+
27+
var setReadOnly = require( '@stdlib/utils/define-read-only-property' );
28+
29+
30+
// MAIN //
31+
2132
/**
22-
* Symbol.
23-
*
24-
* @module @stdlib/symbol
33+
* Top-level namespace.
2534
*
26-
* @example
27-
* var sym = require( '@stdlib/symbol' );
35+
* @namespace ns
2836
*/
37+
var ns = {};
38+
39+
/**
40+
* @name AsyncIteratorSymbol
41+
* @memberof ns
42+
* @readonly
43+
* @type {Function}
44+
* @see {@link module:@stdlib/symbol/async-iterator}
45+
*/
46+
setReadOnly( ns, 'AsyncIteratorSymbol', require( '@stdlib/symbol/async-iterator' ) );
47+
48+
/**
49+
* @name Symbol
50+
* @memberof ns
51+
* @readonly
52+
* @type {Function}
53+
* @see {@link module:@stdlib/symbol/ctor}
54+
*/
55+
setReadOnly( ns, 'Symbol', require( '@stdlib/symbol/ctor' ) );
56+
57+
/**
58+
* @name IteratorSymbol
59+
* @memberof ns
60+
* @readonly
61+
* @type {Function}
62+
* @see {@link module:@stdlib/symbol/iterator}
63+
*/
64+
setReadOnly( ns, 'IteratorSymbol', require( '@stdlib/symbol/iterator' ) );
65+
2966

3067
// EXPORTS //
3168

32-
module.exports = null; // FIXME
69+
module.exports = ns;

lib/node_modules/@stdlib/symbol/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
],
1616
"main": "./lib",
1717
"directories": {
18-
"lib": "./lib"
18+
"example": "./examples",
19+
"lib": "./lib",
20+
"test": "./test"
1921
},
22+
"types": "./docs/types",
2023
"scripts": {},
2124
"homepage": "https://github.com/stdlib-js/stdlib",
2225
"repository": {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 tape = require( 'tape' );
24+
var objectKeys = require( '@stdlib/utils/keys' );
25+
var ns = require( './../lib' );
26+
27+
28+
// TESTS //
29+
30+
tape( 'main export is an object', function test( t ) {
31+
t.ok( true, __filename );
32+
t.equal( typeof ns, 'object', 'main export is an object' );
33+
t.end();
34+
});
35+
36+
tape( 'the exported object contains key-value pairs', function test( t ) {
37+
var keys = objectKeys( ns );
38+
t.equal( keys.length > 0, true, 'has keys' );
39+
t.end();
40+
});

0 commit comments

Comments
 (0)