Lines Matching refs:str
6 * repeat string `str` up to total length of `len`
8 * @param String str string to repeat
12 function repeatString(str, len) {
13 return Array.apply(null, {length: len + 1}).join(str).slice(0, len)
17 * Pad `str` up to total length `max` with `chr`.
18 * If `str` is longer than `max`, padRight will return `str` unaltered.
20 * @param String str string to pad
23 * @return String padded str
26 function padRight(str, max, chr) {
27 str = str != null ? str : ''
28 str = String(str)
29 var length = max - wcwidth(str)
30 if (length <= 0) return str
31 return str + repeatString(chr || ' ', length)
35 * Pad `str` up to total length `max` with `chr`.
36 * If `str` is longer than `max`, padCenter will return `str` unaltered.
38 * @param String str string to pad
41 * @return String padded str
44 function padCenter(str, max, chr) {
45 str = str != null ? str : ''
46 str = String(str)
47 var length = max - wcwidth(str)
48 if (length <= 0) return str
51 return repeatString(chr || ' ', lengthLeft) + str + repeatString(chr || ' ', lengthRight)
55 * Pad `str` up to total length `max` with `chr`, on the left.
56 * If `str` is longer than `max`, padRight will return `str` unaltered.
58 * @param String str string to pad
61 * @return String padded str
64 function padLeft(str, max, chr) {
65 str = str != null ? str : ''
66 str = String(str)
67 var length = max - wcwidth(str)
68 if (length <= 0) return str
69 return repeatString(chr || ' ', length) + str
73 * Split a String `str` into lines of maxiumum length `max`.
76 * @param String str string to split
81 function splitIntoLines(str, max) {
82 function _splitIntoLines(str, max) {
83 return str.trim().split(' ').reduce(function(lines, word) {
94 return str.split('\n').map(function(str) {
95 return _splitIntoLines(str, max)
103 * `str` which are longer than `max`.
105 * @param String str string to split
111 function splitLongWords(str, max, truncationChar) {
112 str = str.trim()
114 var words = str.split(' ')
155 * Truncate `str` into total width `max`
156 * If `str` is shorter than `max`, will return `str` unaltered.
158 * @param String str string to truncated
160 * @return String truncated str
163 function truncateString(str, max) {
165 str = str != null ? str : ''
166 str = String(str)
168 if(max == Infinity) return str
172 while (i < str.length) {
173 var w = wcwidth(str.charAt(i))
179 return str.slice(0, i)