babel-plugin-short-private-properties
v1.0.1
Published
A babel plugin which will convert all private properties `_prop` or methods `_doSome` to short name.
Downloads
4
Readme
short-private-properties
This plugin find in ES6 Classes all methods or properties with start _
and replace them with a short name.
Install
yarn add -D babel-plugin-short-private-properties
# or npm i -D babel-plugin-short-private-properties
Input:
class A {
constructor() {
this._veryLondProppertyNameA = "Test class A";
this._veryLondProppertyNameA2 = "Write A";
}
_getAProperty() {
console.log(this._veryLondProppertyNameA);
}
}
class B extends A {
constructor() {
super();
this._veryLondProppertyNameA2 = "Overwrite B";
this._veryLondProppertyNameB = "Test class B";
}
getResult() {
this._getAProperty();
console.log(this._veryLondProppertyNameB);
console.log(this._veryLondProppertyNameA2);
}
}
new B().getResult();
// Test class A
// Test class B
// Overwrite B
Output:
class A {
constructor() {
this._b = "Test class A";
this._c = "Write A";
}
_d() {
console.log(this._b);
}
}
class B extends A {
constructor() {
super();
this._c = "Overwrite B";
this._e = "Test class B";
}
getResult() {
this._d();
console.log(this._e);
console.log(this._c);
}
}
new B().getResult();
// Test class A
// Test class B
// Overwrite B
Usage
Via .babelrc (Recommended)
{
"plugins": ["babel-plugin-short-private-properties"]
}
Via CLI
$ babel --plugins babel-plugin-short-private-properties script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["babel-plugin-short-private-properties"]
});