(
context: Context,
string: FormattedString
)
| 9 | } |
| 10 | |
| 11 | export function applyFormatting( |
| 12 | context: Context, |
| 13 | string: FormattedString |
| 14 | ): string { |
| 15 | const { CHALK, DEFAULT_COLOR } = context; |
| 16 | |
| 17 | let formattedString = ''; |
| 18 | for (const [substring, colors] of string.iterSubstrings()) { |
| 19 | let formattedSubstring = substring; |
| 20 | const themeColor = reduceThemeColors([...colors, DEFAULT_COLOR]); |
| 21 | |
| 22 | const { color, backgroundColor, modifiers } = themeColor; |
| 23 | if (color) { |
| 24 | formattedSubstring = CHALK.rgb( |
| 25 | Math.floor(color.r), |
| 26 | Math.floor(color.g), |
| 27 | Math.floor(color.b) |
| 28 | )(formattedSubstring); |
| 29 | } |
| 30 | if (backgroundColor) { |
| 31 | formattedSubstring = CHALK.bgRgb( |
| 32 | Math.floor(backgroundColor.r), |
| 33 | Math.floor(backgroundColor.g), |
| 34 | Math.floor(backgroundColor.b) |
| 35 | )(formattedSubstring); |
| 36 | } |
| 37 | if (modifiers) { |
| 38 | for (const modifier of modifiers) { |
| 39 | formattedSubstring = CHALK[modifier](formattedSubstring); |
| 40 | } |
| 41 | } |
| 42 | formattedString += formattedSubstring; |
| 43 | } |
| 44 | return formattedString; |
| 45 | } |
no test coverage detected