16902aac36109b3b1e37172aa1120ccf4797ac1525ab357a590aba1b455a02526a865fd55cdd5fe3a096f98cc02d7ce20cafd381d8a0a545f53b0041f144fa 818 B

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