object.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const benchmark_1 = __importDefault(require("benchmark"));
  7. const index_1 = require("../index");
  8. const emptySuite = new benchmark_1.default.Suite("z.object: empty");
  9. const shortSuite = new benchmark_1.default.Suite("z.object: short");
  10. const longSuite = new benchmark_1.default.Suite("z.object: long");
  11. const empty = index_1.z.object({});
  12. const short = index_1.z.object({
  13. string: index_1.z.string(),
  14. });
  15. const long = index_1.z.object({
  16. string: index_1.z.string(),
  17. number: index_1.z.number(),
  18. boolean: index_1.z.boolean(),
  19. });
  20. emptySuite
  21. .add("valid", () => {
  22. empty.parse({});
  23. })
  24. .add("valid: extra keys", () => {
  25. empty.parse({ string: "string" });
  26. })
  27. .add("invalid: null", () => {
  28. try {
  29. empty.parse(null);
  30. }
  31. catch (err) { }
  32. })
  33. .on("cycle", (e) => {
  34. console.log(`${emptySuite.name}: ${e.target}`);
  35. });
  36. shortSuite
  37. .add("valid", () => {
  38. short.parse({ string: "string" });
  39. })
  40. .add("valid: extra keys", () => {
  41. short.parse({ string: "string", number: 42 });
  42. })
  43. .add("invalid: null", () => {
  44. try {
  45. short.parse(null);
  46. }
  47. catch (err) { }
  48. })
  49. .on("cycle", (e) => {
  50. console.log(`${shortSuite.name}: ${e.target}`);
  51. });
  52. longSuite
  53. .add("valid", () => {
  54. long.parse({ string: "string", number: 42, boolean: true });
  55. })
  56. .add("valid: extra keys", () => {
  57. long.parse({ string: "string", number: 42, boolean: true, list: [] });
  58. })
  59. .add("invalid: null", () => {
  60. try {
  61. long.parse(null);
  62. }
  63. catch (err) { }
  64. })
  65. .on("cycle", (e) => {
  66. console.log(`${longSuite.name}: ${e.target}`);
  67. });
  68. exports.default = {
  69. suites: [emptySuite, shortSuite, longSuite],
  70. };