1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { fetchTodaysNytCxPuzzle } from "https://esm.town/v/plr/fetchTodaysNytCxPuzzle";
import type { Puzzle, PuzzleContent } from "https://esm.town/v/plr/fetchTodaysNytCxPuzzle";
const formatGrid = (
grid: Puzzle["content"]["grid"],
{ filled }: { filled: boolean } = { filled: false },
): Puzzle["content"]["grid"] => {
return grid.map(row => row.map(cell => cell !== "." ? filled ? cell : "□" : "■"));
// return grid.map(row => row.map(cell => cell !== "." ? filled ? cell : "X" : "."));
};
export const fetchTodaysNytCxGridAndClues = async (
{ filled }: { filled: boolean } = { filled: false },
): Promise<Pick<PuzzleContent, "grid" | "clues">> => {
const puzzle = await fetchTodaysNytCxPuzzle();
const grid = formatGrid(puzzle.content.grid, { filled });
const clues = puzzle.content.clues;
return { grid, clues };
};