@johnmorrisdotca/kumimoji 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/README.md +80 -39
  3. package/dist/check.d.ts +26 -1
  4. package/dist/check.js +26 -1
  5. package/dist/computer.types.d.ts +24 -2
  6. package/dist/computerPlay.d.ts +45 -2
  7. package/dist/computerPlay.js +45 -2
  8. package/dist/computerTurn.d.ts +42 -3
  9. package/dist/computerTurn.js +42 -3
  10. package/dist/daily.d.ts +22 -2
  11. package/dist/daily.js +22 -2
  12. package/dist/element-define.d.ts +1 -1
  13. package/dist/element-define.js +3 -13
  14. package/dist/element.d.ts +85 -4
  15. package/dist/element.js +176 -45
  16. package/dist/embed-day.d.ts +4 -0
  17. package/dist/embed-day.js +23 -0
  18. package/dist/export.d.ts +123 -6
  19. package/dist/export.js +91 -4
  20. package/dist/generate.d.ts +14 -0
  21. package/dist/generate.js +14 -0
  22. package/dist/grid.d.ts +181 -10
  23. package/dist/grid.js +122 -7
  24. package/dist/help.d.ts +36 -3
  25. package/dist/help.js +36 -3
  26. package/dist/judge.d.ts +14 -0
  27. package/dist/judge.js +14 -0
  28. package/dist/kana.d.ts +23 -1
  29. package/dist/kana.js +23 -1
  30. package/dist/kumimoji.types.d.ts +70 -5
  31. package/dist/party.d.ts +268 -14
  32. package/dist/party.js +268 -14
  33. package/dist/party.types.d.ts +50 -2
  34. package/dist/partyKept.d.ts +74 -4
  35. package/dist/partyKept.js +74 -4
  36. package/dist/partySeats.d.ts +92 -6
  37. package/dist/partySeats.js +72 -4
  38. package/dist/partyTurns.d.ts +171 -5
  39. package/dist/partyTurns.js +171 -5
  40. package/dist/placement.d.ts +50 -2
  41. package/dist/placement.js +30 -0
  42. package/dist/play.d.ts +247 -15
  43. package/dist/play.js +237 -15
  44. package/dist/random.d.ts +34 -3
  45. package/dist/random.js +23 -2
  46. package/dist/react.d.ts +42 -4
  47. package/dist/react.js +22 -5
  48. package/dist/showcase.d.ts +83 -7
  49. package/dist/showcase.js +49 -4
  50. package/dist/strings.d.ts +54 -5
  51. package/dist/strings.js +34 -3
  52. package/dist/tableView.d.ts +151 -8
  53. package/dist/tableView.js +129 -6
  54. package/dist/tileFace.d.ts +59 -5
  55. package/dist/tileFace.js +48 -4
  56. package/dist/tileFamily.d.ts +9 -0
  57. package/dist/tileFamily.js +9 -0
  58. package/dist/tileWords.d.ts +93 -6
  59. package/dist/tileWords.js +83 -6
  60. package/dist/tileWordsModule.d.ts +11 -1
  61. package/dist/tileWordsModule.js +11 -1
  62. package/dist/tiles.constants.d.ts +99 -5
  63. package/dist/tiles.constants.js +99 -5
  64. package/dist/turn.d.ts +82 -4
  65. package/dist/turn.js +82 -4
  66. package/dist/ui/board.d.ts +60 -5
  67. package/dist/ui/board.js +28 -2
  68. package/dist/ui/mount.d.ts +41 -2
  69. package/dist/ui/mount.js +38 -1
  70. package/dist/ui/style.d.ts +6 -1
  71. package/dist/ui/style.js +6 -0
  72. package/dist/version.d.ts +9 -2
  73. package/dist/version.js +9 -2
  74. package/dist/wilds.d.ts +22 -1
  75. package/dist/wilds.js +22 -1
  76. package/package.json +64 -56
package/dist/export.d.ts CHANGED
@@ -14,9 +14,31 @@ import { type KumimojiStrings } from "./strings.ts";
14
14
  * the game only if every tile in the hand and on the table is one that came
15
15
  * out of that bag and was not given back.
16
16
  */
