type NodeVarObject = { [key: string]: string }; const solidityCodePadding = " ".repeat(8); const pad = (decl: string, padding: string = solidityCodePadding) => padding + decl + "\n"; class DeclCalculator { declType!: string; padding!: string; transformator!: Function; public constructor( declType: string, padding: string = solidityCodePadding, transformator: Function = ( () => (x: any) => x )() ) { this.declType = declType; this.padding = padding; this.transformator = transformator; } private displayVariableName(varObj: NodeVarObject) { return Object.keys(varObj)[0]; } public calculateDecl = (varObj: NodeVarObject, type: string = "bytes32") => { const solidityVariableName = this.displayVariableName(varObj); const solidityVariableValue = this.transformator(Object.values(varObj)[0]); const solidityDeclaration = `${this.declType || type} ${solidityVariableName} = ${solidityVariableValue};`; return pad(solidityDeclaration, this.padding); }; } export { DeclCalculator };