Skip to content

Instantly share code, notes, and snippets.

@Nate-Wilkins
Created September 12, 2014 00:16
Show Gist options
  • Save Nate-Wilkins/7a0c4d74f88846e75fc6 to your computer and use it in GitHub Desktop.
Save Nate-Wilkins/7a0c4d74f88846e75fc6 to your computer and use it in GitHub Desktop.
strlen
// https://github.com/Automattic/cli-table/blob/db9f235d50680d7bdcdd0e42f1c85ab1de273ed1/lib/cli-table/utils.js#L79
// Strip unicode color data and get the underlying string length
exports.strlen = function(str){
var code = /\u001b\[(?:\d*;){0,5}\d*m/g;
var stripped = ("" + str).replace(code,'');
var split = stripped.split("\n");
return split.reduce(function (memo, s) { return (s.length > memo) ? s.length : memo }, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment