3 module.exports = function defFunc(ajv) {
6 inline: function (it, keyword, schema) {
7 return getRegExp() + '.test(data' + (it.dataLevel || '') + ')';
11 if (typeof schema == 'object')
12 return new RegExp(schema.pattern, schema.flags);
14 var rx = schema.match(/^\/(.*)\/([gimuy]*)$/);
15 if (rx) return new RegExp(rx[1], rx[2]);
16 throw new Error('cannot parse string into RegExp');
18 console.error('regular expression', schema, 'is invalid');
24 type: ['string', 'object'],
26 pattern: { type: 'string' },
27 flags: { type: 'string' }
29 required: ['pattern'],
30 additionalProperties: false
34 ajv.addKeyword('regexp', defFunc.definition);