13 module.exports = function defFunc(ajv) {
14 /* istanbul ignore else */
15 if (typeof Buffer != 'undefined')
16 CONSTRUCTORS.Buffer = Buffer;
18 /* istanbul ignore else */
19 if (typeof Promise != 'undefined')
20 CONSTRUCTORS.Promise = Promise;
22 defFunc.definition = {
23 compile: function (schema) {
24 if (typeof schema == 'string') {
25 var Constructor = getConstructor(schema);
26 return function (data) {
27 return data instanceof Constructor;
31 var constructors = schema.map(getConstructor);
32 return function (data) {
33 for (var i=0; i<constructors.length; i++)
34 if (data instanceof constructors[i]) return true;
38 CONSTRUCTORS: CONSTRUCTORS,
44 items: { type: 'string' }
50 ajv.addKeyword('instanceof', defFunc.definition);
53 function getConstructor(c) {
54 var Constructor = CONSTRUCTORS[c];
55 if (Constructor) return Constructor;
56 throw new Error('invalid "instanceof" keyword value ' + c);