npm.io
1.0.2 • Published 9 years ago

babel-plugin-transform-string-literal-replace

Licence
ISC
Version
1.0.2
Deps
0
Vulns
0
Weekly
0

string-literal-replace

A simple Babel plugin to transform source code by finding and replacing string literals with other values.

Use Case

Inject constants and other snippets into source code.

Usage

.babelrc
{
  "plugins": [
    ["transform-string-literal-replace", {
      "Sebastiaan": "Seb",
      "SOME_MESSAGE": 1234567890
    }]
  ]
}
import {transform} from 'babel-core'
const input = `var name = 'Sebastiaan';alert('SOME_MESSAGE');`
const output = transform(input)
// -> `var name = 'Seb';alert(1234567890);`

Options

pattern

An Object or Map containing strings to replace with values that are either String, Number, Boolean, or null.