@ohos-ports/stdlib-symbol 0.0.0-stage → 0.4.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +1 -0
  3. package/README.md +205 -2
  4. package/SECURITY.md +5 -0
  5. package/async-iterator/README.md +129 -0
  6. package/async-iterator/docs/repl.txt +16 -0
  7. package/async-iterator/docs/types/index.d.ts +31 -0
  8. package/async-iterator/docs/types/test.ts +29 -0
  9. package/async-iterator/lib/index.js +43 -0
  10. package/async-iterator/lib/main.js +48 -0
  11. package/async-iterator/package.json +61 -0
  12. package/ctor/README.md +143 -0
  13. package/ctor/docs/repl.txt +27 -0
  14. package/ctor/docs/types/index.d.ts +34 -0
  15. package/ctor/docs/types/test.ts +34 -0
  16. package/ctor/lib/index.js +40 -0
  17. package/ctor/lib/main.js +28 -0
  18. package/ctor/package.json +60 -0
  19. package/docs/types/index.d.ts +116 -0
  20. package/has-instance/README.md +143 -0
  21. package/has-instance/docs/repl.txt +18 -0
  22. package/has-instance/docs/types/index.d.ts +31 -0
  23. package/has-instance/docs/types/test.ts +29 -0
  24. package/has-instance/lib/index.js +49 -0
  25. package/has-instance/lib/main.js +54 -0
  26. package/has-instance/package.json +57 -0
  27. package/is-concat-spreadable/README.md +122 -0
  28. package/is-concat-spreadable/docs/repl.txt +18 -0
  29. package/is-concat-spreadable/docs/types/index.d.ts +31 -0
  30. package/is-concat-spreadable/docs/types/test.ts +29 -0
  31. package/is-concat-spreadable/lib/index.js +46 -0
  32. package/is-concat-spreadable/lib/main.js +50 -0
  33. package/is-concat-spreadable/package.json +58 -0
  34. package/iterator/README.md +164 -0
  35. package/iterator/docs/repl.txt +16 -0
  36. package/iterator/docs/types/index.d.ts +31 -0
  37. package/iterator/docs/types/test.ts +29 -0
  38. package/iterator/lib/index.js +75 -0
  39. package/iterator/lib/main.js +79 -0
  40. package/iterator/package.json +58 -0
  41. package/lib/index.js +105 -0
  42. package/package.json +58 -4
  43. package/replace/README.md +130 -0
  44. package/replace/docs/repl.txt +18 -0
  45. package/replace/docs/types/index.d.ts +31 -0
  46. package/replace/docs/types/test.ts +29 -0
  47. package/replace/lib/index.js +44 -0
  48. package/replace/lib/main.js +48 -0
  49. package/replace/package.json +58 -0
  50. package/to-primitive/README.md +158 -0
  51. package/to-primitive/docs/repl.txt +16 -0
  52. package/to-primitive/docs/types/index.d.ts +30 -0
  53. package/to-primitive/docs/types/test.ts +29 -0
  54. package/to-primitive/lib/index.js +57 -0
  55. package/to-primitive/lib/main.js +63 -0
  56. package/to-primitive/package.json +61 -0
