UNPKG

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