src/hexdump.js
function Hexdump(data, options) {
    var self = this;
    self.hexdump = [];
    self.hex = false;
    self.options = {
        container: options.container || ''
      , width: options.width || 16
      , byteGrouping: options.byteGrouping || 0
      , ascii: options.ascii
      , lineNumber: options.lineNumber
      , endian: options.endian || 'big'
      , html: options.html
      , base: options.base || 'hexadecimal'
      , nonPrintable: options.nonPrintable || '.'
      , style: {
          lineNumberLeft: options.style.lineNumberLeft || ''
        , lineNumberRight: options.style.lineNumberRight || ':'
        , stringLeft: options.style.stringLeft || '|'
        , stringRight: options.style.stringRight || '|'
        , hexLeft: options.style.hexLeft || ''
        , hexRight: options.style.hexRight || ''
        , hexNull: options.style.hexNull || '.'
        , stringNull: options.style.stringNull || ' '
      }
    };

    if (self.options.base == 'hex') {
      self.hex = true;
    } else if (self.options.base == 'hexadecimal') {
      self.hex = true;
    };

    // Check for the line number option and turn it off 
    // if not set unless it has been explicitly turned
    // off by the user.
    var ln = self.options.lineNumber;
    if (typeof ln == "undefined" || ln == null) {
      self.options.lineNumber = true;
    };

    var askey = self.options.ascii;
    if (typeof askey == "undefined" || askey == null) {
      self.options.ascii = false;
    };

    
    var html = self.options.html;
    if (typeof html == "undefined" || html == null) {
      self.options.html = true;
    };
    
    if (self.endian != ('little' || 'big')) {
      self.endian = 'big';
    };

    // Make sure spacing is within proper range.
    if (self.options.byteGrouping > data.length) {
      self.options.byteGrouping = data.length;
    };
    self.options.byteGrouping--;

    // Make sure width is within proper range.
    if (self.options.width > data.length) {
      self.options.width = data.length;
    };
    
    // Base padding
    self.padding = {
      hex: 4,
      dec: 5,
      bin: 8
    };
    
    // Base conversion logic
    switch(self.options.base) {
      case 'hexadecimal': case 'hex': case 16:
        self.setNullPadding(self.padding.hex);
        self.baseConvert = function(characters) {
          
          for (var i=0; i < characters.length; i++) {
            return self.addPadding(characters[i].charCodeAt(0).toString(16), self.padding.hex);
          };

        }; break;
      case 'decimal': case 'dec': case 10:
        self.setNullPadding(self.padding.dec);
        self.baseConvert = function(characters) {
          
          for (var i=0; i < characters.length; i++) {
            return self.addPadding(characters[i].charCodeAt(0), self.padding.dec);
          };

        }; break;
      case 'binary': case 'bin': case 2:
        self.setNullPadding(self.padding.bin);
        self.baseConvert = function(characters) {
          for (var i=0; i < characters.length; i++) {
            var ddx = characters[i].charCodeAt(0), r = "";
            
            for (var bbx = 0; bbx < 8; bbx++) { 
              r = (ddx%2) + r; ddx = Math.floor(ddx/2);
            };

            return self.addPadding(r, self.padding.bin);
          };
        }; break;
      default:
        self.options.base = 'hex';
        self.hex = true;

        self.setNullPadding(self.padding.hex);
        self.baseConvert = function(characters) {

          for (var i=0; i < characters.length; i++) {
            return self.addPadding(characters[i].charCodeAt(0).toString(16), self.padding.hex);
          };

      };
    };
    
    var regex = new RegExp('.{1,' + this.options.width + '}', 'g');

    self.data = data.match(regex);
    
    self.nullCount = (self.options.width - self.data[self.data.length - 1].length);
    
    self.hexCounter = 0;
    
    self.stringCounter = 0;
    
    for (var i=0; i < self.data.length; i++) {
      var tempData = self.process(self.data[i]);
      
      self.hexdump.push({
        data: tempData.data,
        string: tempData.string,
        length: self.data[i].length,
        missing: (self.options.width - self.data[i].length)
      });
    };
    
    self.dump();
  }