@@ -0,0 +1,48 @@
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( '@ohos-ports/stdlib-assert/has-async-iterator-symbol-support' ); // eslint-disable-line id-length
24
+ var Symbol = require( './../../ctor' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Async iterator symbol.
31
+ *
32
+ * @name AsyncIteratorSymbol
33
+ * @constant
34
+ * @type {(symbol|null)}
35
+ *
36
+ * @example
37
+ * if ( AsyncIteratorSymbol === null ) {
38
+ * console.log( 'Environment does not support Symbol.asyncIterator.' );
39
+ * } else {
40
+ * console.log( 'Environment does support Symbol.asyncIterator.' );
41
+ * }
42
+ */
43
+ var AsyncIteratorSymbol = ( hasAsyncIteratorSymbolSupport() ) ? Symbol.asyncIterator : null; // eslint-disable-line max-len
44
+
45
+
46
+ // EXPORTS //
47
+
48
+ module.exports = AsyncIteratorSymbol;
@@ -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
+ "doc": "./docs",
19
+ "example": "./examples",
20
+ "lib": "./lib",
21
+ "test": "./test"
22
+ },
23
+ "types": "./docs/types",
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
+ }
package/ctor/README.md ADDED
@@ -0,0 +1,143 @@
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
+ # Symbol
22
+
23
+ > [Symbol][mdn-symbol] factory.
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 Symbol = require( '@stdlib/symbol/ctor' );
41
+ ```
42
+
43
+ #### Symbol( \[description] )
44
+
45
+ Returns a [`Symbol`][mdn-symbol] primitive.
46
+
47
+ <!-- run-disable -->
48
+
49
+ <!-- eslint-disable symbol-description -->
50
+
51
+ ```javascript
52
+ var s = Symbol();
53
+ // returns <symbol>
54
+ ```
55
+
56
+ To aid debugging, provide a [symbol][mdn-symbol] `description`.
57
+
58
+ <!-- run-disable -->
59
+
60
+ ```javascript
61
+ var s = Symbol( 'beep' );
62
+ // returns <symbol>
63
+ ```
64
+
65
+ </section>
66
+
67
+ <!-- /.usage -->
68
+
69
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
70
+
71
+ <section class="notes">
72
+
73
+ ## Notes
74
+
75
+ - Unlike conventional constructors, the function does **not** support the `new` keyword.
76
+ - The function is only supported in environments which support [symbols][mdn-symbol]. In non-supporting environments, the value is `undefined`.
77
+
78
+ </section>
79
+
80
+ <!-- /.notes -->
81
+
82
+ <!-- Package usage examples. -->
83
+
84
+ <section class="examples">
85
+
86
+ ## Examples
87
+
88
+ <!-- eslint no-undef: "error" -->
89
+
90
+ ```javascript
91
+ var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
92
+ var Symbol = require( '@stdlib/symbol/ctor' );
93
+
94
+ var s;
95
+
96
+ if ( hasSymbolSupport() ) {
97
+ s = Symbol( 'beep' );
98
+
99
+ // Print the value type:
100
+ console.log( typeof s );
101
+ // => 'symbol'
102
+
103
+ // Serialize the symbol as a string:
104
+ console.log( s.toString() );
105
+ // => 'Symbol(beep)'
106
+
107
+ // Test symbol equality:
108
+ console.log( s === Symbol( 'beep' ) );
109
+ // => false
110
+ } else {
111
+ console.log( 'Environment does not support symbols.' );
112
+ }
113
+ ```
114
+
115
+ </section>
116
+
117
+ <!-- /.examples -->
118
+
119
+ <!-- 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. -->
120
+
121
+ <section class="references">
122
+
123
+ </section>
124
+
125
+ <!-- /.references -->
126
+
127
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
128
+
129
+ <section class="related">
130
+
131
+ </section>
132
+
133
+ <!-- /.related -->
134
+
135
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
136
+
137
+ <section class="links">
138
+
139
+ [mdn-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
140
+
141
+ </section>
142
+
143
+ <!-- /.links -->
@@ -0,0 +1,27 @@
1
+
2
+ {{alias}}( [description] )
3
+ Returns a symbol.
4
+
5
+ Unlike conventional constructors, this function does **not** support the
6
+ `new` keyword.
7
+
8
+ This function is only supported in environments which support symbols.
9
+
10
+ Parameters
11
+ ----------
12
+ description: string (optional)
13
+ Symbol description which can be used for debugging but not to access the
14
+ symbol itself.
15
+
16
+ Returns
17
+ -------
18
+ out: symbol
19
+ Symbol.
20
+
21
+ Examples
22
+ --------
23
+ > var s = ( {{alias}} ) ? {{alias}}( 'beep' ) : null
24
+
25
+ See Also
26
+ --------
27
+
@@ -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
+ // TypeScript Version: 4.1
20
+
21
+ // EXPORTS //
22
+
23
+ /**
24
+ * Returns a symbol.
25
+ *
26
+ * ## Notes
27
+ *
28
+ * - Unlike conventional constructors, this function does **not** support the `new` keyword.
29
+ * - This function is only supported in environments which support symbols.
30
+ *
31
+ * @param description - symbol description which can be used for debugging but not to access the symbol itself
32
+ * @returns symbol
33
+ */
34
+ export = Symbol;
@@ -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
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
20
+
21
+ import Symbol = require( './index' );
22
+
23
+
24
+ // TESTS //
25
+
26
+ // The function returns a symbol...
27
+ {
28
+ Symbol( 'boop' ); // $ExpectType symbol
29
+ }
30
+
31
+ // The compiler throws an error if the function is provided an unsupported number of arguments...
32
+ {
33
+ Symbol( 'beep', 'boop' ); // $ExpectError
34
+ }
@@ -0,0 +1,40 @@
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
+ * Symbol factory.
23
+ *
24
+ * @module @stdlib/symbol/ctor
25
+ *
26
+ * @example
27
+ * var Symbol = require( '@stdlib/symbol/ctor' );
28
+ *
29
+ * var s = Symbol( 'beep' );
30
+ * // returns <symbol>
31
+ */
32
+
33
+ // MODULES //
34
+
35
+ var main = require( './main.js' );
36
+
37
+
38
+ // EXPORTS //
39
+
40
+ module.exports = main;
@@ -0,0 +1,28 @@
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
+ // MAIN //
22
+
23
+ var Sym = ( typeof Symbol === 'function' ) ? Symbol : void 0; // eslint-disable-line stdlib/require-globals
24
+
25
+
26
+ // EXPORTS //
27
+
28
+ module.exports = Sym;
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@stdlib/symbol/ctor",
3
+ "version": "0.0.0",
4
+ "description": "Symbols.",
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
+ "types": "./docs/types",
25
+ "scripts": {},
26
+ "homepage": "https://github.com/stdlib-js/stdlib",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git://github.com/stdlib-js/stdlib.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/stdlib-js/stdlib/issues"
33
+ },
34
+ "dependencies": {},
35
+ "devDependencies": {},
36
+ "engines": {
37
+ "node": ">=0.10.0",
38
+ "npm": ">2.7.0"
39
+ },
40
+ "os": [
41
+ "aix",
42
+ "darwin",
43
+ "freebsd",
44
+ "linux",
45
+ "macos",
46
+ "openbsd",
47
+ "sunos",
48
+ "win32",
49
+ "windows"
50
+ ],
51
+ "keywords": [
52
+ "stdlib",
53
+ "stdtypes",
54
+ "types",
55
+ "symbol",
56
+ "sym",
57
+ "unique",
58
+ "identifier"
59
+ ]
60
+ }
@@ -0,0 +1,116 @@
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: 4.1
20
+
21
+ /* eslint-disable max-lines */
22
+
23
+ import AsyncIteratorSymbol = require( './../../async-iterator' );
24
+ import Symbol = require( './../../ctor' );
25
+ import HasInstanceSymbol = require( './../../has-instance' );
26
+ import IsConcatSpreadableSymbol = require( './../../is-concat-spreadable' );
27
+ import IteratorSymbol = require( './../../iterator' );
28
+ import ReplaceSymbol = require( './../../replace' );
29
+ import ToPrimitiveSymbol = require( './../../to-primitive' );
30
+
31
+ /**
32
+ * Interface describing the `symbol` namespace.
33
+ */
34
+ interface Namespace {
35
+ /**
36
+ * Async iterator symbol.
37
+ *
38
+ * ## Notes
39
+ *
40
+ * - This symbol specifies the default async iterator for an object.
41
+ * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
42
+ */
43
+ AsyncIteratorSymbol: typeof AsyncIteratorSymbol;
44
+
45
+ /**
46
+ * Returns a symbol.
47
+ *
48
+ * ## Notes
49
+ *
50
+ * - Unlike conventional constructors, this function does **not** support the `new` keyword.
51
+ * - This function is only supported in environments which support symbols.
52
+ *
53
+ * @param description - symbol description which can be used for debugging but not to access the symbol itself
54
+ * @returns symbol
55
+ */
56
+ Symbol: typeof Symbol;
57
+
58
+ /**
59
+ * Has instance symbol.
60
+ *
61
+ * ## Notes
62
+ *
63
+ * - This symbol is used to determine whether a constructor object recognizes an object as its instance.
64
+ * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
65
+ */
66
+ HasInstanceSymbol: typeof HasInstanceSymbol;
67
+
68
+ /**
69
+ * Concat spreadable symbol.
70
+ *
71
+ * ## Notes
72
+ *
73
+ * - This symbol specifies whether an array-like object should be flattened to its array elements during concatenation.
74
+ * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
75
+ */
76
+ IsConcatSpreadableSymbol: typeof IsConcatSpreadableSymbol;
77
+
78
+ /**
79
+ * Iterator symbol.
80
+ *
81
+ * ## Notes
82
+ *
83
+ * - This symbol specifies the default iterator for an object.
84
+ * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
85
+ */
86
+ IteratorSymbol: typeof IteratorSymbol;
87
+
88
+ /**
89
+ * Replace symbol.
90
+ *
91
+ * ## Notes
92
+ *
93
+ * - This symbol provides a method for replacing substrings matched by the current object.
94
+ * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
95
+ */
96
+ ReplaceSymbol: typeof ReplaceSymbol;
97
+
98
+ /**
99
+ * Symbol which specifies a method for converting an object to a primitive value.
100
+ *
101
+ * ## Notes
102
+ *
103
+ * - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
104
+ */
105
+ ToPrimitiveSymbol: typeof ToPrimitiveSymbol;
106
+ }
107
+
108
+ /**
109
+ * Symbol.
110
+ */
111
+ declare var ns: Namespace;
112
+
113
+
114
+ // EXPORTS //
115
+
116
+ export = ns;