const { gen, data, opts } = it;
const coerceTo = coerceToTypes(types, opts.coerceTypes);
const checkTypes = types.length > 0 &&
- !(coerceTo.length === 0 && types.length === 1 && applicability_1.schemaHasRulesForType(it, types[0]));
+ !(coerceTo.length === 0 && types.length === 1 && (0, applicability_1.schemaHasRulesForType)(it, types[0]));
if (checkTypes) {
const wrongType = checkDataTypes(types, data, opts.strictNumbers, DataType.Wrong);
gen.if(wrongType, () => {
}
function coerceData(it, types, coerceTo) {
const { gen, data, opts } = it;
- const dataType = gen.let("dataType", codegen_1._ `typeof ${data}`);
- const coerced = gen.let("coerced", codegen_1._ `undefined`);
+ const dataType = gen.let("dataType", (0, codegen_1._) `typeof ${data}`);
+ const coerced = gen.let("coerced", (0, codegen_1._) `undefined`);
if (opts.coerceTypes === "array") {
- gen.if(codegen_1._ `${dataType} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen
- .assign(data, codegen_1._ `${data}[0]`)
- .assign(dataType, codegen_1._ `typeof ${data}`)
+ gen.if((0, codegen_1._) `${dataType} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen
+ .assign(data, (0, codegen_1._) `${data}[0]`)
+ .assign(dataType, (0, codegen_1._) `typeof ${data}`)
.if(checkDataTypes(types, data, opts.strictNumbers), () => gen.assign(coerced, data)));
}
- gen.if(codegen_1._ `${coerced} !== undefined`);
+ gen.if((0, codegen_1._) `${coerced} !== undefined`);
for (const t of coerceTo) {
if (COERCIBLE.has(t) || (t === "array" && opts.coerceTypes === "array")) {
coerceSpecificType(t);
gen.else();
reportTypeError(it);
gen.endIf();
- gen.if(codegen_1._ `${coerced} !== undefined`, () => {
+ gen.if((0, codegen_1._) `${coerced} !== undefined`, () => {
gen.assign(data, coerced);
assignParentData(it, coerced);
});
switch (t) {
case "string":
gen
- .elseIf(codegen_1._ `${dataType} == "number" || ${dataType} == "boolean"`)
- .assign(coerced, codegen_1._ `"" + ${data}`)
- .elseIf(codegen_1._ `${data} === null`)
- .assign(coerced, codegen_1._ `""`);
+ .elseIf((0, codegen_1._) `${dataType} == "number" || ${dataType} == "boolean"`)
+ .assign(coerced, (0, codegen_1._) `"" + ${data}`)
+ .elseIf((0, codegen_1._) `${data} === null`)
+ .assign(coerced, (0, codegen_1._) `""`);
return;
case "number":
gen
- .elseIf(codegen_1._ `${dataType} == "boolean" || ${data} === null
+ .elseIf((0, codegen_1._) `${dataType} == "boolean" || ${data} === null
|| (${dataType} == "string" && ${data} && ${data} == +${data})`)
- .assign(coerced, codegen_1._ `+${data}`);
+ .assign(coerced, (0, codegen_1._) `+${data}`);
return;
case "integer":
gen
- .elseIf(codegen_1._ `${dataType} === "boolean" || ${data} === null
+ .elseIf((0, codegen_1._) `${dataType} === "boolean" || ${data} === null
|| (${dataType} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`)
- .assign(coerced, codegen_1._ `+${data}`);
+ .assign(coerced, (0, codegen_1._) `+${data}`);
return;
case "boolean":
gen
- .elseIf(codegen_1._ `${data} === "false" || ${data} === 0 || ${data} === null`)
+ .elseIf((0, codegen_1._) `${data} === "false" || ${data} === 0 || ${data} === null`)
.assign(coerced, false)
- .elseIf(codegen_1._ `${data} === "true" || ${data} === 1`)
+ .elseIf((0, codegen_1._) `${data} === "true" || ${data} === 1`)
.assign(coerced, true);
return;
case "null":
- gen.elseIf(codegen_1._ `${data} === "" || ${data} === 0 || ${data} === false`);
+ gen.elseIf((0, codegen_1._) `${data} === "" || ${data} === 0 || ${data} === false`);
gen.assign(coerced, null);
return;
case "array":
gen
- .elseIf(codegen_1._ `${dataType} === "string" || ${dataType} === "number"
+ .elseIf((0, codegen_1._) `${dataType} === "string" || ${dataType} === "number"
|| ${dataType} === "boolean" || ${data} === null`)
- .assign(coerced, codegen_1._ `[${data}]`);
+ .assign(coerced, (0, codegen_1._) `[${data}]`);
}
}
}
function assignParentData({ gen, parentData, parentDataProperty }, expr) {
// TODO use gen.property
- gen.if(codegen_1._ `${parentData} !== undefined`, () => gen.assign(codegen_1._ `${parentData}[${parentDataProperty}]`, expr));
+ gen.if((0, codegen_1._) `${parentData} !== undefined`, () => gen.assign((0, codegen_1._) `${parentData}[${parentDataProperty}]`, expr));
}
function checkDataType(dataType, data, strictNums, correct = DataType.Correct) {
const EQ = correct === DataType.Correct ? codegen_1.operators.EQ : codegen_1.operators.NEQ;
let cond;
switch (dataType) {
case "null":
- return codegen_1._ `${data} ${EQ} null`;
+ return (0, codegen_1._) `${data} ${EQ} null`;
case "array":
- cond = codegen_1._ `Array.isArray(${data})`;
+ cond = (0, codegen_1._) `Array.isArray(${data})`;
break;
case "object":
- cond = codegen_1._ `${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
+ cond = (0, codegen_1._) `${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
break;
case "integer":
- cond = numCond(codegen_1._ `!(${data} % 1) && !isNaN(${data})`);
+ cond = numCond((0, codegen_1._) `!(${data} % 1) && !isNaN(${data})`);
break;
case "number":
cond = numCond();
break;
default:
- return codegen_1._ `typeof ${data} ${EQ} ${dataType}`;
+ return (0, codegen_1._) `typeof ${data} ${EQ} ${dataType}`;
}
- return correct === DataType.Correct ? cond : codegen_1.not(cond);
+ return correct === DataType.Correct ? cond : (0, codegen_1.not)(cond);
function numCond(_cond = codegen_1.nil) {
- return codegen_1.and(codegen_1._ `typeof ${data} == "number"`, _cond, strictNums ? codegen_1._ `isFinite(${data})` : codegen_1.nil);
+ return (0, codegen_1.and)((0, codegen_1._) `typeof ${data} == "number"`, _cond, strictNums ? (0, codegen_1._) `isFinite(${data})` : codegen_1.nil);
}
}
exports.checkDataType = checkDataType;
return checkDataType(dataTypes[0], data, strictNums, correct);
}
let cond;
- const types = util_1.toHash(dataTypes);
+ const types = (0, util_1.toHash)(dataTypes);
if (types.array && types.object) {
- const notObj = codegen_1._ `typeof ${data} != "object"`;
- cond = types.null ? notObj : codegen_1._ `!${data} || ${notObj}`;
+ const notObj = (0, codegen_1._) `typeof ${data} != "object"`;
+ cond = types.null ? notObj : (0, codegen_1._) `!${data} || ${notObj}`;
delete types.null;
delete types.array;
delete types.object;
if (types.number)
delete types.integer;
for (const t in types)
- cond = codegen_1.and(cond, checkDataType(t, data, strictNums, correct));
+ cond = (0, codegen_1.and)(cond, checkDataType(t, data, strictNums, correct));
return cond;
}
exports.checkDataTypes = checkDataTypes;
const typeError = {
message: ({ schema }) => `must be ${schema}`,
- params: ({ schema, schemaValue }) => typeof schema == "string" ? codegen_1._ `{type: ${schema}}` : codegen_1._ `{type: ${schemaValue}}`,
+ params: ({ schema, schemaValue }) => typeof schema == "string" ? (0, codegen_1._) `{type: ${schema}}` : (0, codegen_1._) `{type: ${schemaValue}}`,
};
function reportTypeError(it) {
const cxt = getTypeErrorContext(it);
- errors_1.reportError(cxt, typeError);
+ (0, errors_1.reportError)(cxt, typeError);
}
exports.reportTypeError = reportTypeError;
function getTypeErrorContext(it) {
const { gen, data, schema } = it;
- const schemaCode = util_1.schemaRefOrVal(it, schema, "type");
+ const schemaCode = (0, util_1.schemaRefOrVal)(it, schema, "type");
return {
gen,
keyword: "type",