1 |
|
2 | "use strict";
|
3 |
|
4 | const colors = require('ansi-colors');
|
5 |
|
6 | const rainbowColors = [
|
7 | 'red',
|
8 | 'yellowBright',
|
9 | 'green',
|
10 | 'blue',
|
11 | "cyan",
|
12 | 'magentaBright',
|
13 | "whiteBright",
|
14 |
|
15 | "redBright"
|
16 | ];
|
17 |
|
18 | function colorize(exploded, letter, i) {
|
19 | if (letter === ' ') {
|
20 | return exploded + letter;
|
21 | } else {
|
22 | return exploded + colors[rainbowColors[i++ % rainbowColors.length]](letter);
|
23 | }
|
24 | };
|
25 | module.exports =
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 | function rainbow(str) {
|
32 | return Array.from(str).reduce(colorize, '');
|
33 | } |
\ | No newline at end of file |