Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lovetingyuan/babel-plugin-transform-constant-string
transform string constant variable
https://github.com/lovetingyuan/babel-plugin-transform-constant-string
babel constant javascript plugin string syntactic-sugar
Last synced: 29 days ago
JSON representation
transform string constant variable
- Host: GitHub
- URL: https://github.com/lovetingyuan/babel-plugin-transform-constant-string
- Owner: lovetingyuan
- License: mit
- Created: 2017-08-20T08:53:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-25T05:16:09.000Z (over 7 years ago)
- Last Synced: 2024-11-30T05:07:17.845Z (about 2 months ago)
- Topics: babel, constant, javascript, plugin, string, syntactic-sugar
- Language: JavaScript
- Size: 28.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-plugin-transform-constant-string
transform constant string variable
## Example
**In**
```js
CONSPORT(HELLO_WORLD)function foo() {
const bar = 'foo-bar'
CONST(THIS_IS_A_CONSTANT_STRING_VALUE)
console.log('other code...');
CONST(
A_FOO,
B_BAR,
C_FOO_BAR
)
return bar
}
```**Out**
```js
"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
```sh
$ npm install babel-plugin-transform-constant-string
```## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json5
{
"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
```sh
$ babel --plugins transform-constant-string script.js
```### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["transform-constant-string"]
});
```### license
MIT