Comparing version 1.3.0 to 1.3.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LazyType = exports.PartialType = exports.EnumType = exports.IntersectionType = exports.UnionType = exports.TupleType = exports.ArrayType = exports.ObjectType = exports.keySignature = exports.DateType = exports.NullableType = exports.OptionalType = exports.UnknownType = exports.LiteralType = exports.NullType = exports.UndefinedType = exports.BigIntType = exports.NumberType = exports.BooleanType = exports.StringType = exports.coercionTypeSymbol = exports.ValidationError = exports.Type = void 0; | ||
const _mapSymb = Symbol.for('_map'); | ||
function clone(value) { | ||
if (typeof value !== 'object' || value === null) { | ||
return value; | ||
} | ||
if (Array.isArray(value)) { | ||
return value.map(elem => clone(elem)); | ||
} | ||
const cpy = Object.create(null); | ||
for (const k in value) { | ||
cpy[k] = clone(value[k]); | ||
} | ||
for (const s of Object.getOwnPropertySymbols(value)) { | ||
cpy[s] = clone(value[s]); | ||
} | ||
Object.setPrototypeOf(cpy, Object.getPrototypeOf(value)); | ||
return cpy; | ||
} | ||
class Type { | ||
@@ -31,6 +47,7 @@ constructor() { } | ||
map(fn) { | ||
this[_mapSymb] = fn; | ||
const parse = this.parse.bind(this); | ||
this.parse = (value) => fn(parse(value)); | ||
return this; | ||
const cpy = clone(this); | ||
const parse = cpy.parse.bind(cpy); | ||
cpy.parse = (value) => fn(parse(value)); | ||
cpy[exports.coercionTypeSymbol] = true; | ||
return cpy; | ||
} | ||
@@ -37,0 +54,0 @@ } |
{ | ||
"name": "myzod", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "", | ||
@@ -29,10 +29,10 @@ "main": "./libs/index.js", | ||
"devDependencies": { | ||
"@types/mocha": "^8.0.4", | ||
"@types/node": "^14.14.9", | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.22", | ||
"benchmonkey": "0.0.7", | ||
"mocha": "^8.2.1", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.2.0", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.1.2" | ||
"prettier": "^2.2.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.3" | ||
}, | ||
@@ -39,0 +39,0 @@ "nyc": { |
104585
7
1793