changed to new input format, updated plugintest

This commit is contained in:
pavanteja-potnuru
2018-08-22 11:45:57 +05:30
parent 1a1461fce8
commit 81cc971cc5
6 changed files with 1178 additions and 188 deletions

View File

@@ -1,5 +1,55 @@
// Exports the interface for the plugin
var convert = require('./lib/convert.js'),
fs = require('fs'),
validate = require('./lib/validate.js');
module.exports = {
convert: require('./lib/convert.js'),
validate: require('./lib/validate.js')
convert: function(input, options, cb) {
try {
var data;
if (input.type === 'string') {
return convert(input.data, cb);
}
else if (input.type === 'json') {
return convert(input.data, cb);
}
else if (input.type === 'file') {
data = fs.readFileSync(input.data).toString();
return convert(data, cb);
}
return cb(null, {
result: false,
reason: 'input type is not valid'
});
}
catch (e) {
return cb(e);
}
},
validate: function(input) {
try {
var data;
if (input.type === 'string') {
return validate(input.data);
}
else if (input.type === 'json') {
return validate(input.data);
}
else if (input.type === 'file') {
data = fs.readFileSync(input.data).toString();
return validate(data);
}
return {
result: false,
reason: 'input type is not valid'
};
}
catch (e) {
return {
result: false,
reason: e.toString()
};
}
}
};