UNPKG

3.14 kBMarkdownView Raw
1[![Build status][build-image]][build-url]
2[![Tests coverage][cov-image]][cov-url]
3[![npm version][npm-image]][npm-url]
4
5# es6-symbol
6
7## ECMAScript 6 Symbol polyfill
8
9For more information about symbols see following links
10
11- [Symbols in ECMAScript 6 by Axel Rauschmayer](http://www.2ality.com/2014/12/es6-symbols.html)
12- [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
13- [Specification](https://tc39.github.io/ecma262/#sec-symbol-objects)
14
15### Limitations
16
17Underneath it uses real string property names which can easily be retrieved, however accidental collision with other property names is unlikely.
18
19### Usage
20
21If you'd like to use native version when it exists and fallback to [ponyfill](https://ponyfill.com) if it doesn't, use _es6-symbol_ as following:
22
23```javascript
24var Symbol = require("es6-symbol");
25```
26
27If you want to make sure your environment implements `Symbol` globally, do:
28
29```javascript
30require("es6-symbol/implement");
31```
32
33If you strictly want to use polyfill even if native `Symbol` exists (hard to find a good reason for that), do:
34
35```javascript
36var Symbol = require("es6-symbol/polyfill");
37```
38
39#### API
40
41Best is to refer to [specification](https://tc39.github.io/ecma262/#sec-symbol-objects). Still if you want quick look, follow examples:
42
43```javascript
44var Symbol = require("es6-symbol");
45
46var symbol = Symbol("My custom symbol");
47var x = {};
48
49x[symbol] = "foo";
50console.log(x[symbol]);
51("foo");
52
53// Detect iterable:
54var iterator, result;
55if (possiblyIterable[Symbol.iterator]) {
56 iterator = possiblyIterable[Symbol.iterator]();
57 result = iterator.next();
58 while (!result.done) {
59 console.log(result.value);
60 result = iterator.next();
61 }
62}
63```
64
65### Installation
66
67#### NPM
68
69In your project path:
70
71 $ npm install es6-symbol
72
73##### Browser
74
75To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
76
77## Tests
78
79 $ npm test
80
81## Security contact information
82
83To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
84
85---
86
87<div align="center">
88 <b>
89 <a href="https://tidelift.com/subscription/pkg/npm-es6-symbol?utm_source=npm-es6-symbol&utm_medium=referral&utm_campaign=readme">Get professional support for d with a Tidelift subscription</a>
90 </b>
91 <br>
92 <sub>
93 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
94 </sub>
95</div>
96
97[build-image]: https://github.com/medikoo/es6-symbol/workflows/Integrate/badge.svg
98[build-url]: https://github.com/medikoo/es6-symbol/actions?query=workflow%3AIntegrate
99[cov-image]: https://img.shields.io/codecov/c/github/medikoo/es6-symbol.svg
100[cov-url]: https://codecov.io/gh/medikoo/es6-symbol
101[npm-image]: https://img.shields.io/npm/v/es6-symbol.svg
102[npm-url]: https://www.npmjs.com/package/es6-symbol