Socket
Socket
Sign inDemoInstall

babel-plugin-transform-es2015-typeof-symbol

Package Overview
Dependencies
3
Maintainers
6
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-es2015-typeof-symbol

This transformer wraps all typeof expressions with a method that replicates native behaviour. (ie. returning “symbol” for symbols)


Version published
Weekly downloads
1.4M
increased by1.43%
Maintainers
6
Install size
2.23 MB
Created
Weekly downloads
 

Package description

What is babel-plugin-transform-es2015-typeof-symbol?

The babel-plugin-transform-es2015-typeof-symbol npm package is a plugin for Babel that ensures the behavior of the `typeof` operator is spec-compliant when used with symbols, a new primitive type introduced in ES2015 (ES6). It is part of the Babel's ES2015 preset and is used to transform code so that it can run in environments that do not natively support the new symbol type.

What are babel-plugin-transform-es2015-typeof-symbol's main functionalities?

Transform typeof usage with symbols

This code sample demonstrates how the plugin transforms the `typeof` operator when used with a symbol. The plugin adds a helper function to correctly return 'symbol' when the operand is a symbol.

"use strict";

var _typeof = function (obj) {
  return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
};

var sym = Symbol('foo');
console.log(_typeof(sym) === 'symbol'); // true

Other packages similar to babel-plugin-transform-es2015-typeof-symbol

Readme

Source

babel-plugin-transform-es2015-typeof-symbol

ES6 introduces a new native type called symbols. This transformer wraps all typeof expressions with a method that replicates native behaviour. (ie. returning "symbol" for symbols)

Example

In

typeof Symbol() === "symbol";

Out

var _typeof = function (obj) {
  return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
};

_typeof(Symbol()) === "symbol";

Installation

npm install --save-dev babel-plugin-transform-es2015-typeof-symbol

Usage

.babelrc

{
  "plugins": ["transform-es2015-typeof-symbol"]
}

Via CLI

babel --plugins transform-es2015-typeof-symbol script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-es2015-typeof-symbol"]
});

Keywords

FAQs

Last updated on 13 Feb 2017

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