0.1.0 • Published 7 years ago

babel-plugin-transform-constant-string v0.1.0

Weekly downloads
9
License
-
Repository
github
Last release
7 years ago

babel-plugin-transform-constant-string

transform constant string variable

Example

In

constant(HELLO_WORLD)

function foo() {
  const bar = 'foo-bar'
  constant(THIS_IS_A_CONSTANT_STRING_VALUE)
  console.log('other code...');
  constant(
    A_FOO,
    B_BAR,
    C_FOO_BAR
  )
  return bar
}

Out

"use strict";
export const HELLO_WORLD = 'HELLO_WORLD';

function foo() {
  const bar = 'foo-bar';
  const THIS_IS_A_CONSTANT_STRING_VALUE = 'THIS_IS_A_CONSTANT_STRING_VALUE';
  console.log('other code...');
  const A_FOO = 'A_FOO';
  const B_BAR = 'B_BAR';
  const C_FOO_BAR = 'C_FOO_BAR';
  return bar;
}
// output code

Installation

$ npm install babel-plugin-transform-constant-string

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["transform-constant-string", {
    "callName": "CONST" // string, which callee to be transformed, default is "CONST",
    "exportCallName": "CONSPORT" // string, which will add `export` for the variable, default is "CONSPORT"
  }]
}

Via CLI

$ babel --plugins transform-constant-string script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-constant-string"]
});

license

MIT