function strlen(str) {
  // Call the native functions if there's no surrogate char
  if (!hasSurrogateUnit(str)) {
    return str.length;
  }

  let len = 0;
  for (let pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
    len++;
  }
  return len;
}
Fully Unicode-enabled replacement for String#length

@param {string} str  Valid Unicode string
@return {number}     The number of Unicode characters in the string