Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { type, items } = schema;
if (value === '') {
return undefined;
} else if (type === 'array' && items && nums.has(items.type)) {
return value.map(asNumber);
} else if (type === 'boolean') {
return value === 'true';
} else if (type === 'number') {
return asNumber(value);
}
// If type is undefined, but an enum is present, try and infer the type from
// the enum values
if (schema.enum) {
if (schema.enum.every((x: any) => guessType(x) === 'number')) {
return asNumber(value);
} else if (schema.enum.every((x: any) => guessType(x) === 'boolean')) {
return value === 'true';
}
}
return value;
};
const { type, items } = schema;
if (value === '') {
return undefined;
} else if (type === 'array' && items && nums.has(items.type)) {
return value.map(asNumber);
} else if (type === 'boolean') {
return value === 'true';
} else if (type === 'number') {
return asNumber(value);
}
// If type is undefined, but an enum is present, try and infer the type from
// the enum values
if (schema.enum) {
if (schema.enum.every((x: any) => guessType(x) === 'number')) {
return asNumber(value);
} else if (schema.enum.every((x: any) => guessType(x) === 'boolean')) {
return value === 'true';
}
}
return value;
};
const processValue = (schema: any, value: any) => {
// "enum" is a reserved word, so only "type" and "items" can be destructured
const { type, items } = schema;
if (value === '') {
return undefined;
} else if (type === 'array' && items && nums.has(items.type)) {
return value.map(asNumber);
} else if (type === 'boolean') {
return value === 'true';
} else if (type === 'number') {
return asNumber(value);
}
// If type is undefined, but an enum is present, try and infer the type from
// the enum values
if (schema.enum) {
if (schema.enum.every((x: any) => guessType(x) === 'number')) {
return asNumber(value);
} else if (schema.enum.every((x: any) => guessType(x) === 'boolean')) {
return value === 'true';
}
}
return value;
};
function processValue({type, items}, value) {
if (type === 'array' && items && ['number', 'integer'].includes(items.type)) {
return value.map(asNumber);
} else if (type === 'boolean') {
return value === 'true';
} else if (type === 'number') {
return asNumber(value);
}
return value;
}
onInputChange = event => {
const errors = [];
const {type} = this.props.schema;
let value = event.target.value;
if (this.props.required && !value) {
errors.push({
message: 'required'
});
}
if (type.includes('number') || type.includes('integer')) {
const dialogSchema = cloneDeepWith(this.props.schema);
value = (value === '' && dialogSchema.nullable) ? null : asNumber(value);
if (dialogSchema.nullable) {
dialogSchema.type = [dialogSchema.type, 'null'];
}
validator.validate(dialogSchema, value);
} else {
validator.validate(this.props.schema, value);
}
if (validator.errors) {
errors.push(...validator.errors);
}
this.setState({errors});
this.props.onChange(value);