GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.8 KiB

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