Thomas Grainger 640f555b8a
fix eslint:recommended errors
this should find most of the imports
2016-11-29 18:36:38 +00:00

55 lines
1.0 KiB
JavaScript
Executable File

/**
* Numerical base operations.
*
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*
* @namespace
*/
const Base = {
/**
* @constant
* @default
*/
DEFAULT_RADIX: 36,
/**
* To Base operation.
*
* @param {number} input
* @param {Object[]} args
* @returns {string}
*/
run_to(input, args) {
if (!input) {
throw ('Error: Input must be a number');
}
const radix = args[0] || Base.DEFAULT_RADIX;
if (radix < 2 || radix > 36) {
throw 'Error: Radix argument must be between 2 and 36';
}
return input.toString(radix);
},
/**
* From Base operation.
*
* @param {string} input
* @param {Object[]} args
* @returns {number}
*/
run_from(input, args) {
const radix = args[0] || Base.DEFAULT_RADIX;
if (radix < 2 || radix > 36) {
throw 'Error: Radix argument must be between 2 and 36';
}
return parseInt(input.replace(/\s/g, ''), radix);
},
};
export default Base;