scrabble-solver 2.8.5 → 2.8.7
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.
- package/README.md +31 -24
- package/lerna.json +1 -1
- package/package.json +2 -2
- package/packages/configs/build/literaki/literaki.js +2 -2
- package/packages/configs/build/scrabble/scrabble.js +2 -2
- package/packages/configs/package.json +3 -3
- package/packages/configs/src/literaki/literaki.ts +2 -2
- package/packages/configs/src/scrabble/scrabble.ts +2 -2
- package/packages/constants/package.json +1 -1
- package/packages/dictionaries/package-lock.json +2 -2
- package/packages/dictionaries/package.json +4 -4
- package/packages/logger/package-lock.json +2 -2
- package/packages/logger/package.json +1 -1
- package/packages/scrabble-solver/.next/BUILD_ID +1 -1
- package/packages/scrabble-solver/.next/build-manifest.json +9 -9
- package/packages/scrabble-solver/.next/cache/.tsbuildinfo +1 -1
- package/packages/scrabble-solver/.next/cache/eslint/.cache_8dgz12 +1 -1
- package/packages/scrabble-solver/.next/cache/next-server.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/cache/webpack/client-production/0.pack +0 -0
- package/packages/scrabble-solver/.next/cache/webpack/client-production/index.pack +0 -0
- package/packages/scrabble-solver/.next/cache/webpack/server-production/0.pack +0 -0
- package/packages/scrabble-solver/.next/cache/webpack/server-production/index.pack +0 -0
- package/packages/scrabble-solver/.next/next-server.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/prerender-manifest.json +1 -1
- package/packages/scrabble-solver/.next/routes-manifest.json +1 -1
- package/packages/scrabble-solver/.next/server/chunks/413.js +183 -94
- package/packages/scrabble-solver/.next/server/chunks/{206.js → 429.js} +2 -4137
- package/packages/scrabble-solver/.next/server/chunks/515.js +111 -78
- package/packages/scrabble-solver/.next/server/chunks/{907.js → 911.js} +134 -367
- package/packages/scrabble-solver/.next/server/chunks/939.js +218 -0
- package/packages/scrabble-solver/.next/server/middleware-build-manifest.js +1 -1
- package/packages/scrabble-solver/.next/server/pages/404.html +2 -2
- package/packages/scrabble-solver/.next/server/pages/404.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/500.html +2 -2
- package/packages/scrabble-solver/.next/server/pages/_app.js +3 -2
- package/packages/scrabble-solver/.next/server/pages/_app.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/_document.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/_error.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/api/dictionary/[locale]/[word].js +33 -17
- package/packages/scrabble-solver/.next/server/pages/api/dictionary/[locale]/[word].js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/api/solve.js +404 -58
- package/packages/scrabble-solver/.next/server/pages/api/solve.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/api/visit.js +3 -2
- package/packages/scrabble-solver/.next/server/pages/api/visit.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/index.html +3 -7
- package/packages/scrabble-solver/.next/server/pages/index.js +12 -14
- package/packages/scrabble-solver/.next/server/pages/index.js.nft.json +1 -1
- package/packages/scrabble-solver/.next/server/pages/index.json +1 -1
- package/packages/scrabble-solver/.next/static/chunks/56-cf37c430261bbea5.js +1 -0
- package/packages/scrabble-solver/.next/static/chunks/pages/_app-0b12a65bea70a0df.js +1 -0
- package/packages/scrabble-solver/.next/static/chunks/pages/index-fcb69802550afb81.js +1 -0
- package/packages/scrabble-solver/.next/static/css/1f39b55d50f5b30b.css +1 -0
- package/packages/scrabble-solver/.next/static/css/751e8a14776d05d8.css +1 -0
- package/packages/scrabble-solver/.next/static/z_0_lqfmiI_ISokr6NNRq/_buildManifest.js +1 -0
- package/packages/scrabble-solver/.next/static/{TzKQ3IntkvaYmHBkWpfoi → z_0_lqfmiI_ISokr6NNRq}/_ssgManifest.js +0 -0
- package/packages/scrabble-solver/.next/trace +40 -42
- package/packages/scrabble-solver/package-lock.json +2 -2
- package/packages/scrabble-solver/package.json +8 -8
- package/packages/scrabble-solver/src/api/index.ts +3 -9
- package/packages/scrabble-solver/src/api/isBoardValid.ts +43 -0
- package/packages/scrabble-solver/src/api/isCellValid.ts +26 -0
- package/packages/scrabble-solver/src/api/isRowValid.ts +19 -0
- package/packages/scrabble-solver/src/components/Board/Board.tsx +3 -1
- package/packages/scrabble-solver/src/components/Board/BoardPure.tsx +4 -1
- package/packages/scrabble-solver/src/components/Board/components/Cell/Cell.module.scss +28 -11
- package/packages/scrabble-solver/src/components/Board/components/Cell/Cell.tsx +12 -1
- package/packages/scrabble-solver/src/components/Board/components/Cell/CellPure.tsx +3 -1
- package/packages/scrabble-solver/src/components/Board/components/Cell/lib.ts +10 -2
- package/packages/scrabble-solver/src/components/Dictionary/Dictionary.module.scss +20 -0
- package/packages/scrabble-solver/src/components/Dictionary/Dictionary.tsx +40 -29
- package/packages/scrabble-solver/src/components/Results/Cell.tsx +3 -2
- package/packages/scrabble-solver/src/components/Results/Result.tsx +16 -6
- package/packages/scrabble-solver/src/components/ResultsInput/ResultsInput.tsx +11 -3
- package/packages/scrabble-solver/src/hooks/useIsTablet.ts +2 -2
- package/packages/scrabble-solver/src/lib/getRemainingTiles.ts +1 -1
- package/packages/scrabble-solver/src/lib/index.ts +2 -1
- package/packages/scrabble-solver/src/lib/isRegExp.ts +11 -0
- package/packages/scrabble-solver/src/lib/isStringArray.ts +5 -0
- package/packages/scrabble-solver/src/lib/sortResults.ts +5 -5
- package/packages/scrabble-solver/src/pages/_app.tsx +6 -3
- package/packages/scrabble-solver/src/pages/api/dictionary/[locale]/[word].ts +35 -11
- package/packages/scrabble-solver/src/pages/api/solve.ts +39 -19
- package/packages/scrabble-solver/src/pages/api/visit.ts +1 -0
- package/packages/scrabble-solver/src/pages/index.module.scss +5 -11
- package/packages/scrabble-solver/src/pages/index.tsx +5 -5
- package/packages/scrabble-solver/src/sdk/{findWordDefinition.ts → findWordDefinitions.ts} +3 -3
- package/packages/scrabble-solver/src/sdk/index.ts +1 -1
- package/packages/scrabble-solver/src/state/sagas.ts +11 -11
- package/packages/scrabble-solver/src/state/selectors.ts +6 -2
- package/packages/scrabble-solver/src/state/slices/dictionaryInitialState.ts +3 -3
- package/packages/scrabble-solver/src/state/slices/dictionarySlice.ts +4 -10
- package/packages/solver/build/PatternsFiller.js +1 -1
- package/packages/solver/build/PatternsGenerator.d.ts +4 -4
- package/packages/solver/build/PatternsGenerator.js +6 -6
- package/packages/solver/build/ScoresCalculator.js +1 -1
- package/packages/solver/build/Solver.js +3 -3
- package/packages/solver/build/getUniquePatterns.d.ts +3 -0
- package/packages/solver/build/getUniquePatterns.js +25 -0
- package/packages/solver/package-lock.json +3 -29
- package/packages/solver/package.json +5 -7
- package/packages/solver/src/PatternsFiller.ts +1 -1
- package/packages/solver/src/PatternsGenerator.test.ts +2 -2
- package/packages/solver/src/PatternsGenerator.ts +8 -8
- package/packages/solver/src/ScoresCalculator.ts +1 -1
- package/packages/solver/src/Solver.ts +3 -3
- package/packages/solver/src/getUniquePatterns.ts +30 -0
- package/packages/types/build/Board.d.ts +2 -2
- package/packages/types/build/Board.js +8 -8
- package/packages/types/build/BoardJson.d.ts +2 -1
- package/packages/types/build/BoardJson.js +19 -0
- package/packages/types/build/Cell.d.ts +2 -3
- package/packages/types/build/Cell.js +0 -15
- package/packages/types/build/CellJson.d.ts +1 -0
- package/packages/types/build/CellJson.js +14 -0
- package/packages/types/build/Collision.d.ts +3 -0
- package/packages/types/build/Collision.js +2 -0
- package/packages/types/build/CollisionJson.d.ts +3 -0
- package/packages/types/build/CollisionJson.js +2 -0
- package/packages/types/build/Config.d.ts +2 -2
- package/packages/types/build/Config.js +5 -5
- package/packages/types/build/ConfigJson.d.ts +2 -2
- package/packages/types/build/Locale.d.ts +1 -0
- package/packages/types/build/Locale.js +4 -0
- package/packages/types/build/Pattern.d.ts +1 -1
- package/packages/types/build/Pattern.js +4 -4
- package/packages/types/build/PatternJson.d.ts +1 -1
- package/packages/types/build/Result.d.ts +10 -8
- package/packages/types/build/Result.js +15 -10
- package/packages/types/build/ResultJson.d.ts +3 -2
- package/packages/types/build/TileJson.d.ts +1 -0
- package/packages/types/build/TileJson.js +9 -0
- package/packages/types/build/index.d.ts +7 -4
- package/packages/types/build/index.js +10 -1
- package/packages/types/build/isObject.d.ts +2 -0
- package/packages/types/build/isObject.js +6 -0
- package/packages/types/package.json +2 -2
- package/packages/types/src/Board.ts +11 -11
- package/packages/types/src/BoardJson.ts +22 -2
- package/packages/types/src/Cell.ts +2 -19
- package/packages/types/src/CellJson.ts +12 -1
- package/packages/types/src/Collision.ts +5 -0
- package/packages/types/src/CollisionJson.ts +5 -0
- package/packages/types/src/Config.ts +6 -6
- package/packages/types/src/ConfigJson.ts +2 -2
- package/packages/types/src/Locale.ts +4 -0
- package/packages/types/src/Pattern.ts +4 -5
- package/packages/types/src/PatternJson.ts +1 -1
- package/packages/types/src/Result.ts +33 -23
- package/packages/types/src/ResultJson.ts +3 -2
- package/packages/types/src/TileJson.ts +6 -0
- package/packages/types/src/index.ts +7 -4
- package/packages/types/src/isObject.ts +5 -0
- package/packages/word-definitions/package-lock.json +2 -2
- package/packages/word-definitions/package.json +2 -2
- package/packages/word-lists/build/getDeDeWordList.js +1 -1
- package/packages/word-lists/build/lib/extractWords.js +4 -1
- package/packages/word-lists/package-lock.json +2 -2
- package/packages/word-lists/package.json +2 -2
- package/packages/word-lists/src/getDeDeWordList.ts +1 -1
- package/packages/word-lists/src/lib/extractWords.ts +4 -1
- package/packages/scrabble-solver/.next/static/TzKQ3IntkvaYmHBkWpfoi/_buildManifest.js +0 -1
- package/packages/scrabble-solver/.next/static/chunks/56-2d34867599a0ac66.js +0 -1
- package/packages/scrabble-solver/.next/static/chunks/pages/_app-6ffa2ab900772b67.js +0 -1
- package/packages/scrabble-solver/.next/static/chunks/pages/index-13ea7770a65c69ee.js +0 -1
- package/packages/scrabble-solver/.next/static/css/3159cfe62ff742a3.css +0 -1
- package/packages/scrabble-solver/.next/static/css/551d09cac435debb.css +0 -1
- package/packages/scrabble-solver/src/api/validateBoard.ts +0 -45
- package/packages/scrabble-solver/src/api/validateCell.ts +0 -40
- package/packages/scrabble-solver/src/api/validateCharacter.ts +0 -14
- package/packages/scrabble-solver/src/api/validateCharacters.ts +0 -24
- package/packages/scrabble-solver/src/api/validateConfigId.ts +0 -9
- package/packages/scrabble-solver/src/api/validateLocale.ts +0 -15
- package/packages/scrabble-solver/src/api/validateRow.ts +0 -17
- package/packages/scrabble-solver/src/api/validateTile.ts +0 -21
- package/packages/scrabble-solver/src/api/validateWord.ts +0 -11
- package/packages/scrabble-solver/src/lib/isLocale.ts +0 -7
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { CellJson, Config } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
import validateRow from './validateRow';
|
|
4
|
-
|
|
5
|
-
const validateBoard = (board: unknown, config: Config): void => {
|
|
6
|
-
if (!Array.isArray(board)) {
|
|
7
|
-
throw new Error('Invalid "board" parameter: not an array');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (board.length !== config.boardHeight) {
|
|
11
|
-
throw new Error(`Invalid "board" parameter: does not have ${config.boardHeight} rows`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
board.forEach((row, rowIndex) => validateRow(row, rowIndex, config));
|
|
16
|
-
validateTwoCharacterTiles(board, config);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
const message = error instanceof Error ? error.message : 'unknown';
|
|
19
|
-
throw new Error(`Invalid "board" parameter: ${message}`);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const validateTwoCharacterTiles = (board: CellJson[][], config: Config): void => {
|
|
24
|
-
const cells: CellJson[] = board
|
|
25
|
-
.flat()
|
|
26
|
-
.filter((cell) => cell.tile && config.isTwoCharacterTilePrefix(cell.tile.character));
|
|
27
|
-
|
|
28
|
-
for (const cell of cells) {
|
|
29
|
-
for (const characters of config.twoCharacterTiles) {
|
|
30
|
-
const canCheckDown = cell.y + 1 < board.length;
|
|
31
|
-
const canCheckRight = cell.x + 1 < board[0].length;
|
|
32
|
-
const cellDown = board[cell.y + 1][cell.x];
|
|
33
|
-
const cellRight = board[cell.y][cell.x + 1];
|
|
34
|
-
const collidesDown = canCheckDown && cellDown.tile && cellDown.tile.character === characters[1];
|
|
35
|
-
const collidesRight = canCheckRight && cellRight.tile && cellRight.tile.character === characters[1];
|
|
36
|
-
const collides = collidesDown || collidesRight;
|
|
37
|
-
|
|
38
|
-
if (cell.tile && characters.startsWith(cell.tile.character) && collides) {
|
|
39
|
-
throw new Error(`${characters} can only be used as a single tile`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default validateBoard;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Config } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
import validateTile from './validateTile';
|
|
4
|
-
|
|
5
|
-
const validateCell = (cell: unknown, rowIndex: number, cellIndex: number, config: Config): void => {
|
|
6
|
-
if (typeof cell !== 'object') {
|
|
7
|
-
throw new Error(`board[${rowIndex}][${cellIndex}] is not an object`);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const { x, y, tile, isEmpty } = cell as Record<string, unknown>;
|
|
11
|
-
|
|
12
|
-
if (typeof x !== 'number') {
|
|
13
|
-
throw new Error(`board[${rowIndex}][${cellIndex}].x is not a number`);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (x < 0 || x >= config.boardWidth) {
|
|
17
|
-
throw new Error(`board[${rowIndex}][${cellIndex}].x is out of bounds`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (typeof y !== 'number') {
|
|
21
|
-
throw new Error(`board[${rowIndex}][${cellIndex}].y is not a number`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (y < 0 || y >= config.boardHeight) {
|
|
25
|
-
throw new Error(`board[${rowIndex}][${cellIndex}].y is out of bounds`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (typeof isEmpty !== 'boolean') {
|
|
29
|
-
throw new Error(`board[${rowIndex}][${cellIndex}].isEmpty is not a boolean`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
validateTile(tile, config);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
const message = error instanceof Error ? error.message : 'unknown';
|
|
36
|
-
throw new Error(`board[${rowIndex}][${cellIndex}].tile ${message}`);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export default validateCell;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BLANK } from '@scrabble-solver/constants';
|
|
2
|
-
import { Config } from '@scrabble-solver/types';
|
|
3
|
-
|
|
4
|
-
const validateCharacter = (character: unknown, config: Config): void => {
|
|
5
|
-
if (typeof character !== 'string') {
|
|
6
|
-
throw new Error('character is not a string');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (!config.hasCharacter(character) && character !== BLANK) {
|
|
10
|
-
throw new Error('character is not valid');
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default validateCharacter;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Config } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
import validateCharacter from './validateCharacter';
|
|
4
|
-
|
|
5
|
-
const validateCharacters = (characters: unknown, config: Config): void => {
|
|
6
|
-
if (!Array.isArray(characters)) {
|
|
7
|
-
throw new Error('Invalid "characters" parameter: not an array');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (characters.length === 0) {
|
|
11
|
-
throw new Error('Invalid "characters" parameter: empty array');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
characters.forEach((character, characterIndex) => {
|
|
15
|
-
try {
|
|
16
|
-
validateCharacter(character, config);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
const message = error instanceof Error ? error.message : 'unknown';
|
|
19
|
-
throw new Error(`Invalid "characters" parameter: characters[${characterIndex}] ${message}`);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default validateCharacters;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Locale } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
const locales = Object.values(Locale);
|
|
4
|
-
|
|
5
|
-
const validateLocale = (locale: unknown): void => {
|
|
6
|
-
if (typeof locale !== 'string') {
|
|
7
|
-
throw new Error('Invalid "locale" parameter: not a string');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (!locales.includes(locale as Locale)) {
|
|
11
|
-
throw new Error(`Invalid "locale" parameter: must be one of: ${locales.join(', ')}`);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default validateLocale;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Config } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
import validateCell from './validateCell';
|
|
4
|
-
|
|
5
|
-
const validateRow = (row: unknown, rowIndex: number, config: Config): void => {
|
|
6
|
-
if (!Array.isArray(row)) {
|
|
7
|
-
throw new Error(`board[${rowIndex}] is not an array`);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (row.length !== config.boardWidth) {
|
|
11
|
-
throw new Error(`board[${rowIndex}] does not have ${config.boardWidth} cells`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
row.forEach((cell, cellIndex) => validateCell(cell, rowIndex, cellIndex, config));
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default validateRow;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Config } from '@scrabble-solver/types';
|
|
2
|
-
|
|
3
|
-
import validateCharacter from './validateCharacter';
|
|
4
|
-
|
|
5
|
-
const validateTile = (tile: unknown, config: Config): void => {
|
|
6
|
-
if (typeof tile !== 'object') {
|
|
7
|
-
throw new Error('is not an object');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (tile !== null) {
|
|
11
|
-
const { character, isBlank } = tile as Record<string, unknown>;
|
|
12
|
-
|
|
13
|
-
validateCharacter(character, config);
|
|
14
|
-
|
|
15
|
-
if (typeof isBlank !== 'boolean') {
|
|
16
|
-
throw new Error('isBlank is not a boolean');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default validateTile;
|