21 lines
629 B
JavaScript
21 lines
629 B
JavaScript
|
"use strict";
|
||
|
var BinToDecConverter = (function () {
|
||
|
function BinToDecConverter() {
|
||
|
}
|
||
|
BinToDecConverter.prototype.getDisplayname = function () {
|
||
|
return "Convert binary to decimal";
|
||
|
};
|
||
|
BinToDecConverter.prototype.getId = function () {
|
||
|
return "bintodec";
|
||
|
};
|
||
|
BinToDecConverter.prototype.convert = function (input) {
|
||
|
var n = parseInt(input, 2);
|
||
|
if (isNaN(n)) {
|
||
|
throw new Error("The input seems not to be a valid binary number.");
|
||
|
}
|
||
|
return n.toString(10);
|
||
|
};
|
||
|
return BinToDecConverter;
|
||
|
}());
|
||
|
exports.BinToDecConverter = BinToDecConverter;
|