hex.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createHex = void 0;
  6. var _factory = require("../../utils/factory.js");
  7. var name = 'hex';
  8. var dependencies = ['typed', 'format'];
  9. /**
  10. * Format a number as hexadecimal.
  11. *
  12. * Syntax:
  13. *
  14. * math.hex(value)
  15. *
  16. * Examples:
  17. *
  18. * math.hex(240) // returns "0xF0"
  19. *
  20. * See also:
  21. *
  22. * oct
  23. * bin
  24. *
  25. * @param {number} value Value to be stringified
  26. * @param {number} wordSize Optional word size (see `format`)
  27. * @return {string} The formatted value
  28. */
  29. var createHex = (0, _factory.factory)(name, dependencies, function (_ref) {
  30. var typed = _ref.typed,
  31. format = _ref.format;
  32. return typed(name, {
  33. 'number | BigNumber': function numberBigNumber(n) {
  34. return format(n, {
  35. notation: 'hex'
  36. });
  37. },
  38. 'number | BigNumber, number': function numberBigNumberNumber(n, wordSize) {
  39. return format(n, {
  40. notation: 'hex',
  41. wordSize: wordSize
  42. });
  43. }
  44. });
  45. });
  46. exports.createHex = createHex;