@dzeio/schema 0.3.3 → 0.4.1
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 +1 -0
- package/dist/Schema.d.ts +1 -0
- package/dist/Schema.js +13 -2
- package/dist/Schema.mjs +13 -2
- package/package.json +1 -1
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,11 +316,19 @@ 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
|
}
|
|
322
326
|
parse(input, options) {
|
|
323
|
-
|
|
327
|
+
const res = super.parse(input, options);
|
|
328
|
+
if (!res.valid) {
|
|
329
|
+
return res;
|
|
330
|
+
}
|
|
331
|
+
if (this.isNull(res.object)) {
|
|
324
332
|
return {
|
|
325
333
|
valid: true,
|
|
326
334
|
object: void 0
|
|
@@ -329,12 +337,15 @@ var SchemaNullable = class extends SchemaItem {
|
|
|
329
337
|
return this.child.parse(input, options);
|
|
330
338
|
}
|
|
331
339
|
isOfType(input) {
|
|
332
|
-
return
|
|
340
|
+
return this.isNull(input) || this.child.isOfType(input);
|
|
333
341
|
}
|
|
334
342
|
isNull(value) {
|
|
335
343
|
return typeof value === "undefined" || value === null;
|
|
336
344
|
}
|
|
337
345
|
};
|
|
346
|
+
__decorateClass([
|
|
347
|
+
parceable()
|
|
348
|
+
], SchemaNullable.prototype, "falthyAsNull", 1);
|
|
338
349
|
|
|
339
350
|
// src/items/object.ts
|
|
340
351
|
var import_object_util2 = require("@dzeio/object-util");
|
package/dist/Schema.mjs
CHANGED
|
@@ -273,11 +273,19 @@ 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
|
}
|
|
279
283
|
parse(input, options) {
|
|
280
|
-
|
|
284
|
+
const res = super.parse(input, options);
|
|
285
|
+
if (!res.valid) {
|
|
286
|
+
return res;
|
|
287
|
+
}
|
|
288
|
+
if (this.isNull(res.object)) {
|
|
281
289
|
return {
|
|
282
290
|
valid: true,
|
|
283
291
|
object: void 0
|
|
@@ -286,12 +294,15 @@ var SchemaNullable = class extends SchemaItem {
|
|
|
286
294
|
return this.child.parse(input, options);
|
|
287
295
|
}
|
|
288
296
|
isOfType(input) {
|
|
289
|
-
return
|
|
297
|
+
return this.isNull(input) || this.child.isOfType(input);
|
|
290
298
|
}
|
|
291
299
|
isNull(value) {
|
|
292
300
|
return typeof value === "undefined" || value === null;
|
|
293
301
|
}
|
|
294
302
|
};
|
|
303
|
+
__decorateClass([
|
|
304
|
+
parceable()
|
|
305
|
+
], SchemaNullable.prototype, "falthyAsNull", 1);
|
|
295
306
|
|
|
296
307
|
// src/items/object.ts
|
|
297
308
|
import { isObject, objectClone, objectLoop } from "@dzeio/object-util";
|