1 | 'use strict';
|
2 |
|
3 | var _ = require('lodash');
|
4 | var Promise = require('bluebird');
|
5 |
|
6 | var Formats = require('./lib/formats.js');
|
7 | var Util = require('./lib/util.js');
|
8 |
|
9 | var Converter = module.exports = {};
|
10 | Converter.Formats = Formats;
|
11 | Converter.BaseFormat = require('./lib/base_format.js');
|
12 | Converter.ResourceReaders = Util.resourceReaders;
|
13 |
|
14 | Converter.getSpec = function (source, format, callback) {
|
15 | var spec = new Formats[format]();
|
16 | return spec.resolveResources(source)
|
17 | .return(spec)
|
18 | .asCallback(callback);
|
19 | }
|
20 |
|
21 | Converter.getFormatName = function (name, version) {
|
22 | var result;
|
23 | _.each(Formats, function (format, formatName) {
|
24 | format = format.prototype;
|
25 | if (format.formatName === name && format.supportedVersions.indexOf(version) !== -1)
|
26 | result = formatName;
|
27 | });
|
28 | return result;
|
29 | };
|
30 |
|
31 | Converter.convert = function(options, callback) {
|
32 | return Converter.getSpec(options.source, options.from)
|
33 | .then(fromSpec => fromSpec.convertTo(options.to))
|
34 | .asCallback(callback);
|
35 | }
|