Skip to content

Commit 21df450

Browse files
committedApr 11, 2019
Meta tweaks
1 parent 1c65dfa commit 21df450

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed
 

‎index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare namespace cliTruncate {
1212
/**
1313
Truncate a string to a specific width in the terminal.
1414
15-
@param input - Text to truncate.
15+
@param text - Text to truncate.
1616
@param columns - Columns to occupy in the terminal.
1717
1818
@example
@@ -47,7 +47,7 @@ cliTruncate(paragraph, process.stdout.columns));
4747
```
4848
*/
4949
declare function cliTruncate(
50-
input: string,
50+
text: string,
5151
columns: number,
5252
options?: cliTruncate.Options
5353
): string;

‎index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const sliceAnsi = require('slice-ansi');
33
const 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}`);

‎readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ cliTruncate(paragraph, process.stdout.columns));
4747

4848
## API
4949

50-
### cliTruncate(input, columns, [options])
50+
### cliTruncate(text, columns, [options])
5151

52-
#### input
52+
#### text
5353

5454
Type: `string`
5555

0 commit comments

Comments
 (0)
Please sign in to comment.