22const sliceAnsi = require ( 'slice-ansi' ) ;
33const stringWidth = require ( 'string-width' ) ;
44
5- module . exports = ( input , columns , options ) => {
5+ module . exports = ( text , columns , options ) => {
66 options = {
77 position : 'end' ,
88 ...options
@@ -11,8 +11,8 @@ module.exports = (input, columns, options) => {
1111 const { position} = options ;
1212 const ellipsis = '…' ;
1313
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 } ` ) ;
1616 }
1717
1818 if ( typeof columns !== 'number' ) {
@@ -27,23 +27,23 @@ module.exports = (input, columns, options) => {
2727 return ellipsis ;
2828 }
2929
30- const length = stringWidth ( input ) ;
30+ const length = stringWidth ( text ) ;
3131
3232 if ( length <= columns ) {
33- return input ;
33+ return text ;
3434 }
3535
3636 if ( position === 'start' ) {
37- return ellipsis + sliceAnsi ( input , length - columns + 1 , length ) ;
37+ return ellipsis + sliceAnsi ( text , length - columns + 1 , length ) ;
3838 }
3939
4040 if ( position === 'middle' ) {
4141 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 ) ;
4343 }
4444
4545 if ( position === 'end' ) {
46- return sliceAnsi ( input , 0 , columns - 1 ) + ellipsis ;
46+ return sliceAnsi ( text , 0 , columns - 1 ) + ellipsis ;
4747 }
4848
4949 throw new Error ( `Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${ position } ` ) ;
0 commit comments