Buckets:
149 MB
6,599 files
Updated 13 days ago
Ctrl+K
| Name | Size | Uploaded | Xet hash |
|---|---|---|---|
| tests | 1 items | ||
| LICENSE | 1.51 kB xet | dabe1ea9 | |
| README.md | 1.87 kB xet | ab939a36 | |
| index.d.ts | 1.16 kB xet | 740e5c63 | |
| index.js | 3.88 kB xet | 7c359f38 | |
| package.json | 359 Bytes xet | dfd342cc |
@protobufjs/codegen
A 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: 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.<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") // 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
({ c: 1 }); // 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 }
console.log(add(1, 2)); // calculates 1 + 2 - 1 + 1 = 3
License: BSD 3-Clause License
- Total size
- 149 MB
- Files
- 6,599
- Last updated
- Jun 23
- Pre-warmed CDN
- US EU US EU