Projekt

Obecné

Profil

Stáhnout (818 Bajtů) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
var KNOWN_TYPES = ['undefined', 'string', 'number', 'object', 'function', 'boolean', 'symbol'];
4

    
5
module.exports = function defFunc(ajv) {
6
  defFunc.definition = {
7
    inline: function (it, keyword, schema) {
8
      var data = 'data' + (it.dataLevel || '');
9
      if (typeof schema == 'string') return 'typeof ' + data + ' == "' + schema + '"';
10
      schema = 'validate.schema' + it.schemaPath + '.' + keyword;
11
      return schema + '.indexOf(typeof ' + data + ') >= 0';
12
    },
13
    metaSchema: {
14
      anyOf: [
15
        {
16
          type: 'string',
17
          enum: KNOWN_TYPES
18
        },
19
        {
20
          type: 'array',
21
          items: {
22
            type: 'string',
23
            enum: KNOWN_TYPES
24
          }
25
        }
26
      ]
27
    }
28
  };
29

    
30
  ajv.addKeyword('typeof', defFunc.definition);
31
  return ajv;
32
};
(20-20/21)