@org-formation/tombok
Version:
Lombok for TypeScript
34 lines (33 loc) • 829 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getter = void 0;
const utils_1 = require("./utils");
/**
* This decorator can be used on any class property to make tombok build a Java-like getter.
*
* Example:
* ```typescript
* @getter
* private foo: number;
* ```
*
* will generate:
*
* ```typescript
* public getFoo(): number {
* return this.foo;
* }
* ```
*
* @param {any} target Base class where we are going to mutate its method
* @param {string} key Name of the method that was decorated
*/
function getter(target, key) {
const capitalizedKey = utils_1.capitalize(key);
const methodName = `get${capitalizedKey}`;
target[methodName] = function () {
const obj = this;
return obj[key];
};
}
exports.getter = getter;