zod 3.13.2 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,23 +10,19 @@
10
10
  <a href="./src/__tests__" rel="nofollow"><img src="./coverage.svg" alt="coverage"></a>
11
11
  <a href="https://discord.gg/KaSRdyX2vc" rel="nofollow"><img src="https://img.shields.io/discord/893487829802418277?label=Discord&logo=discord&logoColor=white" alt="discord server"></a>
12
12
  </p>
13
- <p align="center">
14
- by <a href="https://twitter.com/colinhacks">@colinhacks</a>
15
- </p>
16
13
 
17
- > Hi! Colin here, creator of Zod. I hope you find it easy to use and powerful enough for all your use cases. If you have any issues or suggestions, please [open an issue](https://github.com/colinhacks/zod/issues/new)!
18
- >
19
- > If you like typesafety, check out my other library [tRPC](https://trpc.io). It works in concert with Zod to provide a seamless way to build end-to-end typesafe APIs without GraphQL or code generation — just TypeScript.
20
- >
21
- > Colin (AKA [@colinhacks](https://twitter.com/colinhacks))
22
-
23
- <h3 align="center">
24
- <a href="https://discord.gg/RcG33DQJdf">💬 Chat on Discord</a>
25
- ·
26
- <a href="https://zod.js.org/">📝 Explore the Docs</a>
27
- ·
28
- <a href="https://www.npmjs.com/package/zod">✨ Install Zod</a>
29
- </h3>
14
+ <div align="center">
15
+ <a href="https://discord.gg/RcG33DQJdf">Discord</a>
16
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
17
+ <a href="https://www.npmjs.com/package/zod">NPM</a>
18
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
19
+ <a href="https://github.com/colinhacks/zod/issues/new">Issues</a>
20
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
21
+ <a href="https://twitter.com/colinhacks">@colinhacks</a>
22
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
23
+ <a href="https://trpc.io">tRPC</a>
24
+ <br />
25
+ </div>
30
26
 
31
27
  <br/>
32
28
 
@@ -34,6 +30,10 @@ These docs have been translated into [Chinese](./README_ZH.md).
34
30
 
35
31
  # Table of contents
36
32
 
33
+ <!-- The full documentation is available both on the [official documentation site](https://zod.js.org/) (recommended) and in `README.md`.
34
+
35
+ ### Go to [zod.js.org](https://zod.js.org) >> -->
36
+
37
37
  - [What is Zod](#what-is-zod)
38
38
  - [Installation](#installation)
39
39
  - [Ecosystem](#ecosystem)
@@ -114,7 +114,7 @@ Zod is designed to be as developer-friendly as possible. The goal is to eliminat
114
114
  Some other great aspects:
115
115
 
116
116
  - Zero dependencies
117
- - Works in Node.js and browsers (including IE 11)
117
+ - Works in Node.js and all modern browsers
118
118
  - Tiny: 8kb minified + zipped
119
119
  - Immutable: methods (i.e. `.optional()`) return a new instance
120
120
  - Concise, chainable interface
@@ -246,6 +246,7 @@ There are a growing number of tools that are built atop or support Zod natively!
246
246
 
247
247
  - [`react-hook-form`](https://github.com/react-hook-form/resolvers#zod): A first-party Zod resolver for React Hook Form
248
248
  - [`zod-formik-adapter`](https://github.com/robertLichtnow/zod-formik-adapter): A community-maintained Formik adapter for Zod
249
+ - [`react-zorm`](https://github.com/esamattis/react-zorm): Standalone `<form>` generation and validation for React using Zod
249
250
 
250
251
  # Basic usage
251
252
 
@@ -427,26 +428,25 @@ const isActive = z.boolean({
427
428
  ```
428
429
 
429
430
  ## Dates
431
+
430
432
  z.date() accepts a date, not a date string
433
+
431
434
  ```ts
432
- z.date().safeParse( new Date() ) // success: true
433
- z.date().safeParse( '2022-01-12T00:00:00.000Z' ) // success: false
435
+ z.date().safeParse(new Date()); // success: true
436
+ z.date().safeParse("2022-01-12T00:00:00.000Z"); // success: false
434
437
  ```
435
438
 
436
439
  To allow for dates or date strings, you can use preprocess
440
+
437
441
  ```ts
438
- const dateSchema = z.preprocess(
439
- arg => {
440
- if ( typeof arg == 'string' || arg instanceof Date )
441
- return new Date( arg )
442
- },
443
- z.date()
444
- )
445
- type DateSchema = z.infer<typeof dateSchema>
442
+ const dateSchema = z.preprocess((arg) => {
443
+ if (typeof arg == "string" || arg instanceof Date) return new Date(arg);
444
+ }, z.date());
445
+ type DateSchema = z.infer<typeof dateSchema>;
446
446
  // type DateSchema = Date
447
447
 
448
- dateSchema.safeParse( new Date( '1/12/22' ) ) // success: true
449
- dateSchema.safeParse( '2022-01-12T00:00:00.000Z' ) // success: true
448
+ dateSchema.safeParse(new Date("1/12/22")); // success: true
449
+ dateSchema.safeParse("2022-01-12T00:00:00.000Z"); // success: true
450
450
  ```
451
451
 
452
452
  ## Zod enums
@@ -556,6 +556,12 @@ FruitEnum.parse(3); // passes
556
556
  FruitEnum.parse("Cantaloupe"); // fails
557
557
  ```
558
558
 
559
+ You can access the underlying object with the `.enum` property:
560
+
561
+ ```ts
562
+ FruitEnum.enum.Apple; // "apple"
563
+ ```
564
+
559
565
  ## Optionals
560
566
 
561
567
  You can make any schema optional with `z.optional()`:
package/lib/ZodError.js CHANGED
@@ -1,58 +1,7 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __values = (this && this.__values) || function(o) {
18
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
- if (m) return m.call(o);
20
- if (o && typeof o.length === "number") return {
21
- next: function () {
22
- if (o && i >= o.length) o = void 0;
23
- return { value: o && o[i++], done: !o };
24
- }
25
- };
26
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
- };
28
- var __read = (this && this.__read) || function (o, n) {
29
- var m = typeof Symbol === "function" && o[Symbol.iterator];
30
- if (!m) return o;
31
- var i = m.call(o), r, ar = [], e;
32
- try {
33
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
34
- }
35
- catch (error) { e = { error: error }; }
36
- finally {
37
- try {
38
- if (r && !r.done && (m = i["return"])) m.call(i);
39
- }
40
- finally { if (e) throw e.error; }
41
- }
42
- return ar;
43
- };
44
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
46
- if (ar || !(i in from)) {
47
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
48
- ar[i] = from[i];
49
- }
50
- }
51
- return to.concat(ar || Array.prototype.slice.call(from));
52
- };
53
2
  Object.defineProperty(exports, "__esModule", { value: true });
54
3
  exports.setErrorMap = exports.overrideErrorMap = exports.defaultErrorMap = exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
55
- var util_1 = require("./helpers/util");
4
+ const util_1 = require("./helpers/util");
56
5
  exports.ZodIssueCode = util_1.util.arrayToEnum([
57
6
  "invalid_type",
58
7
  "custom",
@@ -69,238 +18,194 @@ exports.ZodIssueCode = util_1.util.arrayToEnum([
69
18
  "invalid_intersection_types",
70
19
  "not_multiple_of",
71
20
  ]);
72
- var quotelessJson = function (obj) {
73
- var json = JSON.stringify(obj, null, 2);
21
+ const quotelessJson = (obj) => {
22
+ const json = JSON.stringify(obj, null, 2);
74
23
  return json.replace(/"([^"]+)":/g, "$1:");
75
24
  };
76
25
  exports.quotelessJson = quotelessJson;
77
- var ZodError = /** @class */ (function (_super) {
78
- __extends(ZodError, _super);
79
- function ZodError(issues) {
80
- var _newTarget = this.constructor;
81
- var _this = _super.call(this) || this;
82
- _this.issues = [];
83
- _this.format = function () {
84
- var fieldErrors = { _errors: [] };
85
- var processError = function (error) {
86
- var e_1, _a;
87
- try {
88
- for (var _b = __values(error.issues), _c = _b.next(); !_c.done; _c = _b.next()) {
89
- var issue = _c.value;
90
- if (issue.code === "invalid_union") {
91
- issue.unionErrors.map(processError);
92
- }
93
- else if (issue.code === "invalid_return_type") {
94
- processError(issue.returnTypeError);
95
- }
96
- else if (issue.code === "invalid_arguments") {
97
- processError(issue.argumentsError);
98
- }
99
- else if (issue.path.length === 0) {
100
- fieldErrors._errors.push(issue.message);
101
- }
102
- else {
103
- var curr = fieldErrors;
104
- var i = 0;
105
- while (i < issue.path.length) {
106
- var el = issue.path[i];
107
- var terminal = i === issue.path.length - 1;
108
- if (!terminal) {
109
- if (typeof el === "string") {
110
- curr[el] = curr[el] || { _errors: [] };
111
- }
112
- else if (typeof el === "number") {
113
- var errorArray = [];
114
- errorArray._errors = [];
115
- curr[el] = curr[el] || errorArray;
116
- }
117
- }
118
- else {
26
+ class ZodError extends Error {
27
+ constructor(issues) {
28
+ super();
29
+ this.issues = [];
30
+ this.format = () => {
31
+ const fieldErrors = { _errors: [] };
32
+ const processError = (error) => {
33
+ for (const issue of error.issues) {
34
+ if (issue.code === "invalid_union") {
35
+ issue.unionErrors.map(processError);
36
+ }
37
+ else if (issue.code === "invalid_return_type") {
38
+ processError(issue.returnTypeError);
39
+ }
40
+ else if (issue.code === "invalid_arguments") {
41
+ processError(issue.argumentsError);
42
+ }
43
+ else if (issue.path.length === 0) {
44
+ fieldErrors._errors.push(issue.message);
45
+ }
46
+ else {
47
+ let curr = fieldErrors;
48
+ let i = 0;
49
+ while (i < issue.path.length) {
50
+ const el = issue.path[i];
51
+ const terminal = i === issue.path.length - 1;
52
+ if (!terminal) {
53
+ if (typeof el === "string") {
119
54
  curr[el] = curr[el] || { _errors: [] };
120
- curr[el]._errors.push(issue.message);
121
55
  }
122
- curr = curr[el];
123
- i++;
56
+ else if (typeof el === "number") {
57
+ const errorArray = [];
58
+ errorArray._errors = [];
59
+ curr[el] = curr[el] || errorArray;
60
+ }
124
61
  }
62
+ else {
63
+ curr[el] = curr[el] || { _errors: [] };
64
+ curr[el]._errors.push(issue.message);
65
+ }
66
+ curr = curr[el];
67
+ i++;
125
68
  }
126
69
  }
127
70
  }
128
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
129
- finally {
130
- try {
131
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
132
- }
133
- finally { if (e_1) throw e_1.error; }
134
- }
135
71
  };
136
- processError(_this);
72
+ processError(this);
137
73
  return fieldErrors;
138
74
  };
139
- _this.addIssue = function (sub) {
140
- _this.issues = __spreadArray(__spreadArray([], __read(_this.issues), false), [sub], false);
75
+ this.addIssue = (sub) => {
76
+ this.issues = [...this.issues, sub];
141
77
  };
142
- _this.addIssues = function (subs) {
143
- if (subs === void 0) { subs = []; }
144
- _this.issues = __spreadArray(__spreadArray([], __read(_this.issues), false), __read(subs), false);
78
+ this.addIssues = (subs = []) => {
79
+ this.issues = [...this.issues, ...subs];
145
80
  };
146
- var actualProto = _newTarget.prototype;
81
+ const actualProto = new.target.prototype;
147
82
  if (Object.setPrototypeOf) {
148
83
  // eslint-disable-next-line ban/ban
149
- Object.setPrototypeOf(_this, actualProto);
84
+ Object.setPrototypeOf(this, actualProto);
150
85
  }
151
86
  else {
152
- _this.__proto__ = actualProto;
87
+ this.__proto__ = actualProto;
153
88
  }
154
- _this.name = "ZodError";
155
- _this.issues = issues;
156
- return _this;
89
+ this.name = "ZodError";
90
+ this.issues = issues;
91
+ }
92
+ get errors() {
93
+ return this.issues;
157
94
  }
158
- Object.defineProperty(ZodError.prototype, "errors", {
159
- get: function () {
160
- return this.issues;
161
- },
162
- enumerable: false,
163
- configurable: true
164
- });
165
- ZodError.prototype.toString = function () {
95
+ toString() {
166
96
  return this.message;
167
- };
168
- Object.defineProperty(ZodError.prototype, "message", {
169
- get: function () {
170
- return JSON.stringify(this.issues, null, 2);
171
- },
172
- enumerable: false,
173
- configurable: true
174
- });
175
- Object.defineProperty(ZodError.prototype, "isEmpty", {
176
- get: function () {
177
- return this.issues.length === 0;
178
- },
179
- enumerable: false,
180
- configurable: true
181
- });
182
- ZodError.prototype.flatten = function (mapper) {
183
- var e_2, _a;
184
- if (mapper === void 0) { mapper = function (issue) { return issue.message; }; }
185
- var fieldErrors = {};
186
- var formErrors = [];
187
- try {
188
- for (var _b = __values(this.issues), _c = _b.next(); !_c.done; _c = _b.next()) {
189
- var sub = _c.value;
190
- if (sub.path.length > 0) {
191
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
192
- fieldErrors[sub.path[0]].push(mapper(sub));
193
- }
194
- else {
195
- formErrors.push(mapper(sub));
196
- }
97
+ }
98
+ get message() {
99
+ return JSON.stringify(this.issues, null, 2);
100
+ }
101
+ get isEmpty() {
102
+ return this.issues.length === 0;
103
+ }
104
+ flatten(mapper = (issue) => issue.message) {
105
+ const fieldErrors = {};
106
+ const formErrors = [];
107
+ for (const sub of this.issues) {
108
+ if (sub.path.length > 0) {
109
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
110
+ fieldErrors[sub.path[0]].push(mapper(sub));
197
111
  }
198
- }
199
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
200
- finally {
201
- try {
202
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
112
+ else {
113
+ formErrors.push(mapper(sub));
203
114
  }
204
- finally { if (e_2) throw e_2.error; }
205
115
  }
206
- return { formErrors: formErrors, fieldErrors: fieldErrors };
207
- };
208
- Object.defineProperty(ZodError.prototype, "formErrors", {
209
- get: function () {
210
- return this.flatten();
211
- },
212
- enumerable: false,
213
- configurable: true
214
- });
215
- ZodError.create = function (issues) {
216
- var error = new ZodError(issues);
217
- return error;
218
- };
219
- return ZodError;
220
- }(Error));
116
+ return { formErrors, fieldErrors };
117
+ }
118
+ get formErrors() {
119
+ return this.flatten();
120
+ }
121
+ }
221
122
  exports.ZodError = ZodError;
222
- var defaultErrorMap = function (issue, _ctx) {
223
- var message;
123
+ ZodError.create = (issues) => {
124
+ const error = new ZodError(issues);
125
+ return error;
126
+ };
127
+ const defaultErrorMap = (issue, _ctx) => {
128
+ let message;
224
129
  switch (issue.code) {
225
130
  case exports.ZodIssueCode.invalid_type:
226
131
  if (issue.received === "undefined") {
227
132
  message = "Required";
228
133
  }
229
134
  else {
230
- message = "Expected ".concat(issue.expected, ", received ").concat(issue.received);
135
+ message = `Expected ${issue.expected}, received ${issue.received}`;
231
136
  }
232
137
  break;
233
138
  case exports.ZodIssueCode.unrecognized_keys:
234
- message = "Unrecognized key(s) in object: ".concat(issue.keys
235
- .map(function (k) { return "'".concat(k, "'"); })
236
- .join(", "));
139
+ message = `Unrecognized key(s) in object: ${issue.keys
140
+ .map((k) => `'${k}'`)
141
+ .join(", ")}`;
237
142
  break;
238
143
  case exports.ZodIssueCode.invalid_union:
239
- message = "Invalid input";
144
+ message = `Invalid input`;
240
145
  break;
241
146
  case exports.ZodIssueCode.invalid_union_discriminator:
242
- message = "Invalid discriminator value. Expected ".concat(issue.options
243
- .map(function (val) { return (typeof val === "string" ? "'".concat(val, "'") : val); })
244
- .join(" | "));
147
+ message = `Invalid discriminator value. Expected ${issue.options
148
+ .map((val) => (typeof val === "string" ? `'${val}'` : val))
149
+ .join(" | ")}`;
245
150
  break;
246
151
  case exports.ZodIssueCode.invalid_enum_value:
247
- message = "Invalid enum value. Expected ".concat(issue.options
248
- .map(function (val) { return (typeof val === "string" ? "'".concat(val, "'") : val); })
249
- .join(" | "));
152
+ message = `Invalid enum value. Expected ${issue.options
153
+ .map((val) => (typeof val === "string" ? `'${val}'` : val))
154
+ .join(" | ")}`;
250
155
  break;
251
156
  case exports.ZodIssueCode.invalid_arguments:
252
- message = "Invalid function arguments";
157
+ message = `Invalid function arguments`;
253
158
  break;
254
159
  case exports.ZodIssueCode.invalid_return_type:
255
- message = "Invalid function return type";
160
+ message = `Invalid function return type`;
256
161
  break;
257
162
  case exports.ZodIssueCode.invalid_date:
258
- message = "Invalid date";
163
+ message = `Invalid date`;
259
164
  break;
260
165
  case exports.ZodIssueCode.invalid_string:
261
166
  if (issue.validation !== "regex")
262
- message = "Invalid ".concat(issue.validation);
167
+ message = `Invalid ${issue.validation}`;
263
168
  else
264
169
  message = "Invalid";
265
170
  break;
266
171
  case exports.ZodIssueCode.too_small:
267
172
  if (issue.type === "array")
268
- message = "Array must contain ".concat(issue.inclusive ? "at least" : "more than", " ").concat(issue.minimum, " element(s)");
173
+ message = `Array must contain ${issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
269
174
  else if (issue.type === "string")
270
- message = "String must contain ".concat(issue.inclusive ? "at least" : "over", " ").concat(issue.minimum, " character(s)");
175
+ message = `String must contain ${issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
271
176
  else if (issue.type === "number")
272
- message = "Number must be greater than ".concat(issue.inclusive ? "or equal to " : "").concat(issue.minimum);
177
+ message = `Number must be greater than ${issue.inclusive ? `or equal to ` : ``}${issue.minimum}`;
273
178
  else
274
179
  message = "Invalid input";
275
180
  break;
276
181
  case exports.ZodIssueCode.too_big:
277
182
  if (issue.type === "array")
278
- message = "Array must contain ".concat(issue.inclusive ? "at most" : "less than", " ").concat(issue.maximum, " element(s)");
183
+ message = `Array must contain ${issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
279
184
  else if (issue.type === "string")
280
- message = "String must contain ".concat(issue.inclusive ? "at most" : "under", " ").concat(issue.maximum, " character(s)");
185
+ message = `String must contain ${issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
281
186
  else if (issue.type === "number")
282
- message = "Number must be less than ".concat(issue.inclusive ? "or equal to " : "").concat(issue.maximum);
187
+ message = `Number must be less than ${issue.inclusive ? `or equal to ` : ``}${issue.maximum}`;
283
188
  else
284
189
  message = "Invalid input";
285
190
  break;
286
191
  case exports.ZodIssueCode.custom:
287
- message = "Invalid input";
192
+ message = `Invalid input`;
288
193
  break;
289
194
  case exports.ZodIssueCode.invalid_intersection_types:
290
- message = "Intersection results could not be merged";
195
+ message = `Intersection results could not be merged`;
291
196
  break;
292
197
  case exports.ZodIssueCode.not_multiple_of:
293
- message = "Number must be a multiple of ".concat(issue.multipleOf);
198
+ message = `Number must be a multiple of ${issue.multipleOf}`;
294
199
  break;
295
200
  default:
296
201
  message = _ctx.defaultError;
297
202
  util_1.util.assertNever(issue);
298
203
  }
299
- return { message: message };
204
+ return { message };
300
205
  };
301
206
  exports.defaultErrorMap = defaultErrorMap;
302
207
  exports.overrideErrorMap = exports.defaultErrorMap;
303
- var setErrorMap = function (map) {
208
+ const setErrorMap = (map) => {
304
209
  exports.overrideErrorMap = map;
305
210
  };
306
211
  exports.setErrorMap = setErrorMap;
@@ -3,76 +3,76 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var benchmark_1 = __importDefault(require("benchmark"));
7
- var index_1 = require("../index");
8
- var doubleSuite = new benchmark_1.default.Suite("z.discriminatedUnion: double");
9
- var manySuite = new benchmark_1.default.Suite("z.discriminatedUnion: many");
10
- var aSchema = index_1.z.object({
6
+ const benchmark_1 = __importDefault(require("benchmark"));
7
+ const index_1 = require("../index");
8
+ const doubleSuite = new benchmark_1.default.Suite("z.discriminatedUnion: double");
9
+ const manySuite = new benchmark_1.default.Suite("z.discriminatedUnion: many");
10
+ const aSchema = index_1.z.object({
11
11
  type: index_1.z.literal("a"),
12
12
  });
13
- var objA = {
13
+ const objA = {
14
14
  type: "a",
15
15
  };
16
- var bSchema = index_1.z.object({
16
+ const bSchema = index_1.z.object({
17
17
  type: index_1.z.literal("b"),
18
18
  });
19
- var objB = {
19
+ const objB = {
20
20
  type: "b",
21
21
  };
22
- var cSchema = index_1.z.object({
22
+ const cSchema = index_1.z.object({
23
23
  type: index_1.z.literal("c"),
24
24
  });
25
- var objC = {
25
+ const objC = {
26
26
  type: "c",
27
27
  };
28
- var dSchema = index_1.z.object({
28
+ const dSchema = index_1.z.object({
29
29
  type: index_1.z.literal("d"),
30
30
  });
31
- var double = index_1.z.discriminatedUnion("type", [aSchema, bSchema]);
32
- var many = index_1.z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]);
31
+ const double = index_1.z.discriminatedUnion("type", [aSchema, bSchema]);
32
+ const many = index_1.z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]);
33
33
  doubleSuite
34
- .add("valid: a", function () {
34
+ .add("valid: a", () => {
35
35
  double.parse(objA);
36
36
  })
37
- .add("valid: b", function () {
37
+ .add("valid: b", () => {
38
38
  double.parse(objB);
39
39
  })
40
- .add("invalid: null", function () {
40
+ .add("invalid: null", () => {
41
41
  try {
42
42
  double.parse(null);
43
43
  }
44
44
  catch (err) { }
45
45
  })
46
- .add("invalid: wrong shape", function () {
46
+ .add("invalid: wrong shape", () => {
47
47
  try {
48
48
  double.parse(objC);
49
49
  }
50
50
  catch (err) { }
51
51
  })
52
- .on("cycle", function (e) {
53
- console.log("".concat(doubleSuite.name, ": ").concat(e.target));
52
+ .on("cycle", (e) => {
53
+ console.log(`${doubleSuite.name}: ${e.target}`);
54
54
  });
55
55
  manySuite
56
- .add("valid: a", function () {
56
+ .add("valid: a", () => {
57
57
  many.parse(objA);
58
58
  })
59
- .add("valid: c", function () {
59
+ .add("valid: c", () => {
60
60
  many.parse(objC);
61
61
  })
62
- .add("invalid: null", function () {
62
+ .add("invalid: null", () => {
63
63
  try {
64
64
  many.parse(null);
65
65
  }
66
66
  catch (err) { }
67
67
  })
68
- .add("invalid: wrong shape", function () {
68
+ .add("invalid: wrong shape", () => {
69
69
  try {
70
70
  many.parse({ type: "unknown" });
71
71
  }
72
72
  catch (err) { }
73
73
  })
74
- .on("cycle", function (e) {
75
- console.log("".concat(manySuite.name, ": ").concat(e.target));
74
+ .on("cycle", (e) => {
75
+ console.log(`${manySuite.name}: ${e.target}`);
76
76
  });
77
77
  exports.default = {
78
78
  suites: [doubleSuite, manySuite],