honigle/src/lib/words.ts

30 lines
772 B
TypeScript

import { WORDS } from '../constants/wordlist'
import { VALIDGUESSES } from '../constants/validGuesses'
export const isWordInWordList = (word: string) => {
return (
WORDS.includes(word.toLowerCase()) ||
VALIDGUESSES.includes(word.toLowerCase())
)
}
export const isWinningWord = (word: string) => {
return solution === word
}
export const getWordOfDay = () => {
// January 1, 2022 Game Epoch
const epochMs = 1641013200000
const now = Date.now()
const msInDay = 86400000
const index = Math.floor((now - epochMs) / msInDay)
const nextday = (index+1)*msInDay + epochMs;
return {
solution: WORDS[index].toUpperCase(),
solutionIndex: index,
tomorrow: nextday,
}
}
export const { solution, solutionIndex, tomorrow } = getWordOfDay()