convert.js 628 B

1234567891011121314151617181920
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  3. var _parseInt2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/parse-int"));
  4. function fromDecimalToHex(number) {
  5. if (typeof number !== 'number') throw 'The input provided should be a number';
  6. return "0x".concat(number.toString(16));
  7. }
  8. function fromHexToDecimal(hex) {
  9. if (typeof hex !== 'string') throw 'The input provided should be a string';
  10. return (0, _parseInt2.default)(hex, 16);
  11. }
  12. module.exports = {
  13. fromDecimalToHex: fromDecimalToHex,
  14. fromHexToDecimal: fromHexToDecimal
  15. };