1 | # babel-plugin-transform-es2015-typeof-symbol
|
2 |
|
3 | > ES6 introduces a new native type called [symbols](https://babeljs.io/learn-es2015/#ecmascript-2015-features-symbols). This transformer wraps all `typeof` expressions with a method that replicates native behaviour. (ie. returning "symbol" for symbols)
|
4 |
|
5 | ## Example
|
6 |
|
7 | **In**
|
8 |
|
9 | ```javascript
|
10 | typeof Symbol() === "symbol";
|
11 | ```
|
12 |
|
13 | **Out**
|
14 |
|
15 | ```javascript
|
16 | var _typeof = function (obj) {
|
17 | return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
|
18 | };
|
19 |
|
20 | _typeof(Symbol()) === "symbol";
|
21 | ```
|
22 |
|
23 | ## Installation
|
24 |
|
25 | ```sh
|
26 | npm install --save-dev babel-plugin-transform-es2015-typeof-symbol
|
27 | ```
|
28 |
|
29 | ## Usage
|
30 |
|
31 | ### Via `.babelrc` (Recommended)
|
32 |
|
33 | **.babelrc**
|
34 |
|
35 | ```json
|
36 | {
|
37 | "plugins": ["transform-es2015-typeof-symbol"]
|
38 | }
|
39 | ```
|
40 |
|
41 | ### Via CLI
|
42 |
|
43 | ```sh
|
44 | babel --plugins transform-es2015-typeof-symbol script.js
|
45 | ```
|
46 |
|
47 | ### Via Node API
|
48 |
|
49 | ```javascript
|
50 | require("babel-core").transform("code", {
|
51 | plugins: ["transform-es2015-typeof-symbol"]
|
52 | });
|
53 | ```
|