-
-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathindex.ts
More file actions
20 lines (17 loc) · 673 Bytes
/
index.ts
File metadata and controls
20 lines (17 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { type InspectColor, styleText } from 'node:util';
export type StyleText = ((text: string | TemplateStringsArray, ...args: unknown[]) => string) & {
[key in InspectColor]: StyleText;
};
export function createStyleText(...styles: InspectColor[]): StyleText {
return new Proxy(
(text: string | TemplateStringsArray, ...args: unknown[]) =>
styleText(styles, typeof text === 'string' ? text : String.raw({ raw: text }, ...args)),
{
get(_, prop) {
if (typeof prop !== 'string') throw new TypeError('Property must be a string');
return createStyleText(...styles, prop as InspectColor);
},
}
) as StyleText;
}
export default createStyleText();