2
2
const sliceAnsi = require ( 'slice-ansi' ) ;
3
3
const stringWidth = require ( 'string-width' ) ;
4
4
5
- module . exports = ( input , columns , options ) => {
5
+ module . exports = ( text , columns , options ) => {
6
6
options = {
7
7
position : 'end' ,
8
8
...options
@@ -11,8 +11,8 @@ module.exports = (input, columns, options) => {
11
11
const { position} = options ;
12
12
const ellipsis = '…' ;
13
13
14
- if ( typeof input !== 'string' ) {
15
- throw new TypeError ( `Expected \`input\` to be a string, got ${ typeof input } ` ) ;
14
+ if ( typeof text !== 'string' ) {
15
+ throw new TypeError ( `Expected \`input\` to be a string, got ${ typeof text } ` ) ;
16
16
}
17
17
18
18
if ( typeof columns !== 'number' ) {
@@ -27,23 +27,23 @@ module.exports = (input, columns, options) => {
27
27
return ellipsis ;
28
28
}
29
29
30
- const length = stringWidth ( input ) ;
30
+ const length = stringWidth ( text ) ;
31
31
32
32
if ( length <= columns ) {
33
- return input ;
33
+ return text ;
34
34
}
35
35
36
36
if ( position === 'start' ) {
37
- return ellipsis + sliceAnsi ( input , length - columns + 1 , length ) ;
37
+ return ellipsis + sliceAnsi ( text , length - columns + 1 , length ) ;
38
38
}
39
39
40
40
if ( position === 'middle' ) {
41
41
const half = Math . floor ( columns / 2 ) ;
42
- return sliceAnsi ( input , 0 , half ) + ellipsis + sliceAnsi ( input , length - ( columns - half ) + 1 , length ) ;
42
+ return sliceAnsi ( text , 0 , half ) + ellipsis + sliceAnsi ( text , length - ( columns - half ) + 1 , length ) ;
43
43
}
44
44
45
45
if ( position === 'end' ) {
46
- return sliceAnsi ( input , 0 , columns - 1 ) + ellipsis ;
46
+ return sliceAnsi ( text , 0 , columns - 1 ) + ellipsis ;
47
47
}
48
48
49
49
throw new Error ( `Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${ position } ` ) ;
0 commit comments