scrabble-solver 2.8.3 → 2.8.5

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 (102) hide show
  1. package/.gitattributes +2 -0
  2. package/HISTORY.md +17 -0
  3. package/README.md +8 -26
  4. package/lerna.json +1 -1
  5. package/package.json +13 -13
  6. package/packages/configs/package.json +3 -3
  7. package/packages/constants/package.json +1 -1
  8. package/packages/dictionaries/build/lib/DiskCache.js +2 -4
  9. package/packages/dictionaries/build/lib/index.d.ts +0 -2
  10. package/packages/dictionaries/build/lib/index.js +1 -5
  11. package/packages/dictionaries/package-lock.json +10 -10
  12. package/packages/dictionaries/package.json +5 -5
  13. package/packages/dictionaries/src/lib/DiskCache.ts +2 -4
  14. package/packages/dictionaries/src/lib/index.ts +0 -2
  15. package/packages/logger/package-lock.json +2 -2
  16. package/packages/logger/package.json +1 -1
  17. package/packages/scrabble-solver/.next/BUILD_ID +1 -1
  18. package/packages/scrabble-solver/.next/build-manifest.json +10 -10
  19. package/packages/scrabble-solver/.next/cache/.tsbuildinfo +1 -1
  20. package/packages/scrabble-solver/.next/cache/eslint/.cache_8dgz12 +1 -1
  21. package/packages/scrabble-solver/.next/cache/next-server.js.nft.json +1 -1
  22. package/packages/scrabble-solver/.next/cache/webpack/client-production/0.pack +0 -0
  23. package/packages/scrabble-solver/.next/cache/webpack/client-production/index.pack +0 -0
  24. package/packages/scrabble-solver/.next/cache/webpack/server-production/0.pack +0 -0
  25. package/packages/scrabble-solver/.next/cache/webpack/server-production/index.pack +0 -0
  26. package/packages/scrabble-solver/.next/next-server.js.nft.json +1 -1
  27. package/packages/scrabble-solver/.next/prerender-manifest.json +1 -1
  28. package/packages/scrabble-solver/.next/routes-manifest.json +1 -1
  29. package/packages/scrabble-solver/.next/server/chunks/206.js +98 -97
  30. package/packages/scrabble-solver/.next/server/chunks/413.js +5 -4
  31. package/packages/scrabble-solver/.next/server/chunks/515.js +135 -53
  32. package/packages/scrabble-solver/.next/server/chunks/907.js +2 -2
  33. package/packages/scrabble-solver/.next/server/middleware-build-manifest.js +1 -1
  34. package/packages/scrabble-solver/.next/server/pages/404.html +5 -1
  35. package/packages/scrabble-solver/.next/server/pages/404.js.nft.json +1 -1
  36. package/packages/scrabble-solver/.next/server/pages/500.html +2 -2
  37. package/packages/scrabble-solver/.next/server/pages/_app.js.nft.json +1 -1
  38. package/packages/scrabble-solver/.next/server/pages/_error.js.nft.json +1 -1
  39. package/packages/scrabble-solver/.next/server/pages/api/dictionary/[locale]/[word].js +1 -1
  40. package/packages/scrabble-solver/.next/server/pages/api/solve.js +50 -94
  41. package/packages/scrabble-solver/.next/server/pages/index.html +17 -1
  42. package/packages/scrabble-solver/.next/server/pages/index.js +5 -12
  43. package/packages/scrabble-solver/.next/server/pages/index.js.nft.json +1 -1
  44. package/packages/scrabble-solver/.next/server/pages/index.json +1 -1
  45. package/packages/scrabble-solver/.next/static/TzKQ3IntkvaYmHBkWpfoi/_buildManifest.js +1 -0
  46. package/packages/scrabble-solver/.next/static/{OhUvTNKwyrrzmNwKBnpUU → TzKQ3IntkvaYmHBkWpfoi}/_ssgManifest.js +0 -0
  47. package/packages/scrabble-solver/.next/static/chunks/56-2d34867599a0ac66.js +1 -0
  48. package/packages/scrabble-solver/.next/static/chunks/pages/{404-02d949d2fe59e960.js → 404-30c06e61d256c5b2.js} +1 -1
  49. package/packages/scrabble-solver/.next/static/chunks/pages/_app-6ffa2ab900772b67.js +1 -0
  50. package/packages/scrabble-solver/.next/static/chunks/pages/{index-75517525489ab316.js → index-13ea7770a65c69ee.js} +1 -1
  51. package/packages/scrabble-solver/.next/static/css/{d676d43c6b9c9a57.css → 551d09cac435debb.css} +1 -1
  52. package/packages/scrabble-solver/.next/static/css/{6a9e5ba3f77c27f2.css → cdbc9e0afcff5473.css} +1 -1
  53. package/packages/scrabble-solver/.next/trace +42 -42
  54. package/packages/scrabble-solver/package-lock.json +85 -85
  55. package/packages/scrabble-solver/package.json +13 -13
  56. package/packages/scrabble-solver/src/components/Board/hooks/useGrid.ts +9 -0
  57. package/packages/scrabble-solver/src/components/KeyMap/KeyMap.tsx +1 -1
  58. package/packages/scrabble-solver/src/components/KeyMap/components/Mapping/Mapping.module.scss +4 -0
  59. package/packages/scrabble-solver/src/components/KeyMap/components/Mapping/Mapping.tsx +16 -12
  60. package/packages/scrabble-solver/src/components/PlainTiles/PlainTiles.tsx +4 -0
  61. package/packages/scrabble-solver/src/components/SvgFontCss/SvgFontCss.tsx +12 -0
  62. package/packages/scrabble-solver/src/components/SvgFontCss/index.ts +1 -0
  63. package/packages/scrabble-solver/src/components/Tile/TilePure.tsx +1 -1
  64. package/packages/scrabble-solver/src/components/index.ts +1 -0
  65. package/packages/scrabble-solver/src/lib/createKeyboardNavigation.ts +3 -0
  66. package/packages/scrabble-solver/src/pages/index.tsx +5 -14
  67. package/packages/scrabble-solver/src/styles/global.scss +3 -0
  68. package/packages/solver/build/PatternsFiller.js +2 -6
  69. package/packages/solver/build/PatternsGenerator.js +13 -9
  70. package/packages/solver/build/Solver.js +3 -4
  71. package/packages/solver/package-lock.json +17 -17
  72. package/packages/solver/package.json +7 -7
  73. package/packages/solver/src/PatternsFiller.ts +2 -8
  74. package/packages/solver/src/PatternsGenerator.ts +17 -16
  75. package/packages/solver/src/Solver.ts +4 -8
  76. package/packages/types/build/Cell.js +1 -1
  77. package/packages/types/build/Pattern.js +1 -1
  78. package/packages/types/package.json +2 -2
  79. package/packages/types/src/Cell.ts +1 -1
  80. package/packages/types/src/Pattern.ts +1 -1
  81. package/packages/word-definitions/build/crawl/crawlGerman.js +1 -1
  82. package/packages/word-definitions/package-lock.json +8 -8
  83. package/packages/word-definitions/package.json +2 -2
  84. package/packages/word-definitions/src/crawl/crawlGerman.ts +1 -1
  85. package/packages/word-lists/build/getPlPlWordList.js +2 -3
  86. package/packages/word-lists/build/lib/downloadFile.d.ts +1 -2
  87. package/packages/word-lists/build/lib/downloadFile.js +24 -6
  88. package/packages/word-lists/build/lib/getTxtWordList.js +2 -4
  89. package/packages/word-lists/package-lock.json +2 -2
  90. package/packages/word-lists/package.json +2 -2
  91. package/packages/word-lists/src/getPlPlWordList.ts +2 -3
  92. package/packages/word-lists/src/lib/downloadFile.ts +25 -7
  93. package/packages/word-lists/src/lib/getTxtWordList.ts +2 -4
  94. package/packages/dictionaries/build/lib/readFile.d.ts +0 -2
  95. package/packages/dictionaries/build/lib/readFile.js +0 -19
  96. package/packages/dictionaries/build/lib/writeFile.d.ts +0 -2
  97. package/packages/dictionaries/build/lib/writeFile.js +0 -19
  98. package/packages/dictionaries/src/lib/readFile.ts +0 -15
  99. package/packages/dictionaries/src/lib/writeFile.ts +0 -15
  100. package/packages/scrabble-solver/.next/static/OhUvTNKwyrrzmNwKBnpUU/_buildManifest.js +0 -1
  101. package/packages/scrabble-solver/.next/static/chunks/195-4b75c9c697b7b455.js +0 -1
  102. package/packages/scrabble-solver/.next/static/chunks/pages/_app-72522bfb306a8aef.js +0 -1
