Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save JavaScript-Packer/1fcc4323d93837728ad6 to your computer and use it in GitHub Desktop.

Select an option

Save JavaScript-Packer/1fcc4323d93837728ad6 to your computer and use it in GitHub Desktop.
Pass any string of characters (binary, ascii, Chinese, etc) and it will return the bytes (formatted like 1,000,000) of characters (not just the character count, some characters are more than one byte). Used on http://www.whak.ca/packer/JavaScript.htm
function bytez(n) {
return n = unescape(encodeURI(n)).length, ("" + n).split(/(?=(?:\d{3})+(?:\.|$))/g).join(",");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment