@protobufjs/codegen
Minimalistic code generation utility.
API
-
codegen([functionParams: string[]
], [functionName: string]): Codegen
Begins generating a function.
-
codegen.verbose = false
When set to true, codegen will log generated code to console. Useful for debugging.
Invoking codegen returns an appender function that appends code to the function's body and returns itself:
-
Codegen(formatString: string
, [...formatParams: any
]): Codegen
Appends code to the function's body. The format string can contain placeholders specifying the types of inserted format parameters:
%d
: Integer%f
: Floating point number%j
: JSON.stringify'ed value%s
: Raw string
-
Codegen([scope: Object.<string,*>
]): Function
Finishes the function and returns it.
-
Codegen.toString([functionNameOverride: string
]): string
Returns the function as a string.
Example
var codegen = require("@protobufjs/codegen");
var add = codegen(["a", "b"], "add")
("// awesome comment")
("return a + b - c + %d", 1)
({ c: 1 });
console.log(add.toString());
console.log(add(1, 2));
License: BSD 3-Clause License