17
- /** The shape of the JSON this package writes. It goes up only when a reader of the old shape would be wrong about the new one. */
17
+ /** The shape of the JSON this package writes. It goes up only when a reader of the old shape would be wrong about the new one.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { KUMIMOJI_EXPORT_FORMAT } from "@johnmorrisdotca/kumimoji";
22
+ * console.log(KUMIMOJI_EXPORT_FORMAT);
23
+ * ```
24
+ */
18
25
  export declare const KUMIMOJI_EXPORT_FORMAT = 1;
19
- /** A game alone as it is kept: the deal, where the player has got to, and the time spent so far. */
26
+ /** A game alone as it is kept: the deal, where the player has got to, and the time spent so far.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { deal, generateKumimoji } from "@johnmorrisdotca/kumimoji";
31
+ * import type { KumimojiSaved } from "@johnmorrisdotca/kumimoji";
32
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
33
+ *
34
+ * await loadTileWordsFromModule("english");
35
+ * const play = deal("catdog",3);
36
+ * const dealt = generateKumimoji(3,"hard",44);
37
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
38
+ * const value: KumimojiSaved = saved;
39
+ * console.log(value);
40
+ * ```
41
+ */
20
42
  export type KumimojiSaved = {
21
43
  /** The game as dealt: `generateKumimoji`'s. */
22
44
  deal: KumimojiDeal;
@@ -25,7 +47,22 @@ export type KumimojiSaved = {
25
47
  /** Milliseconds spent on it so far. */
26
48
  elapsedMs: number;
27
49
  };
28
- /** A whole JSON export of one game: what `kumimojiToJSON` writes and `kumimojiFromJSON` reads. */
50
+ /** A whole JSON export of one game: what `kumimojiToJSON` writes and `kumimojiFromJSON` reads.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { deal, generateKumimoji, kumimojiExported } from "@johnmorrisdotca/kumimoji";
55
+ * import type { KumimojiExported } from "@johnmorrisdotca/kumimoji";
56
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
57
+ *
58
+ * await loadTileWordsFromModule("english");
59
+ * const play = deal("catdog",3);
60
+ * const dealt = generateKumimoji(3,"hard",44);
61
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
62
+ * const value: KumimojiExported = kumimojiExported(saved);
63
+ * console.log(value);
64
+ * ```
65
+ */
29
66
  export type KumimojiExported = {
30
67
  /** The shape's number: `KUMIMOJI_EXPORT_FORMAT`. */
31
68
  format: typeof KUMIMOJI_EXPORT_FORMAT;
@@ -52,9 +89,39 @@ export type KumimojiExported = {
52
89
  /** Milliseconds spent so far. */
53
90
  elapsedMs: number;
54
91
  };
55
- /** A game as the JSON export's object. */
92
+ /** A game as the JSON export's object.
93
+ *
94
+ * @param saved - The original deal, current progress and elapsed time.
95
+ * @returns A game as the JSON export's object.
96
+ * @example
97
+ * ```ts
98
+ * import { deal, generateKumimoji, kumimojiExported } from "@johnmorrisdotca/kumimoji";
99
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
100
+ *
101
+ * await loadTileWordsFromModule("english");
102
+ * const play = deal("catdog",3);
103
+ * const dealt = generateKumimoji(3,"hard",44);
104
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
105
+ * console.log(kumimojiExported(saved).format);
106
+ * ```
107
+ */
56
108
  export declare function kumimojiExported(saved: KumimojiSaved): KumimojiExported;
57
- /** A game as JSON, two spaces deep, with the format's number first. `kumimojiFromJSON` reads it back. */
109
+ /** A game as JSON, two spaces deep, with the format's number first. `kumimojiFromJSON` reads it back.
110
+ *
111
+ * @param saved - The original deal, current progress and elapsed time.
112
+ * @returns A game as JSON, two spaces deep, with the format's number first. `kumimojiFromJSON` reads it back.
113
+ * @example
114
+ * ```ts
115
+ * import { deal, generateKumimoji, kumimojiToJSON } from "@johnmorrisdotca/kumimoji";
116
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
117
+ *
118
+ * await loadTileWordsFromModule("english");
119
+ * const play = deal("catdog",3);
120
+ * const dealt = generateKumimoji(3,"hard",44);
121
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
122
+ * console.log(kumimojiToJSON(saved));
123
+ * ```
124
+ */
58
125
  export declare function kumimojiToJSON(saved: KumimojiSaved): string;
59
126
  /**
60
127
  * A game from JSON that `kumimojiToJSON` wrote. Nothing in it is trusted: the
@@ -66,15 +133,50 @@ export declare function kumimojiToJSON(saved: KumimojiSaved): string;
66
133
  * The word list of the game's language is loaded first, since dealing needs
67
134
  * it; where there is no browser, import `@johnmorrisdotca/kumimoji/words`
68
135
  * once, or the promise is rejected as `loadTileWords` rejects it.
136
+ *
137
+ * @param text - The saved JSON text to validate.
138
+ * @returns A game from JSON that `kumimojiToJSON` wrote. Nothing in it is trusted: the bag is dealt again from the seed, and the game opens only if every tile held is one that came out of that bag. Resolves to null when the text is not JSON, is of a later format than this version reads, is another game's, or holds a hand or a grid that this bag never dealt.
139
+ * @example
140
+ * ```ts
141
+ * import { deal, generateKumimoji, kumimojiFromJSON, kumimojiToJSON } from "@johnmorrisdotca/kumimoji";
142
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
143
+ *
144
+ * await loadTileWordsFromModule("english");
145
+ * const play = deal("catdog",3);
146
+ * const dealt = generateKumimoji(3,"hard",44);
147
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
148
+ * console.log((await kumimojiFromJSON(kumimojiToJSON(saved)))?.deal.seed);
149
+ * ```
69
150
  */
70
151
  export declare function kumimojiFromJSON(text: string): Promise<KumimojiSaved | null>;
71
- /** A time as minutes and seconds: `1:05`. */
152
+ /** A time as minutes and seconds: `1:05`.
153
+ *
154
+ * @param ms - The duration in milliseconds.
155
+ * @returns A time as minutes and seconds: `1:05`.
156
+ * @example
157
+ * ```ts
158
+ * import { kumimojiClock } from "@johnmorrisdotca/kumimoji";
159
+ *
160
+ * console.log(kumimojiClock(65000));
161
+ * ```
162
+ */
72
163
  export declare function kumimojiClock(ms: number): string;
73
164
  /**
74
165
  * A grid as lines of text, the way it lies on the table: English letters in
75
166
  * capitals with a space between squares and a dot for an empty one, kana side
76
167
  * by side with a full-width dot for an empty one, so that either lines up in a
77
168
  * fixed-width face, every row as wide as the crossword. A wild that has been given nothing is `*`. No tiles is "".
169
+ *
170
+ * @param tiles - The map from row,column square names to internal tile codes.
171
+ * @param language - The English or Japanese tile language.
172
+ * @returns A grid as lines of text, the way it lies on the table: English letters in capitals with a space between squares and a dot for an empty one, kana side by side with a full-width dot for an empty one, so that either lines up in a fixed-width face, every row as wide as the crossword. A wild that has been given nothing is `*`. No tiles is "".
173
+ * @example
174
+ * ```ts
175
+ * import { gridToText } from "@johnmorrisdotca/kumimoji";
176
+ *
177
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
178
+ * console.log(gridToText(tiles));
179
+ * ```
78
180
  */
79
181
  export declare function gridToText(tiles: Tiles, language?: KumimojiLanguage): string;
80
182
  /**
@@ -83,5 +185,20 @@ export declare function gridToText(tiles: Tiles, language?: KumimojiLanguage): s
83
185
  * English unless given another table of strings (`KUMIMOJI_STRINGS.ja`). The
84
186
  * word list of the game's language must have been loaded, as for any judging.
85
187
  * Lines end with a line feed.
188
+ *
189
+ * @param saved - The original deal, current progress and elapsed time.
190
+ * @param strings - The localized words for readable export.
191
+ * @returns A game as plain text, for a chat or a note: how it was set up, the crossword as it lies, the hand, how many tiles are left, and the time. In English unless given another table of strings (`KUMIMOJI_STRINGS.ja`). The word list of the game's language must have been loaded, as for any judging. Lines end with a line feed.
192
+ * @example
193
+ * ```ts
194
+ * import { deal, generateKumimoji, kumimojiToText } from "@johnmorrisdotca/kumimoji";
195
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
196
+ *
197
+ * await loadTileWordsFromModule("english");
198
+ * const play = deal("catdog",3);
199
+ * const dealt = generateKumimoji(3,"hard",44);
200
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
201
+ * console.log(kumimojiToText(saved));
202
+ * ```
86
203
  */
87
204
  export declare function kumimojiToText(saved: KumimojiSaved, strings?: KumimojiStrings): string;
package/dist/export.js CHANGED
@@ -19,9 +19,31 @@ import { KUMIMOJI_VERSION } from "./version.js";
19
19
  * the game only if every tile in the hand and on the table is one that came
20
20
  * out of that bag and was not given back.
21
21
  */
22
- /** The shape of the JSON this package writes. It goes up only when a reader of the old shape would be wrong about the new one. */
22
+ /** The shape of the JSON this package writes. It goes up only when a reader of the old shape would be wrong about the new one.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { KUMIMOJI_EXPORT_FORMAT } from "@johnmorrisdotca/kumimoji";
27
+ * console.log(KUMIMOJI_EXPORT_FORMAT);
28
+ * ```
29
+ */
23
30
  export const KUMIMOJI_EXPORT_FORMAT = 1;
24
- /** A game as the JSON export's object. */
31
+ /** A game as the JSON export's object.
32
+ *
33
+ * @param saved - The original deal, current progress and elapsed time.
34
+ * @returns A game as the JSON export's object.
35
+ * @example
36
+ * ```ts
37
+ * import { deal, generateKumimoji, kumimojiExported } from "@johnmorrisdotca/kumimoji";
38
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
39
+ *
40
+ * await loadTileWordsFromModule("english");
41
+ * const play = deal("catdog",3);
42
+ * const dealt = generateKumimoji(3,"hard",44);
43
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
44
+ * console.log(kumimojiExported(saved).format);
45
+ * ```
46
+ */
25
47
  export function kumimojiExported(saved) {
26
48
  const { deal, play } = saved;
27
49
  return {
@@ -39,7 +61,22 @@ export function kumimojiExported(saved) {
39
61
  elapsedMs: Math.max(0, Math.round(saved.elapsedMs)),
40
62
  };
41
63
  }
42
- /** A game as JSON, two spaces deep, with the format's number first. `kumimojiFromJSON` reads it back. */
64
+ /** A game as JSON, two spaces deep, with the format's number first. `kumimojiFromJSON` reads it back.
65
+ *
66
+ * @param saved - The original deal, current progress and elapsed time.
67
+ * @returns A game as JSON, two spaces deep, with the format's number first. `kumimojiFromJSON` reads it back.
68
+ * @example
69
+ * ```ts
70
+ * import { deal, generateKumimoji, kumimojiToJSON } from "@johnmorrisdotca/kumimoji";
71
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
72
+ *
73
+ * await loadTileWordsFromModule("english");
74
+ * const play = deal("catdog",3);
75
+ * const dealt = generateKumimoji(3,"hard",44);
76
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
77
+ * console.log(kumimojiToJSON(saved));
78
+ * ```
79
+ */
43
80
  export function kumimojiToJSON(saved) {
44
81
  return `${JSON.stringify(kumimojiExported(saved), null, 2)}\n`;
45
82
  }
@@ -57,6 +94,20 @@ const PROGRESS_MOST = 4000;
57
94
  * The word list of the game's language is loaded first, since dealing needs
58
95
  * it; where there is no browser, import `@johnmorrisdotca/kumimoji/words`
59
96
  * once, or the promise is rejected as `loadTileWords` rejects it.
97
+ *
98
+ * @param text - The saved JSON text to validate.
99
+ * @returns A game from JSON that `kumimojiToJSON` wrote. Nothing in it is trusted: the bag is dealt again from the seed, and the game opens only if every tile held is one that came out of that bag. Resolves to null when the text is not JSON, is of a later format than this version reads, is another game's, or holds a hand or a grid that this bag never dealt.
100
+ * @example
101
+ * ```ts
102
+ * import { deal, generateKumimoji, kumimojiFromJSON, kumimojiToJSON } from "@johnmorrisdotca/kumimoji";
103
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
104
+ *
105
+ * await loadTileWordsFromModule("english");
106
+ * const play = deal("catdog",3);
107
+ * const dealt = generateKumimoji(3,"hard",44);
108
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
109
+ * console.log((await kumimojiFromJSON(kumimojiToJSON(saved)))?.deal.seed);
110
+ * ```
60
111
  */
61
112
  export async function kumimojiFromJSON(text) {
62
113
  let data;
@@ -102,7 +153,17 @@ export async function kumimojiFromJSON(text) {
102
153
  const play = decodeTileProgress(progress, deal.givens, language);
103
154
  return play === null ? null : { deal, play, elapsedMs: spent };
104
155
  }
105
- /** A time as minutes and seconds: `1:05`. */
156
+ /** A time as minutes and seconds: `1:05`.
157
+ *
158
+ * @param ms - The duration in milliseconds.
159
+ * @returns A time as minutes and seconds: `1:05`.
160
+ * @example
161
+ * ```ts
162
+ * import { kumimojiClock } from "@johnmorrisdotca/kumimoji";
163
+ *
164
+ * console.log(kumimojiClock(65000));
165
+ * ```
166
+ */
106
167
  export function kumimojiClock(ms) {
107
168
  const seconds = Math.max(0, Math.floor(ms / 1000));
108
169
  return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
@@ -112,6 +173,17 @@ export function kumimojiClock(ms) {
112
173
  * capitals with a space between squares and a dot for an empty one, kana side
113
174
  * by side with a full-width dot for an empty one, so that either lines up in a
114
175
  * fixed-width face, every row as wide as the crossword. A wild that has been given nothing is `*`. No tiles is "".
176
+ *
177
+ * @param tiles - The map from row,column square names to internal tile codes.
178
+ * @param language - The English or Japanese tile language.
179
+ * @returns A grid as lines of text, the way it lies on the table: English letters in capitals with a space between squares and a dot for an empty one, kana side by side with a full-width dot for an empty one, so that either lines up in a fixed-width face, every row as wide as the crossword. A wild that has been given nothing is `*`. No tiles is "".
180
+ * @example
181
+ * ```ts
182
+ * import { gridToText } from "@johnmorrisdotca/kumimoji";
183
+ *
184
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
185
+ * console.log(gridToText(tiles));
186
+ * ```
115
187
  */
116
188
  export function gridToText(tiles, language = "english") {
117
189
  const bounds = boundsOf(tiles);
@@ -140,6 +212,21 @@ export function gridToText(tiles, language = "english") {
140
212
  * English unless given another table of strings (`KUMIMOJI_STRINGS.ja`). The
141
213
  * word list of the game's language must have been loaded, as for any judging.
142
214
  * Lines end with a line feed.
215
+ *
216
+ * @param saved - The original deal, current progress and elapsed time.
217
+ * @param strings - The localized words for readable export.
218
+ * @returns A game as plain text, for a chat or a note: how it was set up, the crossword as it lies, the hand, how many tiles are left, and the time. In English unless given another table of strings (`KUMIMOJI_STRINGS.ja`). The word list of the game's language must have been loaded, as for any judging. Lines end with a line feed.
219
+ * @example
220
+ * ```ts
221
+ * import { deal, generateKumimoji, kumimojiToText } from "@johnmorrisdotca/kumimoji";
222
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
223
+ *
224
+ * await loadTileWordsFromModule("english");
225
+ * const play = deal("catdog",3);
226
+ * const dealt = generateKumimoji(3,"hard",44);
227
+ * const saved = {deal:dealt,play:deal(dealt.givens,dealt.size),elapsedMs:0};
228
+ * console.log(kumimojiToText(saved));
229
+ * ```
143
230
  */
144
231
  export function kumimojiToText(saved, strings = KUMIMOJI_STRINGS.en) {
145
232
  const { deal, play } = saved;
@@ -25,5 +25,19 @@ import type { KumimojiDeal, KumimojiLevel, KumimojiOptions } from "./kumimoji.ty
25
25
  *
26
26
  * Deterministic in the seed, like every generator here: two browsers in a
27
27
  * race, or one tomorrow, deal the same bag in the same order.
28
+ *
29
+ * @param size - The supported initial hand size.
30
+ * @param level - The difficulty that determines the wildcard allowance.
31
+ * @param seed - The numeric seed for deterministic deals or random draws.
32
+ * @param options - Native game, component or presentation options.
33
+ * @returns MAKING A KUMIMOJI, in the browser, from a seed: the bag the game is played from, in the order its tiles come out.
34
+ * @example
35
+ * ```ts
36
+ * import { generateKumimoji } from "@johnmorrisdotca/kumimoji";
37
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
38
+ *
39
+ * await loadTileWordsFromModule("english");
40
+ * console.log(generateKumimoji(3,"hard",44).givens);
41
+ * ```
28
42
  */
29
43
  export declare function generateKumimoji(size: number, level: KumimojiLevel, seed: number, options?: KumimojiOptions): KumimojiDeal;
package/dist/generate.js CHANGED
@@ -29,6 +29,20 @@ import { tileWords } from "./tileWords.js";
29
29
  *
30
30
  * Deterministic in the seed, like every generator here: two browsers in a
31
31
  * race, or one tomorrow, deal the same bag in the same order.
32
+ *
33
+ * @param size - The supported initial hand size.
34
+ * @param level - The difficulty that determines the wildcard allowance.
35
+ * @param seed - The numeric seed for deterministic deals or random draws.
36
+ * @param options - Native game, component or presentation options.
37
+ * @returns MAKING A KUMIMOJI, in the browser, from a seed: the bag the game is played from, in the order its tiles come out.
38
+ * @example
39
+ * ```ts
40
+ * import { generateKumimoji } from "@johnmorrisdotca/kumimoji";
41
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
42
+ *
43
+ * await loadTileWordsFromModule("english");
44
+ * console.log(generateKumimoji(3,"hard",44).givens);
45
+ * ```
32
46
  */
33
47
  export function generateKumimoji(size, level, seed, options = {}) {
34
48
  const gameLength = options.gameLength ?? "short";
package/dist/grid.d.ts CHANGED
@@ -11,40 +11,139 @@
11
11
  * and COW down from its C. Only
12
12
  * where the tiles stand beside one another is written, never where on the
13
13
  * table they were, so one grid has one spelling however far it was dragged.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import type { Tiles } from "@johnmorrisdotca/kumimoji";
18
+ *
19
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
20
+ * const value: Tiles = tiles;
21
+ * console.log(value);
22
+ * ```
14
23
  */
15
24
  export type Tiles = ReadonlyMap<string, string>;
16
- /** A square's name, "row,col". */
25
+ /** A square's name, "row,col".
26
+ *
27
+ * @param row - The integer row coordinate, which may be negative.
28
+ * @param col - The integer column coordinate, which may be negative.
29
+ * @returns A square's name, "row,col".
30
+ * @example
31
+ * ```ts
32
+ * import { squareAt } from "@johnmorrisdotca/kumimoji";
33
+ *
34
+ * console.log(squareAt(-1,2));
35
+ * ```
36
+ */
17
37
  export declare function squareAt(row: number, col: number): string;
18
- /** A square's row and column, from its name. */
38
+ /** A square's row and column, from its name.
39
+ *
40
+ * @param square - The row,column square name.
41
+ * @returns A square's row and column, from its name.
42
+ * @example
43
+ * ```ts
44
+ * import { placeOf } from "@johnmorrisdotca/kumimoji";
45
+ *
46
+ * console.log(placeOf("-1,2"));
47
+ * ```
48
+ */
19
49
  export declare function placeOf(square: string): {
20
50
  row: number;
21
51
  col: number;
22
52
  };
23
- /** The rows and columns a grid's tiles stand within. */
53
+ /** The rows and columns a grid's tiles stand within.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import type { Bounds } from "@johnmorrisdotca/kumimoji";
58
+ *
59
+ * const value: Bounds = {top:0,left:0,bottom:0,right:2};
60
+ * console.log(value);
61
+ * ```
62
+ */
24
63
  export type Bounds = {
25
64
  top: number;
26
65
  left: number;
27
66
  bottom: number;
28
67
  right: number;
29
68
  };
30
- /** The rows and columns the tiles stand within, or null for no tiles. */
69
+ /** The rows and columns the tiles stand within, or null for no tiles.
70
+ *
71
+ * @param tiles - The map from row,column square names to internal tile codes.
72
+ * @returns The rows and columns the tiles stand within, or null for no tiles.
73
+ * @example
74
+ * ```ts
75
+ * import { boundsOf } from "@johnmorrisdotca/kumimoji";
76
+ *
77
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
78
+ * console.log(boundsOf(tiles));
79
+ * ```
80
+ */
31
81
  export declare function boundsOf(tiles: Tiles): Bounds | null;
32
- /** A grid as a string, drawn from its own top-left tile: `cat/2o/2w`. `decodeGrid` reads it back. */
82
+ /** A grid as a string, drawn from its own top-left tile: `cat/2o/2w`. `decodeGrid` reads it back.
83
+ *
84
+ * @param tiles - The map from row,column square names to internal tile codes.
85
+ * @returns A grid as a string, drawn from its own top-left tile: `cat/2o/2w`. `decodeGrid` reads it back.
86
+ * @example
87
+ * ```ts
88
+ * import { encodeGrid } from "@johnmorrisdotca/kumimoji";
89
+ *
90
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
91
+ * console.log(encodeGrid(tiles));
92
+ * ```
93
+ */
33
94
  export declare function encodeGrid(tiles: Tiles): string;
34
95
  /**
35
96
  * A grid read back, its first row at row 0, or null for anything that is not
36
97
  * one: a stray character, a capital, a grid wider or taller than any grid of
37
98
  * fifty tiles can be. An empty string is no tiles.
99
+ *
100
+ * @param code - The encoded grid or progress text.
101
+ * @returns A grid read back, its first row at row 0, or null for anything that is not one: a stray character, a capital, a grid wider or taller than any grid of fifty tiles can be. An empty string is no tiles.
102
+ * @example
103
+ * ```ts
104
+ * import { decodeGrid } from "@johnmorrisdotca/kumimoji";
105
+ *
106
+ * console.log(decodeGrid("cat"));
107
+ * ```
38
108
  */
39
109
  export declare function decodeGrid(code: string): Map<string, string> | null;
40
- /** How many of each letter. */
110
+ /** How many of each letter.
111
+ *
112
+ * @param letters - The iterable tile letters to count.
113
+ * @returns How many of each letter.
114
+ * @example
115
+ * ```ts
116
+ * import { lettersOf } from "@johnmorrisdotca/kumimoji";
117
+ *
118
+ * console.log(lettersOf("cat"));
119
+ * ```
120
+ */
41
121
  export declare function lettersOf(letters: Iterable<string>): Map<string, number>;
42
- /** Whether two tallies hold the same letters, as many of each. */
122
+ /** Whether two tallies hold the same letters, as many of each.
123
+ *
124
+ * @param a - The first letter-count map.
125
+ * @param b - The second letter-count map.
126
+ * @returns Whether two tallies hold the same letters, as many of each.
127
+ * @example
128
+ * ```ts
129
+ * import { lettersOf, sameLetters } from "@johnmorrisdotca/kumimoji";
130
+ *
131
+ * console.log(sameLetters(lettersOf("cat"),lettersOf("act")));
132
+ * ```
133
+ */
43
134
  export declare function sameLetters(a: Map<string, number>, b: Map<string, number>): boolean;
44
135
  /**
45
136
  * THE LINES A RUN MAY LIE ALONG, each read top to bottom (and across, left to
46
137
  * right): across and down always, and the two diagonals when the game was set
47
138
  * up with Diagonals — down to the right, and down to the left.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import type { RunLine } from "@johnmorrisdotca/kumimoji";
143
+ *
144
+ * const value: RunLine = "across";
145
+ * console.log(value);
146
+ * ```
48
147
  */
49
148
  export type RunLine = "across" | "down" | "downRight" | "downLeft";
50
149
  /**
@@ -52,13 +151,37 @@ export type RunLine = "across" | "down" | "downRight" | "downLeft";
52
151
  * at a corner are what every crossword is full of — the letter above a word
53
152
  * and the one beside it — so a pair is free, and only three or more in a
54
153
  * line are a diagonal word.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * import { DIAGONAL_RUN_LEAST } from "@johnmorrisdotca/kumimoji";
158
+ * console.log(DIAGONAL_RUN_LEAST);
159
+ * ```
55
160
  */
56
161
  export declare const DIAGONAL_RUN_LEAST = 3;
57
- /** How a grid is read: whether its diagonals are (`KumimojiOptions.diagonals`). */
162
+ /** How a grid is read: whether its diagonals are (`KumimojiOptions.diagonals`).
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * import type { GridRules } from "@johnmorrisdotca/kumimoji";
167
+ *
168
+ * const value: GridRules = {diagonals:true};
169
+ * console.log(value);
170
+ * ```
171
+ */
58
172
  export type GridRules = {
59
173
  diagonals?: boolean;
60
174
  };
61
- /** A run of tiles along one line: the word it spells and the squares it stands on, in reading order. */
175
+ /** A run of tiles along one line: the word it spells and the squares it stands on, in reading order.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import type { Run } from "@johnmorrisdotca/kumimoji";
180
+ *
181
+ * const value: Run = {word:"cat",squares:["0,0","0,1","0,2"],line:"across"};
182
+ * console.log(value);
183
+ * ```
184
+ */
62
185
  export type Run = {
63
186
  word: string;
64
187
  squares: string[];
@@ -68,6 +191,17 @@ export type Run = {
68
191
  * Every run the grid is read by: two or more tiles across, then down, and
69
192
  * with Diagonals three or more down to the right, then down to the left. A
70
193
  * tile with nothing beside it in a line is no run.
194
+ *
195
+ * @param tiles - The map from row,column square names to internal tile codes.
196
+ * @param rules - Whether diagonal runs are also judged.
197
+ * @returns Every run the grid is read by: two or more tiles across, then down, and with Diagonals three or more down to the right, then down to the left. A tile with nothing beside it in a line is no run.
198
+ * @example
199
+ * ```ts
200
+ * import { runsOf } from "@johnmorrisdotca/kumimoji";
201
+ *
202
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
203
+ * console.log(runsOf(tiles));
204
+ * ```
71
205
  */
72
206
  export declare function runsOf(tiles: Tiles, rules?: GridRules): Run[];
73
207
  /**
@@ -76,6 +210,17 @@ export declare function runsOf(tiles: Tiles, rules?: GridRules): Run[];
76
210
  * other in one of those runs are joined too: a diagonal word holds a
77
211
  * crossword together as a word across does. A pair touching at a corner is
78
212
  * never a link, because it is never read.
213
+ *
214
+ * @param tiles - The map from row,column square names to internal tile codes.
215
+ * @param links - The runs connecting groups; computed from the grid when omitted.
216
+ * @returns The tiles in groups that touch across or down, largest first. With `links` — the diagonal runs a grid with Diagonals reads — the tiles next to each other in one of those runs are joined too: a diagonal word holds a crossword together as a word across does. A pair touching at a corner is never a link, because it is never read.
217
+ * @example
218
+ * ```ts
219
+ * import { groupsOf } from "@johnmorrisdotca/kumimoji";
220
+ *
221
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
222
+ * console.log(groupsOf(tiles));
223
+ * ```
79
224
  */
80
225
  export declare function groupsOf(tiles: Tiles, links?: readonly Run[]): string[][];
81
226
  /**
@@ -85,6 +230,18 @@ export declare function groupsOf(tiles: Tiles, links?: readonly Run[]): string[]
85
230
  * With Diagonals (`rules`), the diagonal runs of three or more are runs too:
86
231
  * each must be a word, a misspelt one is marked as any other is, and each
87
232
  * joins its tiles (`groupsOf`).
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * import { loadTileWordsFromModule } from "@johnmorrisdotca/kumimoji/words";
237
+ * import { judgeWithWords } from "@johnmorrisdotca/kumimoji";
238
+ * import type { GridVerdict } from "@johnmorrisdotca/kumimoji";
239
+ *
240
+ * const words = await loadTileWordsFromModule("english");
241
+ * const verdict = judgeWithWords(new Map([["0,0","c"],["0,1","a"],["0,2","t"]]),words);
242
+ * const value: GridVerdict = verdict;
243
+ * console.log(value);
244
+ * ```
88
245
  */
89
246
  export type GridVerdict = {
90
247
  sound: boolean;
@@ -96,5 +253,19 @@ export type GridVerdict = {
96
253
  /** The runs that are not words, as spelled, for the line under the table. */
97
254
  notWords: readonly string[];
98
255
  };
99
- /** A grid judged against any test of a word: `isWord` answers for a run as spelt, and `readable` says how to name one that is not. `judgeWithWords` is this with a language's list. */
256
+ /** A grid judged against any test of a word: `isWord` answers for a run as spelt, and `readable` says how to name one that is not. `judgeWithWords` is this with a language's list.
257
+ *
258
+ * @param tiles - The map from row,column square names to internal tile codes.
259
+ * @param isWord - The predicate that accepts a readable word.
260
+ * @param readable - The conversion from tile codes to readable words.
261
+ * @param rules - Whether diagonal runs are also judged.
262
+ * @returns A grid judged against any test of a word: `isWord` answers for a run as spelt, and `readable` says how to name one that is not. `judgeWithWords` is this with a language's list.
263
+ * @example
264
+ * ```ts
265
+ * import { judgeGrid } from "@johnmorrisdotca/kumimoji";
266
+ *
267
+ * const tiles = new Map([["0,0","c"],["0,1","a"],["0,2","t"]]);
268
+ * console.log(judgeGrid(tiles,word=>word==="cat"));
269
+ * ```
270
+ */
100
271
  export declare function judgeGrid(tiles: Tiles, isWord: (word: string) => boolean, readable?: (word: string) => string, rules?: GridRules): GridVerdict;