UNPKG

993 BJavaScriptView Raw
1'use strict';
2
3var _ = require('lodash');
4var Promise = require('bluebird');
5
6var Formats = require('./lib/formats.js');
7var Util = require('./lib/util.js');
8
9var Converter = module.exports = {};
10Converter.Formats = Formats;
11Converter.BaseFormat = require('./lib/base_format.js');
12Converter.ResourceReaders = Util.resourceReaders;
13
14Converter.getSpec = function (source, format, callback) {
15 var spec = new Formats[format]();
16 return spec.resolveResources(source)
17 .return(spec)
18 .asCallback(callback);
19}
20
21Converter.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
31Converter.convert = function(options, callback) {
32 return Converter.getSpec(options.source, options.from)
33 .then(fromSpec => fromSpec.convertTo(options.to))
34 .asCallback(callback);
35}