You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. [![Build status][nix-build-image]][nix-build-url]
  2. [![Windows status][win-build-image]][win-build-url]
  3. ![Transpilation status][transpilation-image]
  4. [![npm version][npm-image]][npm-url]
  5. # es6-symbol
  6. ## ECMAScript 6 Symbol polyfill
  7. For more information about symbols see following links
  8. - [Symbols in ECMAScript 6 by Axel Rauschmayer](http://www.2ality.com/2014/12/es6-symbols.html)
  9. - [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
  10. - [Specification](https://tc39.github.io/ecma262/#sec-symbol-objects)
  11. ### Limitations
  12. Underneath it uses real string property names which can easily be retrieved, however accidental collision with other property names is unlikely.
  13. ### Usage
  14. If 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:
  15. ```javascript
  16. var Symbol = require("es6-symbol");
  17. ```
  18. If you want to make sure your environment implements `Symbol` globally, do:
  19. ```javascript
  20. require("es6-symbol/implement");
  21. ```
  22. If you strictly want to use polyfill even if native `Symbol` exists (hard to find a good reason for that), do:
  23. ```javascript
  24. var Symbol = require("es6-symbol/polyfill");
  25. ```
  26. #### API
  27. Best is to refer to [specification](https://tc39.github.io/ecma262/#sec-symbol-objects). Still if you want quick look, follow examples:
  28. ```javascript
  29. var Symbol = require("es6-symbol");
  30. var symbol = Symbol("My custom symbol");
  31. var x = {};
  32. x[symbol] = "foo";
  33. console.log(x[symbol]);
  34. ("foo");
  35. // Detect iterable:
  36. var iterator, result;
  37. if (possiblyIterable[Symbol.iterator]) {
  38. iterator = possiblyIterable[Symbol.iterator]();
  39. result = iterator.next();
  40. while (!result.done) {
  41. console.log(result.value);
  42. result = iterator.next();
  43. }
  44. }
  45. ```
  46. ### Installation
  47. #### NPM
  48. In your project path:
  49. $ npm install es6-symbol
  50. ##### Browser
  51. To 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/)
  52. ## Tests
  53. $ npm test
  54. ## Security contact information
  55. To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
  56. ---
  57. <div align="center">
  58. <b>
  59. <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>
  60. </b>
  61. <br>
  62. <sub>
  63. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  64. </sub>
  65. </div>
  66. [nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/es6-symbol/branches/master/shields_badge.svg
  67. [nix-build-url]: https://semaphoreci.com/medikoo-org/es6-symbol
  68. [win-build-image]: https://ci.appveyor.com/api/projects/status/1s743lt3el278anj?svg=true
  69. [win-build-url]: https://ci.appveyor.com/project/medikoo/es6-symbol
  70. [transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
  71. [npm-image]: https://img.shields.io/npm/v/es6-symbol.svg
  72. [npm-url]: https://www.npmjs.com/package/es6-symbol