1
- import chalk , { type Chalk } from 'chalk' ;
2
- import { isBgHex , isBgRgb , isHex , isRgb , isString , normalizeRgb } from '../helpers' ;
1
+ import chalk , { type ChalkInstance } from 'chalk' ;
2
+ import { isBgHex , isBgRgb , isHex , isRgb , isString , normalizeRgb } from '../helpers/index.js ' ;
3
3
4
4
/**
5
5
* A palette error.
@@ -25,10 +25,10 @@ export default class PaletteError extends Error {
25
25
/**
26
26
* Returns a Chalk instance with specified styles applied.
27
27
* @param {(string | string[]) } [styles=[]] - The styles to apply.
28
- * @param {Chalk } [chain] - The Chalk instance to chain with.
29
- * @returns {Chalk } A Chalk instance with the specified styles.
28
+ * @param {ChalkInstance } [chain] - The Chalk instance to chain with.
29
+ * @returns {ChalkInstance } A Chalk instance with the specified styles.
30
30
*/
31
- palette ( styles : string | string [ ] = [ ] , chain ?: Chalk ) : Chalk {
31
+ palette ( styles : string | string [ ] = [ ] , chain ?: ChalkInstance ) : ChalkInstance {
32
32
const isArray = Array . isArray ( styles ) ;
33
33
const isIllegal = ! isArray && ! isString ( styles ) ;
34
34
@@ -58,11 +58,11 @@ export default class PaletteError extends Error {
58
58
/**
59
59
* Creates a Chalk instance based on the given style.
60
60
* @private
61
- * @param {Chalk } chain - The Chalk instance to chain with.
61
+ * @param {ChalkInstance } chain - The Chalk instance to chain with.
62
62
* @param {string } [style] - The style to apply.
63
- * @returns {Chalk } A Chalk instance with the specified style.
63
+ * @returns {ChalkInstance } A Chalk instance with the specified style.
64
64
*/
65
- private factory ( chain : Chalk , style ?: string ) : Chalk {
65
+ private factory ( chain : ChalkInstance , style ?: string ) : ChalkInstance {
66
66
let nextChain ;
67
67
68
68
if ( ! isString ( style ) ) {
@@ -76,11 +76,11 @@ export default class PaletteError extends Error {
76
76
} else if ( isBgHex ( style ) ) {
77
77
nextChain = chain . bgHex ( ( style as string ) . replace ( / ^ b g : / , '' ) ) ;
78
78
} else if ( isHex ( style ) ) {
79
- nextChain = chain . hex ( style ) ;
79
+ nextChain = chain . hex ( style as string ) ;
80
80
} else {
81
- nextChain = chain [ style ] ;
81
+ nextChain = chain [ style as keyof ChalkInstance ] ?? chain ;
82
82
}
83
83
84
- return nextChain ;
84
+ return nextChain as ChalkInstance ;
85
85
}
86
86
}
0 commit comments