lib/util.js
function indexOfWidth(stringWidth, str, width) {
	if (stringWidth === false)
		return width;
	for (var i = 0; i <= str.length; i++) {
		if (getWidth(stringWidth, str.substr(0, i)) > width)
			return i - 1;
	}
	return str.length;
}
function indexOfWidth(stringWidth, str, width) {
	if (stringWidth === false)
		return width;
	for (var i = 0; i <= str.length; i++) {
		if (getWidth(stringWidth, str.substr(0, i)) > width)
			return i - 1;
	}
	return str.length;
}
function indexOfWidth ( stringWidth , str , width ) { if ( stringWidth === false ) return width ; for ( var i = 0 ; i <= str . length ; i ++ ) { if ( getWidth ( stringWidth , str . substr ( 0 , i ) ) > width ) return i - 1 ; } return str . length ; }
calculate the position that the prefix of string is a specific width
@params {string} str - string to calculate
@params {number} width - the width of target string
@params {boolean} stringWidth - calculate width by wcwidth or String.length
calculate the position that the prefix of string is a specific width