-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccad43c
commit 1a4c32b
Showing
10 changed files
with
129 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import chalk from 'chalk' | ||
import * as Color from 'color' | ||
|
||
import {STANDARD_CHALK, StandardChalk, Theme} from '../interfaces/theme' | ||
|
||
function isStandardChalk(color: any): color is StandardChalk { | ||
return STANDARD_CHALK.includes(color) | ||
} | ||
|
||
export function colorize(color: Color | StandardChalk | undefined, text: string): string { | ||
if (isStandardChalk(color)) return chalk[color](text) | ||
|
||
return color ? chalk.hex(color.hex())(text) : text | ||
} | ||
|
||
export function parseTheme(untypedTheme: Record<string, string>): Theme { | ||
return Object.fromEntries( | ||
Object.entries(untypedTheme) | ||
.map(([key, value]) => [key, getColor(value)]) | ||
.filter(([_, value]) => value), | ||
) | ||
} | ||
|
||
export function getColor(color: string): Color | ||
export function getColor(color: StandardChalk): StandardChalk | ||
export function getColor(color: string | StandardChalk): Color | StandardChalk | undefined { | ||
try { | ||
// eslint-disable-next-line new-cap | ||
return isStandardChalk(color) ? color : new Color.default(color) | ||
} catch {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.