ajv_instances.js 720 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. var Ajv = require('./ajv');
  3. module.exports = getAjvInstances;
  4. function getAjvInstances(options, extraOpts) {
  5. return _getAjvInstances(options, extraOpts || {});
  6. }
  7. function _getAjvInstances(opts, useOpts) {
  8. var optNames = Object.keys(opts);
  9. if (optNames.length) {
  10. opts = copy(opts);
  11. var useOpts1 = copy(useOpts)
  12. , optName = optNames[0];
  13. useOpts1[optName] = opts[optName];
  14. delete opts[optName];
  15. var instances = _getAjvInstances(opts, useOpts)
  16. , instances1 = _getAjvInstances(opts, useOpts1);
  17. return instances.concat(instances1);
  18. }
  19. return [ new Ajv(useOpts) ];
  20. }
  21. function copy(o, to) {
  22. to = to || {};
  23. for (var key in o) to[key] = o[key];
  24. return to;
  25. }