How to use the validate function from tv4
Find comprehensive JavaScript tv4.validate code examples handpicked from public code repositorys.
946 947 948 949 950 951 952 953 954 955
const data = fs.readFileSync(file, "utf8"); if (configRe.test(data)) { const config = data.replace(configRe, "$1"); t.true( // @ts-ignore tv4.validate(JSON.parse(config), configSchemaStrict), file + "\n" + JSON.stringify(tv4.error, null, 2)); } } });
612
0
56
+ 389 other calls in file
930 931 932 933 934 935 936 937 938 939
// eslint-disable-next-line unicorn/prefer-json-parse-buffer "utf8" ); t.true( // @ts-ignore tv4.validate(JSON.parse(data), configSchemaStrict), file + "\n" + JSON.stringify(tv4.error, null, 2)); } });
611
0
55
+ 191 other calls in file
GitHub: delfrrr/tv4
309 310 311 312 313 314 315 316 317
}; var data1 = [true, false]; var data2 = [true, 123]; alert("data 1: " + tv4.validate(data1, schema)); // true alert("data 2: " + tv4.validate(data2, schema)); // false alert("data 2 error: " + JSON.stringify(tv4.error, null, 4)); </pre> </div>
190
0
2
+ 31 other calls in file
6 7 8 9 10 11 12 13 14
There is support for `$ref` with JSON Pointer fragment paths (```other-schema.json#/properties/myKey```). ## Usage 1: Simple validation ```javascript var valid = tv4.validate(data, schema); ``` If validation returns ```false```, then an explanation of why validation failed can be found in ```tv4.error```.
190
0
13
+ 15 other calls in file
GitHub: jbarabander/tiny-mongo
30 31 32 33 34 35 36 37 38 39
return collection[method].apply(collection, args) }) } validate (doc) { return tv4.validate(doc, this.schema) } giveCursorBack (method, args) { return new Cursor(this._collectionPromise, method, args)
0
4
2
tv4.validate is the most popular function in tv4 (982 examples)