0.1.6 • Published 4 years ago
babel-plugin-transform-property-cases v0.1.6
babel-plugin-transform-property-cases
Babel plugin to transform properties into different cases.
Installation
$ yarn add -D babel-plugin-transform-property-cases
Usage
Specify which object property names should be converted to different cases by providing arrays under the following keys in the plugin config:
camelCase
kebab-case
param-case
PascalCase
snake_case
E.g.
{
"camelCase": ["ultra calm", "semi_calm"]
}
would convert:
const o = {
"ultra calm": "lake",
semi_calm: "horse",
};
into:
const o = {
ultraCalm: "lake",
semiCalm: "horse",
};
Property Collections
Also available are property collections for which you can speficy global case-change behaviour. Currently only allCss
is supported, converting any standard css property name according to the specified source
and/or target
subkeys.
E.g.
{
"allCss": {
"source": "snake_case"
}
}
Would convert any margin_top
poperty to margin-top
.
{
"allCss": {
"target": "PascalCase"
}
}
Would convert margin-top
to MarginTop
.
And
{
"allCss": {
"target": "camelCase",
"source": "PascalCase"
}
}
Would convert MarginTop
to marginTop
.
Example
Input file:
const yaDa = 3;
const thing = {
blaBla: 7,
yaDa,
paddingBottom: "1em",
};
function mutateStuff(stuff) {
stuff.blaBla += 2;
}
const meal = {
TotalSoup: {
"munster _vs_ cheese": {
"basel-Craft": "yaDa",
},
},
};
.babelrc
:
{
"plugins": [
[
"babel-plugin-transform-property-cases",
{
"allCss": {
"source": "camelCase"
},
"kebab-case": ["blaBla", "yaDa"],
"camelCase": ["TotalSoup"],
"PascalCase": ["munster _vs_ cheese"],
"snake_case": ["basel-Craft"]
}
]
]
}
Output:
const yaDa = 3;
const thing = {
"bla-bla": 7,
"ya-da": yaDa,
"padding-bottom": "1em",
};
function mutateStuff(stuff) {
stuff["bla-bla"] += 2;
}
const meal = {
totalSoup: {
MunsterVsCheese: {
basel_craft: "yaDa",
},
},
};
License
This plugin is licensed under the MIT license. See LICENSE.
Thanks
This plugin relies heavily on: