# protobufjs_codegen_arkts **Repository Path**: ArkTSCentralRepository/protobufjs_codegen_arkts ## Basic Information - **Project Name**: protobufjs_codegen_arkts - **Description**: A minimalistic code generation utility. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-27 - **Last Updated**: 2025-04-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # protobufjs_codegen_arkts 基于protobufjs/codegen原库1.0.2版本进行适配, 所有功能代码已经转换为`ArkTS`文件 ⚠️由于ArkTS不支持函数中使用this关键字,因此本codegen仅支持输入字符串数据类型 ## Install ```sh ohpm install protobufjs_codegen_arkts ``` 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`: Number (integer or floating point value) * `%f`: Floating point value * `%i`: Integer value * `%j`: JSON.stringify'ed value * `%s`: String value * `%%`: Percent sign
* **Codegen([scope: `Object.`]): `Function`**
Finishes the function and returns it. * **Codegen.toString([functionNameOverride: `string`]): `string`**
Returns the function as a string. Example ------- ```js let add = codegen(["a", "b"], "add") // A function with parameters "a" and "b" named "add" ("// awesome comment") // adds the line to the function's body ("return a + b - c + %d", 1); // replaces %d with 1 and adds the line to the body // adds "c" with a value of 1 to the function's scope console.log(add.toString()); // function add(a, b) { return a + b - c + 1 } ``` **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)