-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathexample.js
More file actions
24 lines (18 loc) · 837 Bytes
/
Copy pathexample.js
File metadata and controls
24 lines (18 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Run: node example.js
import cliTruncate from './index.js';
const rainbow = text => {
const codes = [31, 33, 32, 36, 34, 35];
return [...text].map((ch, i) => `\u001B[${codes[i % codes.length]}m${ch}\u001B[39m`).join('');
};
const title = '\u001B[35m🦄 Unicorn Gazette\u001B[39m';
const desc = '\u001B[2m gallops through a meadow of sparkles and rainbows while sipping glitter-latte \u001B[22m'.repeat(3);
const fancy = `${title} ${rainbow('magical news:')} ${desc}`;
const width = 30;
console.log('End truncation (styled ellipsis):');
console.log(cliTruncate(fancy, width));
console.log();
console.log('Start truncation (styled ellipsis):');
console.log(cliTruncate(fancy, width, {position: 'start'}));
console.log();
console.log('Middle truncation (classic):');
console.log(cliTruncate(fancy, width, {position: 'middle'}));