Created
September 12, 2014 00:16
-
-
Save Nate-Wilkins/7a0c4d74f88846e75fc6 to your computer and use it in GitHub Desktop.
strlen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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