Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
babel-plugin-transform-es2015-typeof-symbol
Advanced tools
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.
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
This is the updated version of the babel-plugin-transform-es2015-typeof-symbol package, which is now scoped under the @babel namespace. It provides the same functionality but is maintained as part of the modern Babel 7 ecosystem.
This package is a Babel preset that includes babel-plugin-transform-es2015-typeof-symbol among other plugins to transform ES2015 code to be ES5 compliant. It is a more comprehensive solution that includes various transformations for ES2015 features.
$ npm install babel-plugin-transform-es2015-typeof-symbol
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-es2015-typeof-symbol"]
}
$ babel --plugins transform-es2015-typeof-symbol script.js
require("babel-core").transform("code", {
plugins: ["transform-es2015-typeof-symbol"]
});
FAQs
This transformer wraps all typeof expressions with a method that replicates native behaviour. (ie. returning “symbol” for symbols)
The npm package babel-plugin-transform-es2015-typeof-symbol receives a total of 1,409,226 weekly downloads. As such, babel-plugin-transform-es2015-typeof-symbol popularity was classified as popular.
We found that babel-plugin-transform-es2015-typeof-symbol demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.