Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function validateProps(props, schema) {
const { children, ...itemProps } = props || {}; // TODO add child count validation too?
const { error } = tv4.validateResult(itemProps, schema, false, true);
if (error) {
const { dataPath, srcPath, message } = error;
if (dataPath) {
throw new Error(`Unknown property: ${dataPath.slice(1)}`);
}
if (srcPath) {
throw new Error(`Invalid value for property ${srcPath.slice(1)}: ${message}`);
}
throw new Error(message);
}
return itemProps;
validate: function(object) {
var schema = BaseClient.Types.getSchema(object['@context']);
if (schema) {
return tv4.validateResult(object, schema);
} else {
throw new SchemaNotFound(object['@context']);
}
},
.time(function () {
Tv4.validateResult({firstName: 'John', lastName: 'Doe', age: 45, tags: ['man', 'human']}, schema);
});
function assertValid(code, done) {
var result = tv4.validateResult(JSON.parse(JSON.stringify(esprima.parse(code), adjustRegexLiteral)), esschema);
assert(result.valid);
done();
}
describe('(function(){ var x = 1, y = 2, z = 3 })', function () {
_validateBySchema(entry, options) {
const schema = getSchema(
{
type: { enum: ['reference'] },
value: { type: 'string', minLength: 1 },
},
options
)
return tv4.validateResult(entry, schema)
}
_validateBySchema(model, options) {
const schema = getBasicSchema(options)
Object.assign(schema.properties, {
type: { enum: ['string-line', 'string-multiline', 'string-html', 'string-markdown'] },
default: { type: 'string', minLength: 1 },
minLength: { type: 'integer', minimum: 0 },
maxLength: { type: 'integer', minimum: 0 },
pattern: { type: 'string', minLength: 1 },
})
return tv4.validateResult(model, schema)
}
}
const _foo = {};
_foo[key] = defaultConfig[key];
const _tempMerged = extend(true, _foo, clone(finalConfig));
const result = tv4.validateResult(_tempMerged, schema);
if (result.valid) {
finalConfig = _tempMerged;
}
}
} else {
finalConfig = extend(true, defaultConfig, userConfig);
}
const result = tv4.validateResult(finalConfig, schema);
if (result.valid) {
return finalConfig;
}
throw new Error(`Config for bundle "${bundle.name}" is invalid:\n` +
`${result.error.message} at ${result.error.dataPath}`);
};
function validateBySchema(schema: any, value: any): SchemaValidationResult {
return tv.validateResult(value, schema);
}
_validateBySchema(model, options) {
const schema = getBasicSchema(options)
schema.required.push('additionalProperties', 'required', 'properties')
Object.assign(schema.properties, {
type: { enum: ['object'] },
additionalProperties: { enum: [false] },
required: { type: 'array', uniqueItems: true, items: { type: 'string', minLength: 1 } },
properties: { type: 'object' },
})
return tv4.validateResult(model, schema)
}
_validate(model, options) {
const schema = getBasicSchema(options)
schema.required.push('default')
Object.assign(schema.properties, {
type: { enum: ['boolean'] },
default: { type: 'boolean' },
})
return tv4.validateResult(model, schema)
}
}