@dzeio/schema 0.3.2 → 0.4.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/dist/Schema.d.mts CHANGED
@@ -194,6 +194,7 @@ declare class SchemaLiteral<Type> extends SchemaItem<Type> {
194
194
  declare class SchemaNullable<Type extends SchemaItem> extends SchemaItem<SchemaInfer<Type> | undefined> {
195
195
  readonly child: Type;
196
196
  constructor(child: Type);
197
+ falthyAsNull(): this;
197
198
  unwrap(): Type;
198
199
  parse(input: unknown, options?: {
199
200
  fast?: boolean;
package/dist/Schema.d.ts CHANGED
@@ -194,6 +194,7 @@ declare class SchemaLiteral<Type> extends SchemaItem<Type> {
194
194
  declare class SchemaNullable<Type extends SchemaItem> extends SchemaItem<SchemaInfer<Type> | undefined> {
195
195
  readonly child: Type;
196
196
  constructor(child: Type);
197
+ falthyAsNull(): this;
197
198
  unwrap(): Type;
198
199
  parse(input: unknown, options?: {
199
200
  fast?: boolean;
package/dist/Schema.js CHANGED
@@ -316,6 +316,10 @@ var SchemaNullable = class extends SchemaItem {
316
316
  super([child]);
317
317
  this.child = child;
318
318
  }
319
+ falthyAsNull() {
320
+ this.addPreProcess((it) => !it ? void 0 : it);
321
+ return this;
322
+ }
319
323
  unwrap() {
320
324
  return this.child;
321
325
  }
@@ -335,6 +339,9 @@ var SchemaNullable = class extends SchemaItem {
335
339
  return typeof value === "undefined" || value === null;
336
340
  }
337
341
  };
342
+ __decorateClass([
343
+ parceable()
344
+ ], SchemaNullable.prototype, "falthyAsNull", 1);
338
345
 
339
346
  // src/items/object.ts
340
347
  var import_object_util2 = require("@dzeio/object-util");
@@ -441,7 +448,16 @@ var SchemaDate = class extends SchemaItem {
441
448
  switch (format) {
442
449
  case "yy-mm-dd":
443
450
  case "iso8601": {
444
- this.addPreProcess((it) => typeof it === "string" ? new Date(it) : it);
451
+ this.addPreProcess((it) => {
452
+ if (typeof it !== "string") {
453
+ return it;
454
+ }
455
+ const date = new Date(it);
456
+ if (isNaN(date.getDate())) {
457
+ return it;
458
+ }
459
+ return date;
460
+ });
445
461
  break;
446
462
  }
447
463
  case "jj/mm/yy": {
@@ -453,7 +469,11 @@ var SchemaDate = class extends SchemaItem {
453
469
  if (splitted.length !== 3) {
454
470
  return input;
455
471
  }
456
- return new Date(splitted[2], splitted[1] - 1, splitted[0]);
472
+ const date = new Date(splitted[2], splitted[1] - 1, splitted[0]);
473
+ if (isNaN(date.getDate())) {
474
+ return input;
475
+ }
476
+ return date;
457
477
  });
458
478
  }
459
479
  }
package/dist/Schema.mjs CHANGED
@@ -273,6 +273,10 @@ var SchemaNullable = class extends SchemaItem {
273
273
  super([child]);
274
274
  this.child = child;
275
275
  }
276
+ falthyAsNull() {
277
+ this.addPreProcess((it) => !it ? void 0 : it);
278
+ return this;
279
+ }
276
280
  unwrap() {
277
281
  return this.child;
278
282
  }
@@ -292,6 +296,9 @@ var SchemaNullable = class extends SchemaItem {
292
296
  return typeof value === "undefined" || value === null;
293
297
  }
294
298
  };
299
+ __decorateClass([
300
+ parceable()
301
+ ], SchemaNullable.prototype, "falthyAsNull", 1);
295
302
 
296
303
  // src/items/object.ts
297
304
  import { isObject, objectClone, objectLoop } from "@dzeio/object-util";
@@ -398,7 +405,16 @@ var SchemaDate = class extends SchemaItem {
398
405
  switch (format) {
399
406
  case "yy-mm-dd":
400
407
  case "iso8601": {
401
- this.addPreProcess((it) => typeof it === "string" ? new Date(it) : it);
408
+ this.addPreProcess((it) => {
409
+ if (typeof it !== "string") {
410
+ return it;
411
+ }
412
+ const date = new Date(it);
413
+ if (isNaN(date.getDate())) {
414
+ return it;
415
+ }
416
+ return date;
417
+ });
402
418
  break;
403
419
  }
404
420
  case "jj/mm/yy": {
@@ -410,7 +426,11 @@ var SchemaDate = class extends SchemaItem {
410
426
  if (splitted.length !== 3) {
411
427
  return input;
412
428
  }
413
- return new Date(splitted[2], splitted[1] - 1, splitted[0]);
429
+ const date = new Date(splitted[2], splitted[1] - 1, splitted[0]);
430
+ if (isNaN(date.getDate())) {
431
+ return input;
432
+ }
433
+ return date;
414
434
  });
415
435
  }
416
436
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dzeio/schema",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "dependencies": {
5
5
  "@dzeio/object-util": "^1.8.3"
6
6
  },