Socket
Socket
Sign inDemoInstall

es6-symbol

Package Overview
Dependencies
8
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-symbol

ECMAScript 6 Symbol polyfill


Version published
Maintainers
1
Weekly downloads
9,508,356
increased by2.82%
Bundle size
2 kB
Minified + gzipped

Weekly downloads

Package description

What is es6-symbol?

The es6-symbol npm package provides a polyfill for the Symbol type introduced in ECMAScript 6. It offers a way to create unique identifiers that can be used as property keys in objects without the risk of name clashes. This is particularly useful for creating private or special properties that should not interfere with other properties in the object.

What are es6-symbol's main functionalities?

Creating symbols

This feature allows the creation of symbols, which can be used as unique identifiers. The code sample demonstrates how to create a symbol using the es6-symbol package.

var symbol = require('es6-symbol');
var mySymbol = symbol('mySymbol');

Using symbols as property keys

Symbols can be used as property keys in objects. This code sample shows how to assign and access a property in an object using a symbol as the key.

var symbol = require('es6-symbol');
var mySymbol = symbol('mySymbol');
var obj = {};
obj[mySymbol] = 'value';
console.log(obj[mySymbol]); // 'value'

Well-known symbols

The package provides access to well-known symbols defined by the ECMAScript specification, such as Symbol.iterator. This code sample demonstrates how to access a well-known symbol.

var symbol = require('es6-symbol');
var iteratorSymbol = symbol.iterator;
console.log(typeof iteratorSymbol); // 'symbol'

Other packages similar to es6-symbol

Readme

Source

Build status Tests coverage npm version

es6-symbol

ECMAScript 6 Symbol polyfill

For more information about symbols see following links

Limitations

Underneath it uses real string property names which can easily be retrieved, however accidental collision with other property names is unlikely.

Usage

If you'd like to use native version when it exists and fallback to ponyfill if it doesn't, use es6-symbol as following:

var Symbol = require("es6-symbol");

If you want to make sure your environment implements Symbol globally, do:

require("es6-symbol/implement");

If you strictly want to use polyfill even if native Symbol exists (hard to find a good reason for that), do:

var Symbol = require("es6-symbol/polyfill");
API

Best is to refer to specification. Still if you want quick look, follow examples:

var Symbol = require("es6-symbol");

var symbol = Symbol("My custom symbol");
var x = {};

x[symbol] = "foo";
console.log(x[symbol]);
("foo");

// Detect iterable:
var iterator, result;
if (possiblyIterable[Symbol.iterator]) {
  iterator = possiblyIterable[Symbol.iterator]();
  result = iterator.next();
  while (!result.done) {
    console.log(result.value);
    result = iterator.next();
  }
}

Installation

NPM

In your project path:

$ npm install es6-symbol
Browser

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Tests

$ npm test

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.


Get professional support for d with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 01 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc