1
+ import { hexToHexString } from '@server/util/colors' ;
2
+
1
3
export const startsWithVowel = ( str : string ) : boolean => {
2
4
str = str . trim ( ) . toLowerCase ( ) ;
3
5
@@ -7,7 +9,7 @@ export const startsWithVowel = (str: string): boolean => {
7
9
} ;
8
10
9
11
// Thank you to the Apollo team for these values. :)
10
- const charWidths = [ 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 ,
12
+ const charWidths = [ 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 ,
11
13
3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 4 , 7 , 14 , 9 , 12 , 12 , 4 , 5 ,
12
14
5 , 10 , 8 , 4 , 8 , 4 , 7 , 9 , 7 , 9 , 8 , 8 , 8 , 9 , 7 , 9 , 9 , 4 , 5 , 7 ,
13
15
9 , 7 , 9 , 14 , 9 , 8 , 8 , 8 , 7 , 7 , 9 , 8 , 6 , 8 , 8 , 7 , 10 , 9 , 9 , 8 ,
@@ -19,7 +21,7 @@ const charWidths = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
19
21
8 , 8 , 4 , 5 , 5 , 6 , 7 , 11 , 11 , 11 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 13 , 8 , 8 ,
20
22
8 , 8 , 8 , 4 , 4 , 5 , 4 , 8 , 9 , 9 , 9 , 9 , 9 , 9 , 8 , 10 , 9 , 9 , 9 , 9 ,
21
23
8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 13 , 6 , 8 , 8 , 8 , 8 , 4 , 4 , 5 , 4 , 8 ,
22
- 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 ] ;
24
+ 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 ] ;
23
25
24
26
export function wrapText ( text : string , maxWidth : number ) : string [ ] {
25
27
const lines = [ ] ;
@@ -30,11 +32,11 @@ export function wrapText(text: string, maxWidth: number): string[] {
30
32
let widthAfterSpace = 0 ;
31
33
let lastSpaceChar = '' ;
32
34
33
- for ( let i = 0 ; i < text . length ; i ++ ) {
35
+ for ( let i = 0 ; i < text . length ; i ++ ) {
34
36
const char = text . charAt ( i ) ;
35
37
36
38
// Ignore <col=> and </col> strings...
37
- if ( char === '<' && ( text . charAt ( i + 1 ) === '/' || text . charAt ( i + 1 ) === 'c' && text . charAt ( i + 2 ) === 'o' && text . charAt ( i + 3 ) === 'l' ) ) {
39
+ if ( char === '<' && ( text . charAt ( i + 1 ) === '/' || text . charAt ( i + 1 ) === 'c' && text . charAt ( i + 2 ) === 'o' && text . charAt ( i + 3 ) === 'l' ) ) {
38
40
const tagCloseIndex = text . indexOf ( '>' , i ) ;
39
41
i = tagCloseIndex ;
40
42
continue ;
@@ -44,20 +46,20 @@ export function wrapText(text: string, maxWidth: number): string[] {
44
46
width += charWidth ;
45
47
widthAfterSpace += charWidth ;
46
48
47
- if ( char === ' ' || char === '\n' || char === '-' ) {
49
+ if ( char === ' ' || char === '\n' || char === '-' ) {
48
50
lastSpaceChar = char ;
49
51
lastSpace = i ;
50
52
widthAfterSpace = 0 ;
51
53
}
52
54
53
- if ( width >= maxWidth || char === '\n' ) {
55
+ if ( width >= maxWidth || char === '\n' ) {
54
56
lines . push ( text . substring ( lineStartIdx , lastSpaceChar === '-' ? lastSpace + 1 : lastSpace ) ) ;
55
57
lineStartIdx = lastSpace + 1 ;
56
58
width = widthAfterSpace ;
57
59
}
58
60
}
59
61
60
- if ( lineStartIdx !== text . length - 1 ) {
62
+ if ( lineStartIdx !== text . length - 1 ) {
61
63
lines . push ( text . substring ( lineStartIdx , text . length ) ) ;
62
64
}
63
65
@@ -67,14 +69,19 @@ export function wrapText(text: string, maxWidth: number): string[] {
67
69
export function stringToLong ( s : string ) : bigint {
68
70
let l : bigint = BigInt ( 0 ) ;
69
71
70
- for ( let i = 0 ; i < s . length && i < 12 ; i ++ ) {
72
+ for ( let i = 0 ; i < s . length && i < 12 ; i ++ ) {
71
73
const c = s . charAt ( i ) ;
72
74
const cc = s . charCodeAt ( i ) ;
73
75
l *= BigInt ( 37 ) ;
74
- if ( c >= 'A' && c <= 'Z' ) l += BigInt ( ( 1 + cc ) - 65 ) ;
75
- else if ( c >= 'a' && c <= 'z' ) l += BigInt ( ( 1 + cc ) - 97 ) ;
76
- else if ( c >= '0' && c <= '9' ) l += BigInt ( ( 27 + cc ) - 48 ) ;
76
+ if ( c >= 'A' && c <= 'Z' ) l += BigInt ( ( 1 + cc ) - 65 ) ;
77
+ else if ( c >= 'a' && c <= 'z' ) l += BigInt ( ( 1 + cc ) - 97 ) ;
78
+ else if ( c >= '0' && c <= '9' ) l += BigInt ( ( 27 + cc ) - 48 ) ;
77
79
}
78
- while ( l % BigInt ( 37 ) == BigInt ( 0 ) && l != BigInt ( 0 ) ) l /= BigInt ( 37 ) ;
80
+ while ( l % BigInt ( 37 ) == BigInt ( 0 ) && l != BigInt ( 0 ) ) l /= BigInt ( 37 ) ;
79
81
return l ;
80
82
}
83
+
84
+ export function colorText ( s : string , hexColor : number ) : string {
85
+ console . log ( hexToHexString ( hexColor ) ) ;
86
+ return `<col=${ hexToHexString ( hexColor ) } >${ s } </col>` ;
87
+ }
0 commit comments