Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / node_modules / @protobufjs / codegen / README.md
1 @protobufjs/codegen\r
2 ===================\r
3 [![npm](https://img.shields.io/npm/v/@protobufjs/codegen.svg)](https://www.npmjs.com/package/@protobufjs/codegen)\r
4 \r
5 A minimalistic code generation utility.\r
6 \r
7 API\r
8 ---\r
9 \r
10 * **codegen([functionParams: `string[]`], [functionName: string]): `Codegen`**<br />\r
11   Begins generating a function.\r
12 \r
13 * **codegen.verbose = `false`**<br />\r
14   When set to true, codegen will log generated code to console. Useful for debugging.\r
15 \r
16 Invoking **codegen** returns an appender function that appends code to the function's body and returns itself:\r
17 \r
18 * **Codegen(formatString: `string`, [...formatParams: `any`]): Codegen**<br />\r
19   Appends code to the function's body. The format string can contain placeholders specifying the types of inserted format parameters:\r
20 \r
21   * `%d`: Number (integer or floating point value)\r
22   * `%f`: Floating point value\r
23   * `%i`: Integer value\r
24   * `%j`: JSON.stringify'ed value\r
25   * `%s`: String value\r
26   * `%%`: Percent sign<br />\r
27 \r
28 * **Codegen([scope: `Object.<string,*>`]): `Function`**<br />\r
29   Finishes the function and returns it.\r
30 \r
31 * **Codegen.toString([functionNameOverride: `string`]): `string`**<br />\r
32   Returns the function as a string.\r
33 \r
34 Example\r
35 -------\r
36 \r
37 ```js\r
38 var codegen = require("@protobufjs/codegen");\r
39 \r
40 var add = codegen(["a", "b"], "add") // A function with parameters "a" and "b" named "add"\r
41   ("// awesome comment")             // adds the line to the function's body\r
42   ("return a + b - c + %d", 1)       // replaces %d with 1 and adds the line to the body\r
43   ({ c: 1 });                        // adds "c" with a value of 1 to the function's scope\r
44 \r
45 console.log(add.toString()); // function add(a, b) { return a + b - c + 1 }\r
46 console.log(add(1, 2));      // calculates 1 + 2 - 1 + 1 = 3\r
47 ```\r
48 \r
49 **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)\r