-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
205 lines (183 loc) · 4.99 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
type BaseColors =
| "black"
| "red"
| "green"
| "yellow"
| "blue"
| "magenta"
| "cyan"
| "white";
type Color =
| BaseColors
| "rand"
| "random"
| "random normal"
| "random semi-bright"
| "random bright"
| "random semi-dark"
| "random dark"
| "rand normal"
| "rand semi-bright"
| "rand bright"
| "rand semi-dark"
| "rand dark"
| "#000000"
| "rgb(0,0,0)"
| "hsl(0,0%,0%)";
type StyleObject = {
weight?: "bold" | "light" | "auto";
style?: "italic";
decoration?: "underline" | "crossed" | "overline";
foreground?: Color;
background?: Color;
color?: Color;
bg?: Color;
underlineColor?: Color;
visibility?: "hidden" | "visible";
border?: "box" | "circle";
font?:
| "0"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "10"
| "fraktur"
| "gothic";
blink?: "slow" | "fast";
colorMode?: "auto" | "invert";
};
type Styles = { [key: string]: StyleObject };
type Colors = { [key: string]: Color };
type Data = { [key: string]: string };
type CallBack = (err: Error, res: string | undefined) => {};
type Preset = "rainbow" | "money";
declare global {
interface String {
/**
* Styles this string with given style object.
* Worst-Case Time complexity O(1) | O(n) - if multiple properties are not efficient.
*
* @param {styleObject} styleObject Style object or a name of saved style template.
* @returns {string} Current string without any style.
*/
style(styleObject: StyleObject): string;
/**
* Apply preset on this string.
* Worst-Case Time complexity: O(preset).
*
* @see {@link ./lib/presets.js}
*
* @param {Preset} presetName Preset name.
* @param {any[]} args Preset arguments.
* @returns {string} Styled string.
*/
preset(presetName: Preset, ...args: any[]): string;
/**
* Clears this string from any styles.
* Worst-Case Time complexity O(|this|)
*
* @returns {string} Current string without any style.
*/
clearStyle(): string;
}
}
/**
* Clears a string from any styles.
* Worst-Case Time complexity O(|str|)
*
* @param {string} str string.
* @returns {string} string without any style.
*/
export function clear(str: string): string;
/**
* Apply style on a given string.
* Worst-Case Time complexity O(1) | O(n) - if multiple properties are not efficient.
*
* @param {string} str string to be styled.
* @param {StyleObject} styleObject Style object.
* @returns {string} Styled string.
*/
export function apply(str: string, styleObject: StyleObject): string;
/**
* Apply preset on a given string.
* Worst-Case Time complexity O(1) | O(|str|) - if multiple properties are not efficient.
*
* @see {@link ./lib/presets.js}
*
* @param {string} str string to be styled.
* @param {Preset} presetName Preset name.
* @param {any[]} args Preset arguments.
* @returns {string} Styled string.
*/
export function preset(str: string, presetName: Preset, ...args: any[]): string;
/**
* Saves style as template within a given name.
* Worst-Case Time complexity O(1).
*
* @param {string} name Style name.
* @param {StyleObject} styleObject Style object.
*/
export function saveStyle(name: string, styleObject: StyleObject): void;
/**
* Saves color as template within a given name.
* Worst-Case Time complexity O(1).
*
* @param {string} name Style name.
* @param {Color} color Color in formats: (BaseColor|HEXColor|RGBColor|HSLColor)
*/
export function saveColor(name: string, color: Color): void;
/**
* Saves multiples styles from js object.
* Worst-Case Time complexity O(1).
*
* @param {Styles} styles Styles object.
*/
export function saveStyles(styles: Styles): void;
/**
* Saves multiples color as template within a given js object.
* Worst-Case Time complexity O(1).
*
* @param {Colors} colors Colors object.
*/
export function saveColors(colors: Colors): void;
/**
* Saves template auto detection (COLOR|STYLE)
* Worst-Case Time complexity O(1).
*
* @param {string} name Style name.
* @param {Styles & Colors} template Template
*/
export function save(name: string, template: Styles & Colors): void;
/**
* Renders style of a txt file [Callback].
* @param {string} file File path.
* @param {CallBack} [cb] Callback function.
*/
export function render(file: string, cb: CallBack): void;
/**
* Renders style of a txt file [Callback].
* @param {string} file File path.
* @param {Data} data Data parameters.
* @param {CallBack} [cb] Callback function.
*/
export function render(file: string, data: Data, cb: CallBack): void;
/**
* Renders style of a txt file [Sync].
* @param {string} file File path.
* @param {Data} [data] Data parameters.
* @returns {string} Encoded string.
*/
export function renderSync(file: string, data?: Data): string;
/**
* Renders style of a txt file [Promise].
* @param {string} file File path.
* @param {Data} [data] Data parameters.
* @returns {Promise} A new promise.
*/
export function renderAsync(file: string, data?: Data): Promise<string>;