forked from thesam73/wordle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare.ts
36 lines (34 loc) · 874 Bytes
/
share.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
import { getGuessStatuses } from './statuses'
import { solutionIndex } from './words'
import { GAME_TITLE } from '../constants/strings'
export const shareStatus = (
guesses: string[],
lost: boolean,
isHardMode: boolean
) => {
navigator.clipboard.writeText(
`${GAME_TITLE} ${solutionIndex} ${lost ? 'X' : guesses.length}/6${
isHardMode ? '*' : ''
}\n\n` + generateEmojiGrid(guesses)
)
}
export const generateEmojiGrid = (guesses: string[]) => {
return guesses
.map((guess) => {
const status = getGuessStatuses(guess)
return guess
.split('')
.map((_, i) => {
switch (status[i]) {
case 'correct':
return '🟩'
case 'present':
return '🟨'
default:
return '⬜'
}
})
.join('')
})
.join('\n')
}