function Hexdump(data, options) {
    var self = this;
    self.hexdump = [];
    self.hex = false;
    self.options = {
        container: options.container || ''
      , width: options.width || 16
      , byteGrouping: options.byteGrouping || 0
      , ascii: options.ascii
      , lineNumber: options.lineNumber
      , endian: options.endian || 'big'
      , html: options.html
      , base: options.base || 'hexadecimal'
      , nonPrintable: options.nonPrintable || '.'
      , style: {
          lineNumberLeft: options.style.lineNumberLeft || ''
        , lineNumberRight: options.style.lineNumberRight || ':'
        , stringLeft: options.style.stringLeft || '|'
        , stringRight: options.style.stringRight || '|'
        , hexLeft: options.style.hexLeft || ''
        , hexRight: options.style.hexRight || ''
        , hexNull: options.style.hexNull || '.'
        , stringNull: options.style.stringNull || ' '
      }
    };

    if (self.options.base == 'hex') {
      self.hex = true;
    } else if (self.options.base == 'hexadecimal') {
      self.hex = true;
    };

    // Check for the line number option and turn it off 
    // if not set unless it has been explicitly turned
    // off by the user.
    var ln = self.options.lineNumber;
    if (typeof ln == "undefined" || ln == null) {
      self.options.lineNumber = true;
    };

    var askey = self.options.ascii;
    if (typeof askey == "undefined" || askey == null) {
      self.options.ascii = false;
    };

    
    var html = self.options.html;
    if (typeof html == "undefined" || html == null) {
      self.options.html = true;
    };
    
    if (self.endian != ('little' || 'big')) {
      self.endian = 'big';
    };

    // Make sure spacing is within proper range.
    if (self.options.byteGrouping > data.length) {
      self.options.byteGrouping = data.length;
    };
    self.options.byteGrouping--;

    // Make sure width is within proper range.
    if (self.options.width > data.length) {
      self.options.width = data.length;
    };
    
    // Base padding
    self.padding = {
      hex: 4,
      dec: 5,
      bin: 8
    };
    
    // Base conversion logic
    switch(self.options.base) {
      case 'hexadecimal': case 'hex': case 16:
        self.setNullPadding(self.padding.hex);
        self.baseConvert = function(characters) {
          
          for (var i=0; i < characters.length; i++) {
            return self.addPadding(characters[i].charCodeAt(0).toString(16), self.padding.hex);
          };

        }; break;
      case 'decimal': case 'dec': case 10:
        self.setNullPadding(self.padding.dec);
        self.baseConvert = function(characters) {
          
          for (var i=0; i < characters.length; i++) {
            return self.addPadding(characters[i].charCodeAt(0), self.padding.dec);
          };

        }; break;
      case 'binary': case 'bin': case 2:
        self.setNullPadding(self.padding.bin);
        self.baseConvert = function(characters) {
          for (var i=0; i < characters.length; i++) {
            var ddx = characters[i].charCodeAt(0), r = "";
            
            for (var bbx = 0; bbx < 8; bbx++) { 
              r = (ddx%2) + r; ddx = Math.floor(ddx/2);
            };

            return self.addPadding(r, self.padding.bin);
          };
        }; break;
      default:
        self.options.base = 'hex';
        self.hex = true;

        self.setNullPadding(self.padding.hex);
        self.baseConvert = function(characters) {

          for (var i=0; i < characters.length; i++) {
            return self.addPadding(characters[i].charCodeAt(0).toString(16), self.padding.hex);
          };

      };
    };
    
    var regex = new RegExp('.{1,' + this.options.width + '}', 'g');

    self.data = data.match(regex);
    
    self.nullCount = (self.options.width - self.data[self.data.length - 1].length);
    
    self.hexCounter = 0;
    
    self.stringCounter = 0;
    
    for (var i=0; i < self.data.length; i++) {
      var tempData = self.process(self.data[i]);
      
      self.hexdump.push({
        data: tempData.data,
        string: tempData.string,
        length: self.data[i].length,
        missing: (self.options.width - self.data[i].length)
      });
    };
    
    self.dump();
  }
Hexdump Initializer data => The string payload. options => hexdump configurations