name.js
function _decodeName (name) {
  var encoded = name;
  var periodIndex = name.indexOf('.');
  if (periodIndex > -1) {
    encoded = name.slice(0, periodIndex);
  }

  var decoded = '';
  var suffix = 0;
  var charValue = 0;;

  for (var i = 0, n = encoded.length; i < n; ++i) {

    // decode char to first nibble
    if (i % 2 === 0) {
      charValue = (encoded.charCodeAt(i) - 'A'.charCodeAt(0)) << 4;

    // decore char to second nibble and then combine with first nibble
    } else {
      charValue += encoded.charCodeAt(i) - 'A'.charCodeAt(0);

      // Append the newly decoded character for the first 15 bytes
      if (i < (encoded.length - 1)) {
        decoded += String.fromCharCode(charValue);

      // The last byte is reserved by convention as the suffix or type
      } else {
        suffix = charValue;
      }
    }
  }

  // NetBIOS names are always space padded out to 15 characters
  decoded = decoded.trim();

  // If there was a scope identifier (domain name) after the NetBIOS name
  // then re-append it to the newly decoded name.
  if (periodIndex > -1) {
    decoded += name.slice(periodIndex);
  }

  return {fqdn: decoded, suffix: suffix};
}
function _decodeName (name) {
  var encoded = name;
  var periodIndex = name.indexOf('.');
  if (periodIndex > -1) {
    encoded = name.slice(0, periodIndex);
  }

  var decoded = '';
  var suffix = 0;
  var charValue = 0;;

  for (var i = 0, n = encoded.length; i < n; ++i) {

    // decode char to first nibble
    if (i % 2 === 0) {
      charValue = (encoded.charCodeAt(i) - 'A'.charCodeAt(0)) << 4;

    // decore char to second nibble and then combine with first nibble
    } else {
      charValue += encoded.charCodeAt(i) - 'A'.charCodeAt(0);

      // Append the newly decoded character for the first 15 bytes
      if (i < (encoded.length - 1)) {
        decoded += String.fromCharCode(charValue);

      // The last byte is reserved by convention as the suffix or type
      } else {
        suffix = charValue;
      }
    }
  }

  // NetBIOS names are always space padded out to 15 characters
  decoded = decoded.trim();

  // If there was a scope identifier (domain name) after the NetBIOS name
  // then re-append it to the newly decoded name.
  if (periodIndex > -1) {
    decoded += name.slice(periodIndex);
  }

  return {fqdn: decoded, suffix: suffix};
}
function _decodeName ( name ) { var encoded = name ; var periodIndex = name . indexOf ( '.' ) ; if ( periodIndex > - 1 ) { encoded = name . slice ( 0 , periodIndex ) ; } var decoded = '' ; var suffix = 0 ; var charValue = 0 ; ; for ( var i = 0 , n = encoded . length ; i < n ; ++ i ) { // decode char to first nibble if ( i % 2 === 0 ) { charValue = ( encoded . charCodeAt ( i ) - 'A' . charCodeAt ( 0 ) ) << 4 ; // decore char to second nibble and then combine with first nibble } else { charValue += encoded . charCodeAt ( i ) - 'A' . charCodeAt ( 0 ) ; // Append the newly decoded character for the first 15 bytes if ( i < ( encoded . length - 1 ) ) { decoded += String . fromCharCode ( charValue ) ; // The last byte is reserved by convention as the suffix or type } else { suffix = charValue ; } } } // NetBIOS names are always space padded out to 15 characters decoded = decoded . trim ( ) ; // If there was a scope identifier (domain name) after the NetBIOS name // then re-append it to the newly decoded name. if ( periodIndex > - 1 ) { decoded += name . slice ( periodIndex ) ; } return { fqdn : decoded , suffix : suffix } ; }
Decode the NetBIOS name after it has been decompressed.  The NetBIOS name is represented as the first part of the FQDN.  See page 26 of RFC 1001 for full details on the encoding algorithm.  In short, each byte of the original NetBIOS name is split into two nibbles.  Each nibble is then encoded as a separate byte by adding the ASCII value for 'A'.  In order to decode we therefore must reverse this logic.
Decode the NetBIOS name after it has been decompressed . The NetBIOS name is represented as the first part of the FQDN . See page 26 of RFC 1001 for full details on the encoding algorithm . In short each byte of the original NetBIOS name is split into two nibbles . Each nibble is then encoded as a separate byte by adding the ASCII value for A . In order to decode we therefore must reverse this logic .