@@ -35,16 +35,20 @@ class PatternsGenerator {
35
35
  .map((_, index) => getNthVector(index));
36
36
  }
37
37
  generateCellsPatterns({ board, cells, PatternModel, }) {
38
- return this.generateStartIndices(cells).reduce((patterns, startIndex) => patterns.concat(this.generateEndIndices(cells, startIndex).reduce((placeablePatterns, endIndex) => {
39
- const pattern = new PatternModel({
40
- board,
41
- cells: cells.slice(startIndex, endIndex + 1),
42
- });
43
- if (pattern.canBePlaced(this.config)) {
44
- placeablePatterns.push(pattern);
38
+ return this.generateStartIndices(cells).flatMap((startIndex) => {
39
+ const endIndices = this.generateEndIndices(cells, startIndex);
40
+ const patterns = [];
41
+ for (const endIndex of endIndices) {
42
+ const pattern = new PatternModel({
43
+ board,
44
+ cells: cells.slice(startIndex, endIndex + 1),
45
+ });
46
+ if (pattern.canBePlaced(this.config)) {
47
+ patterns.push(pattern);
48
+ }
45
49
  }
46
- return placeablePatterns;
47
- }, [])), []);
50
+ return patterns;
51
+ });
48
52
  }
49
53
  generateStartIndices(cells) {
50
54
  return Array(cells.length - 1)
@@ -15,10 +15,9 @@ class Solver {
15
15
  this.scoresCalculator = new ScoresCalculator_1.default(config);
16
16
  }
17
17
  solve(board, tiles) {
18
- const patterns = this.patternsGenerator
19
- .generate(board)
20
- .reduce((filledPatterns, pattern) => filledPatterns.concat(this.patternsFiller.fill(pattern, tiles)), []);
21
- const uniquePatterns = (0, uniqBy_1.default)(patterns, (pattern) => JSON.stringify(pattern.toJson()));
18
+ const patterns = this.patternsGenerator.generate(board);
19
+ const filledPatterns = patterns.flatMap((pattern) => this.patternsFiller.fill(pattern, tiles));
20
+ const uniquePatterns = (0, uniqBy_1.default)(filledPatterns, (pattern) => JSON.stringify(pattern.toJson()));
22
21
  const results = uniquePatterns.map((pattern, index) => new types_1.Result({
23
22
  cells: pattern.cells,
24
23
  id: index,
@@ -1,33 +1,33 @@
1
1
  {
2
2
  "name": "@scrabble-solver/solver",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@scrabble-solver/solver",
9
- "version": "2.8.3",
9
+ "version": "2.8.5",
10
10
  "license": "CC-BY-NC-ND-4.0",
11
11
  "dependencies": {
12
- "@kamilmielnik/trie": "^1.0.3",
12
+ "@kamilmielnik/trie": "^2.0.0",
13
13
  "lodash": "^4.17.21"
14
14
  },
15
15
  "devDependencies": {
16
- "@types/lodash": "^4.14.185"
16
+ "@types/lodash": "^4.14.186"
17
17
  }
18
18
  },
19
19
  "node_modules/@kamilmielnik/trie": {
20
- "version": "1.0.3",
21
- "resolved": "https://registry.npmjs.org/@kamilmielnik/trie/-/trie-1.0.3.tgz",
22
- "integrity": "sha512-xIGglzz91BwfudrsNoxX0nRlfUrGu7Y9QxJ5RnrapLGZAer02CiVayBP00gndpkP3xjmueI9l49xb4W3JgcLXA==",
20
+ "version": "2.0.0",
21
+ "resolved": "https://registry.npmjs.org/@kamilmielnik/trie/-/trie-2.0.0.tgz",
22
+ "integrity": "sha512-YWTYtrV97bQ5hRifG1FImP47PI400a56O8+oQClQOtDjY3tioxab4sOgFHckiDdswciN1RwngCZ9Kv3phJfSuA==",
23
23
  "engines": {
24
- "node": ">=10"
24
+ "node": ">=16"
25
25
  }
26
26
  },
27
27
  "node_modules/@types/lodash": {
28
- "version": "4.14.185",
29
- "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.185.tgz",
30
- "integrity": "sha512-evMDG1bC4rgQg4ku9tKpuMh5iBNEwNa3tf9zRHdP1qlv+1WUg44xat4IxCE14gIpZRGUUWAx2VhItCZc25NfMA==",
28
+ "version": "4.14.186",
29
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.186.tgz",
30
+ "integrity": "sha512-eHcVlLXP0c2FlMPm56ITode2AgLMSa6aJ05JTTbYbI+7EMkCEE5qk2E41d5g2lCVTqRe0GnnRFurmlCsDODrPw==",
31
31
  "dev": true
32
32
  },
33
33
  "node_modules/lodash": {
@@ -38,14 +38,14 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@kamilmielnik/trie": {
41
- "version": "1.0.3",
42
- "resolved": "https://registry.npmjs.org/@kamilmielnik/trie/-/trie-1.0.3.tgz",
43
- "integrity": "sha512-xIGglzz91BwfudrsNoxX0nRlfUrGu7Y9QxJ5RnrapLGZAer02CiVayBP00gndpkP3xjmueI9l49xb4W3JgcLXA=="
41
+ "version": "2.0.0",
42
+ "resolved": "https://registry.npmjs.org/@kamilmielnik/trie/-/trie-2.0.0.tgz",
43
+ "integrity": "sha512-YWTYtrV97bQ5hRifG1FImP47PI400a56O8+oQClQOtDjY3tioxab4sOgFHckiDdswciN1RwngCZ9Kv3phJfSuA=="
44
44
  },
45
45
  "@types/lodash": {
46
- "version": "4.14.185",
47
- "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.185.tgz",
48
- "integrity": "sha512-evMDG1bC4rgQg4ku9tKpuMh5iBNEwNa3tf9zRHdP1qlv+1WUg44xat4IxCE14gIpZRGUUWAx2VhItCZc25NfMA==",
46
+ "version": "4.14.186",
47
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.186.tgz",
48
+ "integrity": "sha512-eHcVlLXP0c2FlMPm56ITode2AgLMSa6aJ05JTTbYbI+7EMkCEE5qk2E41d5g2lCVTqRe0GnnRFurmlCsDODrPw==",
49
49
  "dev": true
50
50
  },
51
51
  "lodash": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/solver",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "description": "Scrabble Solver 2 - Solver",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -24,15 +24,15 @@
24
24
  "clean:force": "npm run clean && rimraf package-lock.json"
25
25
  },
26
26
  "dependencies": {
27
- "@kamilmielnik/trie": "^1.0.3",
28
- "@scrabble-solver/types": "^2.8.3",
27
+ "@kamilmielnik/trie": "^2.0.0",
28
+ "@scrabble-solver/types": "^2.8.5",
29
29
  "lodash": "^4.17.21"
30
30
  },
31
31
  "devDependencies": {
32
- "@scrabble-solver/configs": "^2.8.3",
33
- "@scrabble-solver/constants": "^2.8.3",
34
- "@scrabble-solver/dictionaries": "^2.8.3",
35
- "@types/lodash": "^4.14.185"
32
+ "@scrabble-solver/configs": "^2.8.5",
33
+ "@scrabble-solver/constants": "^2.8.5",
34
+ "@scrabble-solver/dictionaries": "^2.8.5",
35
+ "@types/lodash": "^4.14.186"
36
36
  },
37
37
  "gitHead": "1e2d1ad49a288d4a44196d8e3336740da132c637"
38
38
  }
@@ -24,7 +24,7 @@ class PatternsFiller {
24
24
 
25
25
  for (let index = 0; index < tilesPermutations.length; ++index) {
26
26
  const tilesPermutation = tilesPermutations[index];
27
- this.fillPattern(pattern, String(pattern), tilesPermutation, onPatternFound);
27
+ this.fillPattern(pattern, pattern.toString(), tilesPermutation, onPatternFound);
28
28
  }
29
29
 
30
30
  return patterns;
@@ -66,13 +66,7 @@ class PatternsFiller {
66
66
  }
67
67
 
68
68
  public canAddPattern(pattern: Pattern, word: string): boolean {
69
- return (
70
- this.trie.has(word) &&
71
- pattern
72
- .getCollisions()
73
- .map(String)
74
- .every((collision) => this.trie.has(collision))
75
- );
69
+ return this.trie.has(word) && pattern.getCollisions().every((collision) => this.trie.has(collision.toString()));
76
70
  }
77
71
 
78
72
  public generateBlankTilesPermutations(tiles: Tile[]): Tile[][] {
@@ -66,22 +66,23 @@ class PatternsGenerator {
66
66
  cells: Cell[];
67
67
  PatternModel: new (parameters: { board: Board; cells: Cell[] }) => P;
68
68
  }): P[] {
69
- return this.generateStartIndices(cells).reduce<P[]>(
70
- (patterns, startIndex) =>
71
- patterns.concat(
72
- this.generateEndIndices(cells, startIndex).reduce<P[]>((placeablePatterns, endIndex) => {
73
- const pattern = new PatternModel({
74
- board,
75
- cells: cells.slice(startIndex, endIndex + 1),
76
- });
77
- if (pattern.canBePlaced(this.config)) {
78
- placeablePatterns.push(pattern);
79
- }
80
- return placeablePatterns;
81
- }, []),
82
- ),
83
- [],
84
- );
69
+ return this.generateStartIndices(cells).flatMap((startIndex) => {
70
+ const endIndices = this.generateEndIndices(cells, startIndex);
71
+ const patterns: P[] = [];
72
+
73
+ for (const endIndex of endIndices) {
74
+ const pattern = new PatternModel({
75
+ board,
76
+ cells: cells.slice(startIndex, endIndex + 1),
77
+ });
78
+
79
+ if (pattern.canBePlaced(this.config)) {
80
+ patterns.push(pattern);
81
+ }
82
+ }
83
+
84
+ return patterns;
85
+ });
85
86
  }
86
87
 
87
88
  public generateStartIndices(cells: Cell[]): number[] {
@@ -1,5 +1,5 @@
1
1
  import { Trie } from '@kamilmielnik/trie';
2
- import { Board, Config, Pattern, Result, Tile } from '@scrabble-solver/types';
2
+ import { Board, Config, Result, Tile } from '@scrabble-solver/types';
3
3
  import uniqBy from 'lodash/uniqBy';
4
4
 
5
5
  import PatternsFiller from './PatternsFiller';
@@ -20,13 +20,9 @@ class Solver {
20
20
  }
21
21
 
22
22
  public solve(board: Board, tiles: Tile[]): Result[] {
23
- const patterns = this.patternsGenerator
24
- .generate(board)
25
- .reduce<Pattern[]>(
26
- (filledPatterns, pattern) => filledPatterns.concat(this.patternsFiller.fill(pattern, tiles)),
27
- [],
28
- );
29
- const uniquePatterns = uniqBy(patterns, (pattern) => JSON.stringify(pattern.toJson()));
23
+ const patterns = this.patternsGenerator.generate(board);
24
+ const filledPatterns = patterns.flatMap((pattern) => this.patternsFiller.fill(pattern, tiles));
25
+ const uniquePatterns = uniqBy(filledPatterns, (pattern) => JSON.stringify(pattern.toJson()));
30
26
  const results = uniquePatterns.map(
31
27
  (pattern, index) =>
32
28
  new Result({
@@ -49,7 +49,7 @@ class Cell {
49
49
  };
50
50
  }
51
51
  toString() {
52
- return String(this.tile);
52
+ return this.tile.toString();
53
53
  }
54
54
  }
55
55
  Cell.Null = Object.freeze({
@@ -46,7 +46,7 @@ class Pattern {
46
46
  };
47
47
  }
48
48
  toString() {
49
- return this.cells.map(String).join('');
49
+ return this.cells.reduce((result, cell) => result + cell.toString(), '');
50
50
  }
51
51
  }
52
52
  exports.default = Pattern;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/types",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "description": "Scrabble Solver 2 - Types",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "clean:force": "npm run clean && rimraf package-lock.json"
25
25
  },
26
26
  "dependencies": {
27
- "@scrabble-solver/constants": "^2.8.3"
27
+ "@scrabble-solver/constants": "^2.8.5"
28
28
  },
29
29
  "gitHead": "1e2d1ad49a288d4a44196d8e3336740da132c637"
30
30
  }
@@ -75,7 +75,7 @@ class Cell {
75
75
  }
76
76
 
77
77
  public toString(): string {
78
- return String(this.tile);
78
+ return this.tile.toString();
79
79
  }
80
80
  }
81
81
 
@@ -67,7 +67,7 @@ class Pattern {
67
67
  }
68
68
 
69
69
  public toString(): string {
70
- return this.cells.map(String).join('');
70
+ return this.cells.reduce((result, cell) => result + cell.toString(), '');
71
71
  }
72
72
  }
73
73
 
@@ -5,7 +5,7 @@ const crawlGerman = (word) => {
5
5
  return (0, lib_1.request)({
6
6
  protocol: 'https',
7
7
  hostname: 'www.dwds.de',
8
- path: `?q=${encodeURIComponent(word)}&from=wb`,
8
+ path: `/wb/${encodeURIComponent(word)}`,
9
9
  });
10
10
  };
11
11
  exports.default = crawlGerman;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-definitions",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@scrabble-solver/word-definitions",
9
- "version": "2.8.3",
9
+ "version": "2.8.5",
10
10
  "license": "CC-BY-NC-ND-4.0",
11
11
  "dependencies": {
12
12
  "cheerio": "^1.0.0-rc.12",
@@ -27,9 +27,9 @@
27
27
  }
28
28
  },
29
29
  "node_modules/@types/node": {
30
- "version": "18.7.23",
31
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
32
- "integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg==",
30
+ "version": "18.8.3",
31
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
32
+ "integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w==",
33
33
  "dev": true
34
34
  },
35
35
  "node_modules/boolbase": {
@@ -249,9 +249,9 @@
249
249
  }
250
250
  },
251
251
  "@types/node": {
252
- "version": "18.7.23",
253
- "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
254
- "integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg==",
252
+ "version": "18.8.3",
253
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
254
+ "integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w==",
255
255
  "dev": true
256
256
  },
257
257
  "boolbase": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-definitions",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "description": "Scrabble Solver 2 - Word definitions",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "clean": "rimraf build/ node_modules/ package-lock.json"
24
24
  },
25
25
  "dependencies": {
26
- "@scrabble-solver/types": "^2.8.3",
26
+ "@scrabble-solver/types": "^2.8.5",
27
27
  "cheerio": "^1.0.0-rc.12",
28
28
  "follow-redirects": "^1.15.2",
29
29
  "striptags": "^3.2.0"
@@ -4,7 +4,7 @@ const crawlGerman = (word: string): Promise<string> => {
4
4
  return request({
5
5
  protocol: 'https',
6
6
  hostname: 'www.dwds.de',
7
- path: `?q=${encodeURIComponent(word)}&from=wb`,
7
+ path: `/wb/${encodeURIComponent(word)}`,
8
8
  });
9
9
  };
10
10
 
@@ -11,15 +11,14 @@ const lib_1 = require("./lib");
11
11
  const PAGE_URL = 'https://sjp.pl/sl/growy/';
12
12
  const FILE_TO_EXTRACT_FROM_ZIP = 'slowa.txt';
13
13
  const getPlPlWordList = async () => {
14
- const zipTempFilename = (0, lib_1.getTempFilename)();
15
14
  const tempFilename = (0, lib_1.getTempFilename)();
16
15
  const zipUrl = await fetchZipUrl(PAGE_URL);
17
- await (0, lib_1.downloadFile)(zipUrl, memfs_1.fs.createWriteStream(zipTempFilename));
16
+ const zipTempFilename = await (0, lib_1.downloadFile)(zipUrl);
18
17
  await unzip(zipTempFilename, tempFilename);
19
18
  memfs_1.fs.unlinkSync(zipTempFilename);
20
19
  const file = memfs_1.fs.readFileSync(tempFilename, 'utf-8');
21
20
  memfs_1.fs.unlinkSync(tempFilename);
22
- const words = (0, lib_1.extractWords)(file.toString());
21
+ const words = (0, lib_1.extractWords)(file.toLocaleString());
23
22
  return words;
24
23
  };
25
24
  const fetchZipUrl = async (url) => {
@@ -1,3 +1,2 @@
1
- import { Writable } from 'stream';
2
- declare const downloadFile: (url: string, outputStream: Writable) => Promise<void>;
1
+ declare const downloadFile: (url: string) => Promise<string>;
3
2
  export default downloadFile;
@@ -1,19 +1,37 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const follow_redirects_1 = require("follow-redirects");
4
- const downloadFile = (url, outputStream) => {
7
+ const memfs_1 = require("memfs");
8
+ const getTempFilename_1 = __importDefault(require("./getTempFilename"));
9
+ const downloadFile = (url) => {
5
10
  return new Promise((resolve, reject) => {
11
+ const tempFilename = (0, getTempFilename_1.default)();
6
12
  const protocol = url.startsWith('https') ? follow_redirects_1.https : follow_redirects_1.http;
13
+ const writeStream = memfs_1.fs.createWriteStream(tempFilename);
7
14
  const request = protocol.get(url, (response) => {
8
15
  if (typeof response.statusCode === 'undefined' || response.statusCode >= 400) {
9
- reject();
16
+ reject(new Error(`Cannot download file: ${url}`));
10
17
  return;
11
18
  }
12
- response.pipe(outputStream);
13
- response.on('error', reject);
14
- response.on('end', resolve);
19
+ response.on('error', (error) => {
20
+ writeStream.close();
21
+ reject(error);
22
+ });
23
+ response.on('end', () => {
24
+ writeStream.on('finish', () => {
25
+ writeStream.close();
26
+ resolve(tempFilename);
27
+ });
28
+ });
29
+ response.pipe(writeStream);
30
+ });
31
+ request.on('error', (error) => {
32
+ writeStream.close();
33
+ reject(error);
15
34
  });
16
- request.on('error', reject);
17
35
  });
18
36
  };
19
37
  exports.default = downloadFile;
@@ -6,12 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const memfs_1 = require("memfs");
7
7
  const downloadFile_1 = __importDefault(require("./downloadFile"));
8
8
  const extractWords_1 = __importDefault(require("./extractWords"));
9
- const getTempFilename_1 = __importDefault(require("./getTempFilename"));
10
9
  const getTxtWordList = async (url) => {
11
- const tempFilename = (0, getTempFilename_1.default)();
12
- await (0, downloadFile_1.default)(url, memfs_1.fs.createWriteStream(tempFilename));
10
+ const tempFilename = await (0, downloadFile_1.default)(url);
13
11
  const file = memfs_1.fs.readFileSync(tempFilename, 'utf-8');
14
- const words = (0, extractWords_1.default)(file.toString());
12
+ const words = (0, extractWords_1.default)(file.toLocaleString());
15
13
  memfs_1.fs.unlinkSync(tempFilename);
16
14
  return words;
17
15
  };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-lists",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@scrabble-solver/word-lists",
9
- "version": "2.8.3",
9
+ "version": "2.8.5",
10
10
  "license": "CC-BY-NC-ND-4.0",
11
11
  "dependencies": {
12
12
  "cheerio": "^1.0.0-rc.12",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-lists",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "description": "Scrabble Solver 2 - Word lists",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "clean:force": "npm run clean && rimraf package-lock.json"
25
25
  },
26
26
  "dependencies": {
27
- "@scrabble-solver/types": "^2.8.3",
27
+ "@scrabble-solver/types": "^2.8.5",
28
28
  "cheerio": "^1.0.0-rc.12",
29
29
  "follow-redirects": "^1.15.2",
30
30
  "memfs": "^3.4.7",
@@ -9,15 +9,14 @@ const PAGE_URL = 'https://sjp.pl/sl/growy/';
9
9
  const FILE_TO_EXTRACT_FROM_ZIP = 'slowa.txt';
10
10
 
11
11
  const getPlPlWordList = async (): Promise<string[]> => {
12
- const zipTempFilename = getTempFilename();
13
12
  const tempFilename = getTempFilename();
14
13
  const zipUrl = await fetchZipUrl(PAGE_URL);
15
- await downloadFile(zipUrl, fs.createWriteStream(zipTempFilename));
14
+ const zipTempFilename = await downloadFile(zipUrl);
16
15
  await unzip(zipTempFilename, tempFilename);
17
16
  fs.unlinkSync(zipTempFilename);
18
17
  const file = fs.readFileSync(tempFilename, 'utf-8');
19
18
  fs.unlinkSync(tempFilename);
20
- const words = extractWords(file.toString());
19
+ const words = extractWords(file.toLocaleString());
21
20
  return words;
22
21
  };
23
22
 
@@ -1,20 +1,38 @@
1
1
  import { http, https } from 'follow-redirects';
2
- import { Writable } from 'stream';
2
+ import { fs } from 'memfs';
3
3
 
4
- const downloadFile = (url: string, outputStream: Writable): Promise<void> => {
4
+ import getTempFilename from './getTempFilename';
5
+
6
+ const downloadFile = (url: string): Promise<string> => {
5
7
  return new Promise((resolve, reject) => {
8
+ const tempFilename = getTempFilename();
6
9
  const protocol = url.startsWith('https') ? https : http;
10
+ const writeStream = fs.createWriteStream(tempFilename);
7
11
  const request = protocol.get(url, (response) => {
8
12
  if (typeof response.statusCode === 'undefined' || response.statusCode >= 400) {
9
- reject();
13
+ reject(new Error(`Cannot download file: ${url}`));
10
14
  return;
11
15
  }
12
16
 
13
- response.pipe(outputStream);
14
- response.on('error', reject);
15
- response.on('end', resolve);
17
+ response.on('error', (error) => {
18
+ writeStream.close();
19
+ reject(error);
20
+ });
21
+
22
+ response.on('end', () => {
23
+ writeStream.on('finish', () => {
24
+ writeStream.close();
25
+ resolve(tempFilename);
26
+ });
27
+ });
28
+
29
+ response.pipe(writeStream);
30
+ });
31
+
32
+ request.on('error', (error) => {
33
+ writeStream.close();
34
+ reject(error);
16
35
  });
17
- request.on('error', reject);
18
36
  });
19
37
  };
20
38
 
@@ -2,13 +2,11 @@ import { fs } from 'memfs';
2
2
 
3
3
  import downloadFile from './downloadFile';
4
4
  import extractWords from './extractWords';
5
- import getTempFilename from './getTempFilename';
6
5
 
7
6
  const getTxtWordList = async (url: string): Promise<string[]> => {
8
- const tempFilename = getTempFilename();
9
- await downloadFile(url, fs.createWriteStream(tempFilename));
7
+ const tempFilename = await downloadFile(url);
10
8
  const file = fs.readFileSync(tempFilename, 'utf-8');
11
- const words = extractWords(file.toString());
9
+ const words = extractWords(file.toLocaleString());
12
10
  fs.unlinkSync(tempFilename);
13
11
  return words;
14
12
  };
@@ -1,2 +0,0 @@
1
- declare const readFile: (filepath: string) => Promise<string>;
2
- export default readFile;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const readFile = async (filepath) => {
8
- return new Promise((resolve, reject) => {
9
- fs_1.default.readFile(filepath, { encoding: 'utf-8' }, (error, data) => {
10
- if (error) {
11
- reject();
12
- }
13
- else {
14
- resolve(data.toString());
15
- }
16
- });
17
- });
18
- };
19
- exports.default = readFile;
@@ -1,2 +0,0 @@
1
- declare const writeFile: (filepath: string, data: string) => Promise<void>;
2
- export default writeFile;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const writeFile = async (filepath, data) => {
8
- return new Promise((resolve, reject) => {
9
- fs_1.default.writeFile(filepath, data, (error) => {
10
- if (error) {
11
- reject();
12
- }
13
- else {
14
- resolve();
15
- }
16
- });
17
- });
18
- };
19
- exports.default = writeFile;
@@ -1,15 +0,0 @@
1
- import fs from 'fs';
2
-
3
- const readFile = async (filepath: string): Promise<string> => {
4
- return new Promise((resolve, reject) => {
5
- fs.readFile(filepath, { encoding: 'utf-8' }, (error, data) => {
6
- if (error) {
7
- reject();
8
- } else {
9
- resolve(data.toString());
10
- }
11
- });
12
- });
13
- };
14
-
15
- export default readFile;