@scrabble-solver/word-lists 2.9.3 → 2.10.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 (38) hide show
  1. package/build/getDeDeWordList.js +2 -1
  2. package/build/getEnGbWordList.js +2 -1
  3. package/build/getEnUsWordList.js +2 -1
  4. package/build/getEsEsWordList.js +2 -1
  5. package/build/getFaIrWordList.d.ts +2 -0
  6. package/build/getFaIrWordList.js +9 -0
  7. package/build/getFrFrWordList.js +2 -1
  8. package/build/getPlPlWordList.js +9 -9
  9. package/build/getWordList.js +2 -0
  10. package/build/lib/downloadFile.js +5 -5
  11. package/build/lib/extractWords.d.ts +1 -1
  12. package/build/lib/extractWords.js +10 -7
  13. package/build/lib/findFirstWordIndex.d.ts +1 -1
  14. package/build/lib/findFirstWordIndex.js +2 -2
  15. package/build/lib/getTempFilepath.d.ts +2 -0
  16. package/build/lib/getTempFilepath.js +14 -0
  17. package/build/lib/getTxtWordList.d.ts +1 -1
  18. package/build/lib/getTxtWordList.js +5 -5
  19. package/build/lib/index.d.ts +1 -1
  20. package/build/lib/index.js +3 -3
  21. package/package.json +3 -4
  22. package/src/getDeDeWordList.ts +3 -1
  23. package/src/getEnGbWordList.ts +3 -1
  24. package/src/getEnUsWordList.ts +3 -1
  25. package/src/getEsEsWordList.ts +3 -1
  26. package/src/getFaIrWordList.ts +11 -0
  27. package/src/getFrFrWordList.ts +3 -1
  28. package/src/getPlPlWordList.ts +7 -7
  29. package/src/getWordList.ts +2 -0
  30. package/src/lib/downloadFile.ts +5 -5
  31. package/src/lib/extractWords.ts +13 -7
  32. package/src/lib/findFirstWordIndex.ts +2 -2
  33. package/src/lib/getTempFilepath.ts +13 -0
  34. package/src/lib/getTxtWordList.ts +3 -3
  35. package/src/lib/index.ts +1 -1
  36. package/build/lib/getTempFilename.d.ts +0 -2
  37. package/build/lib/getTempFilename.js +0 -10
  38. package/src/lib/getTempFilename.ts +0 -7
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@scrabble-solver/types");
3
4
  const lib_1 = require("./lib");
4
5
  const FILE_URL = 'https://raw.githubusercontent.com/hippler/german-wordlist/master/words.txt';
5
6
  const getDeDeWordList = async () => {
6
- return (0, lib_1.getTxtWordList)(FILE_URL);
7
+ return (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.DE_DE);
7
8
  };
8
9
  exports.default = getDeDeWordList;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@scrabble-solver/types");
3
4
  const lib_1 = require("./lib");
4
5
  const FILE_URL = 'https://www.wordgamedictionary.com/sowpods/download/sowpods.txt';
5
6
  const getEnGbWordList = async () => {
6
- return (0, lib_1.getTxtWordList)(FILE_URL);
7
+ return (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.EN_GB);
7
8
  };
8
9
  exports.default = getEnGbWordList;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@scrabble-solver/types");
3
4
  const lib_1 = require("./lib");
4
5
  const FILE_URL = 'https://www.wordgamedictionary.com/twl06/download/twl06.txt';
5
6
  const getEnUsWordList = async () => {
6
- return (0, lib_1.getTxtWordList)(FILE_URL);
7
+ return (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.EN_US);
7
8
  };
8
9
  exports.default = getEnUsWordList;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@scrabble-solver/types");
3
4
  const lib_1 = require("./lib");
4
5
  const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/fise-2/master/fise-2.txt';
5
6
  const getEsEsWordList = async () => {
6
- const words = await (0, lib_1.getTxtWordList)(FILE_URL);
7
+ const words = await (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.ES_ES);
7
8
  return words.map(normalizeWord);
8
9
  };
9
10
  const normalizeWord = (word) => {
@@ -0,0 +1,2 @@
1
+ declare const getFaIrWordList: () => Promise<string[]>;
2
+ export default getFaIrWordList;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@scrabble-solver/types");
4
+ const lib_1 = require("./lib");
5
+ const FILE_URL = 'https://raw.githubusercontent.com/MansourM/persian-to-persian-dictionary/main/moein/words.txt';
6
+ const getFaIrWordList = async () => {
7
+ return (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.FA_IR);
8
+ };
9
+ exports.default = getFaIrWordList;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@scrabble-solver/types");
3
4
  const lib_1 = require("./lib");
4
5
  const FILE_URL =
5
6
  // eslint-disable-next-line max-len
6
7
  'https://raw.githubusercontent.com/hbenbel/French-Dictionary/a573eab10cc798d7d5da7daab4d2ac0259bb46a3/dictionary/dictionary.txt';
7
8
  const getFrFrWordList = async () => {
8
- const words = await (0, lib_1.getTxtWordList)(FILE_URL);
9
+ const words = await (0, lib_1.getTxtWordList)(FILE_URL, types_1.Locale.FR_FR);
9
10
  return words.map(normalizeWord);
10
11
  };
11
12
  const normalizeWord = (word) => {
@@ -4,21 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const cheerio_1 = require("cheerio");
7
- const memfs_1 = require("memfs");
7
+ const fs_1 = __importDefault(require("fs"));
8
8
  const unzipper_1 = __importDefault(require("unzipper"));
9
9
  const url_1 = require("url");
10
10
  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 tempFilename = (0, lib_1.getTempFilename)();
14
+ const tempFilepath = (0, lib_1.getTempFilepath)();
15
15
  const zipUrl = await fetchZipUrl(PAGE_URL);
16
16
  const zipTempFilename = await (0, lib_1.downloadFile)(zipUrl);
17
- await unzip(zipTempFilename, tempFilename);
18
- memfs_1.fs.unlinkSync(zipTempFilename);
19
- const file = memfs_1.fs.readFileSync(tempFilename, 'utf-8');
20
- memfs_1.fs.unlinkSync(tempFilename);
21
- const words = (0, lib_1.extractWords)(file.toLocaleString());
17
+ await unzip(zipTempFilename, tempFilepath);
18
+ fs_1.default.unlinkSync(zipTempFilename);
19
+ const file = fs_1.default.readFileSync(tempFilepath, 'utf-8');
20
+ fs_1.default.unlinkSync(tempFilepath);
21
+ const words = (0, lib_1.extractWords)(file.toLocaleString(), 'pl-PL');
22
22
  return words;
23
23
  };
24
24
  const fetchZipUrl = async (url) => {
@@ -40,13 +40,13 @@ const parseZipContainingPage = (html) => {
40
40
  return zipFilename;
41
41
  };
42
42
  const unzip = (zipFilename, outputFilename) => {
43
- return memfs_1.fs
43
+ return fs_1.default
44
44
  .createReadStream(zipFilename)
45
45
  .pipe(unzipper_1.default.Parse())
46
46
  .on('entry', (entry) => {
47
47
  const fileName = entry.path;
48
48
  if (fileName === FILE_TO_EXTRACT_FROM_ZIP) {
49
- entry.pipe(memfs_1.fs.createWriteStream(outputFilename));
49
+ entry.pipe(fs_1.default.createWriteStream(outputFilename));
50
50
  }
51
51
  else {
52
52
  entry.autodrain();
@@ -8,6 +8,7 @@ const getDeDeWordList_1 = __importDefault(require("./getDeDeWordList"));
8
8
  const getEnGbWordList_1 = __importDefault(require("./getEnGbWordList"));
9
9
  const getEnUsWordList_1 = __importDefault(require("./getEnUsWordList"));
10
10
  const getEsEsWordList_1 = __importDefault(require("./getEsEsWordList"));
11
+ const getFaIrWordList_1 = __importDefault(require("./getFaIrWordList"));
11
12
  const getFrFrWordList_1 = __importDefault(require("./getFrFrWordList"));
12
13
  const getPlPlWordList_1 = __importDefault(require("./getPlPlWordList"));
13
14
  const localeMap = {
@@ -15,6 +16,7 @@ const localeMap = {
15
16
  [types_1.Locale.EN_GB]: getEnGbWordList_1.default,
16
17
  [types_1.Locale.EN_US]: getEnUsWordList_1.default,
17
18
  [types_1.Locale.ES_ES]: getEsEsWordList_1.default,
19
+ [types_1.Locale.FA_IR]: getFaIrWordList_1.default,
18
20
  [types_1.Locale.FR_FR]: getFrFrWordList_1.default,
19
21
  [types_1.Locale.PL_PL]: getPlPlWordList_1.default,
20
22
  };
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const follow_redirects_1 = require("follow-redirects");
7
- const memfs_1 = require("memfs");
8
- const getTempFilename_1 = __importDefault(require("./getTempFilename"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const getTempFilepath_1 = __importDefault(require("./getTempFilepath"));
9
9
  const downloadFile = (url) => {
10
10
  return new Promise((resolve, reject) => {
11
- const tempFilename = (0, getTempFilename_1.default)();
11
+ const tempFilepath = (0, getTempFilepath_1.default)();
12
12
  const protocol = url.startsWith('https') ? follow_redirects_1.https : follow_redirects_1.http;
13
- const writeStream = memfs_1.fs.createWriteStream(tempFilename);
13
+ const writeStream = fs_1.default.createWriteStream(tempFilepath);
14
14
  const request = protocol.get(url, (response) => {
15
15
  if (typeof response.statusCode === 'undefined' || response.statusCode >= 400) {
16
16
  reject(new Error(`Cannot download file: ${url}`));
@@ -23,7 +23,7 @@ const downloadFile = (url) => {
23
23
  response.on('end', () => {
24
24
  writeStream.on('finish', () => {
25
25
  writeStream.close();
26
- resolve(tempFilename);
26
+ resolve(tempFilepath);
27
27
  });
28
28
  });
29
29
  response.pipe(writeStream);
@@ -1,2 +1,2 @@
1
- declare const extractWords: (file: string) => string[];
1
+ declare const extractWords: (file: string, locale: string) => string[];
2
2
  export default extractWords;
@@ -4,13 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const findFirstWordIndex_1 = __importDefault(require("./findFirstWordIndex"));
7
- const extractWords = (file) => {
8
- const lines = file.replace(/\r/g, '').split('\n');
9
- const firstWordIndex = (0, findFirstWordIndex_1.default)(lines);
10
- const words = lines
11
- .slice(firstWordIndex)
12
- .filter((word) => word.trim().length > 0)
13
- .map((word) => word.toLocaleLowerCase());
7
+ const extractWords = (file, locale) => {
8
+ const lines = file.split(/\r?\n/g);
9
+ const firstWordIndex = (0, findFirstWordIndex_1.default)(lines, locale);
10
+ const words = [];
11
+ for (let i = firstWordIndex; i < lines.length; ++i) {
12
+ const trimmed = lines[i].trim();
13
+ if (trimmed.length > 0) {
14
+ words.push(trimmed.toLocaleLowerCase());
15
+ }
16
+ }
14
17
  return words;
15
18
  };
16
19
  exports.default = extractWords;
@@ -1,2 +1,2 @@
1
- declare const findFirstWordIndex: (lines: string[]) => number;
1
+ declare const findFirstWordIndex: (lines: string[], locale: string) => number;
2
2
  export default findFirstWordIndex;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const findFirstWordIndex = (lines) => {
3
+ const findFirstWordIndex = (lines, locale) => {
4
4
  const firstWordIndex = lines.findIndex((line, index) => {
5
5
  const nextLine = line[index + 1] || '';
6
- const isNextLineInOrder = line.localeCompare(nextLine) === 1;
6
+ const isNextLineInOrder = line.localeCompare(nextLine, locale) > 0;
7
7
  const hasWhitespace = Boolean(line.match(/\s/));
8
8
  const isEmpty = line.trim().length === 0;
9
9
  return !isEmpty && !hasWhitespace && isNextLineInOrder;
@@ -0,0 +1,2 @@
1
+ declare const getTempFilepath: () => string;
2
+ export default getTempFilepath;
@@ -0,0 +1,14 @@
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 os_1 = __importDefault(require("os"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const getHash_1 = __importDefault(require("./getHash"));
9
+ const OUTPUT_DIRECTORY = path_1.default.resolve(os_1.default.homedir(), '.scrabble-solver');
10
+ const getTempFilepath = () => {
11
+ const filename = `${(0, getHash_1.default)()}.txt`;
12
+ return path_1.default.join(OUTPUT_DIRECTORY, filename);
13
+ };
14
+ exports.default = getTempFilepath;
@@ -1,2 +1,2 @@
1
- declare const getTxtWordList: (url: string) => Promise<string[]>;
1
+ declare const getTxtWordList: (url: string, locale: string) => Promise<string[]>;
2
2
  export default getTxtWordList;
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const memfs_1 = require("memfs");
6
+ const fs_1 = __importDefault(require("fs"));
7
7
  const downloadFile_1 = __importDefault(require("./downloadFile"));
8
8
  const extractWords_1 = __importDefault(require("./extractWords"));
9
- const getTxtWordList = async (url) => {
9
+ const getTxtWordList = async (url, locale) => {
10
10
  const tempFilename = await (0, downloadFile_1.default)(url);
11
- const file = memfs_1.fs.readFileSync(tempFilename, 'utf-8');
12
- const words = (0, extractWords_1.default)(file.toLocaleString());
13
- memfs_1.fs.unlinkSync(tempFilename);
11
+ const file = fs_1.default.readFileSync(tempFilename, 'utf-8');
12
+ const words = (0, extractWords_1.default)(file.toLocaleString(), locale);
13
+ fs_1.default.unlinkSync(tempFilename);
14
14
  return words;
15
15
  };
16
16
  exports.default = getTxtWordList;
@@ -3,5 +3,5 @@ export { default as downloadHtml } from './downloadHtml';
3
3
  export { default as extractWords } from './extractWords';
4
4
  export { default as findFirstWordIndex } from './findFirstWordIndex';
5
5
  export { default as getHash } from './getHash';
6
- export { default as getTempFilename } from './getTempFilename';
6
+ export { default as getTempFilepath } from './getTempFilepath';
7
7
  export { default as getTxtWordList } from './getTxtWordList';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getTxtWordList = exports.getTempFilename = exports.getHash = exports.findFirstWordIndex = exports.extractWords = exports.downloadHtml = exports.downloadFile = void 0;
6
+ exports.getTxtWordList = exports.getTempFilepath = exports.getHash = exports.findFirstWordIndex = exports.extractWords = exports.downloadHtml = exports.downloadFile = void 0;
7
7
  var downloadFile_1 = require("./downloadFile");
8
8
  Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return __importDefault(downloadFile_1).default; } });
9
9
  var downloadHtml_1 = require("./downloadHtml");
@@ -14,7 +14,7 @@ var findFirstWordIndex_1 = require("./findFirstWordIndex");
14
14
  Object.defineProperty(exports, "findFirstWordIndex", { enumerable: true, get: function () { return __importDefault(findFirstWordIndex_1).default; } });
15
15
  var getHash_1 = require("./getHash");
16
16
  Object.defineProperty(exports, "getHash", { enumerable: true, get: function () { return __importDefault(getHash_1).default; } });
17
- var getTempFilename_1 = require("./getTempFilename");
18
- Object.defineProperty(exports, "getTempFilename", { enumerable: true, get: function () { return __importDefault(getTempFilename_1).default; } });
17
+ var getTempFilepath_1 = require("./getTempFilepath");
18
+ Object.defineProperty(exports, "getTempFilepath", { enumerable: true, get: function () { return __importDefault(getTempFilepath_1).default; } });
19
19
  var getTxtWordList_1 = require("./getTxtWordList");
20
20
  Object.defineProperty(exports, "getTxtWordList", { enumerable: true, get: function () { return __importDefault(getTxtWordList_1).default; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/word-lists",
3
- "version": "2.9.3",
3
+ "version": "2.10.0",
4
4
  "description": "Scrabble Solver 2 - Word lists",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -24,15 +24,14 @@
24
24
  "clean:force": "npm run clean && rimraf package-lock.json"
25
25
  },
26
26
  "dependencies": {
27
- "@scrabble-solver/types": "^2.9.3",
27
+ "@scrabble-solver/types": "^2.10.0",
28
28
  "cheerio": "^1.0.0-rc.12",
29
29
  "follow-redirects": "^1.15.2",
30
- "memfs": "^3.4.7",
31
30
  "unzipper": "^0.10.11"
32
31
  },
33
32
  "devDependencies": {
34
33
  "@types/follow-redirects": "^1.14.1",
35
34
  "@types/unzipper": "^0.10.5"
36
35
  },
37
- "gitHead": "ef8d030cbb76256a377f747f7ebe4b85b7eba61e"
36
+ "gitHead": "7fd0f6bf536fca88c18ce02e320da71b0c6d6f61"
38
37
  }
@@ -1,9 +1,11 @@
1
+ import { Locale } from '@scrabble-solver/types';
2
+
1
3
  import { getTxtWordList } from './lib';
2
4
 
3
5
  const FILE_URL = 'https://raw.githubusercontent.com/hippler/german-wordlist/master/words.txt';
4
6
 
5
7
  const getDeDeWordList = async (): Promise<string[]> => {
6
- return getTxtWordList(FILE_URL);
8
+ return getTxtWordList(FILE_URL, Locale.DE_DE);
7
9
  };
8
10
 
9
11
  export default getDeDeWordList;
@@ -1,9 +1,11 @@
1
+ import { Locale } from '@scrabble-solver/types';
2
+
1
3
  import { getTxtWordList } from './lib';
2
4
 
3
5
  const FILE_URL = 'https://www.wordgamedictionary.com/sowpods/download/sowpods.txt';
4
6
 
5
7
  const getEnGbWordList = async (): Promise<string[]> => {
6
- return getTxtWordList(FILE_URL);
8
+ return getTxtWordList(FILE_URL, Locale.EN_GB);
7
9
  };
8
10
 
9
11
  export default getEnGbWordList;
@@ -1,9 +1,11 @@
1
+ import { Locale } from '@scrabble-solver/types';
2
+
1
3
  import { getTxtWordList } from './lib';
2
4
 
3
5
  const FILE_URL = 'https://www.wordgamedictionary.com/twl06/download/twl06.txt';
4
6
 
5
7
  const getEnUsWordList = async (): Promise<string[]> => {
6
- return getTxtWordList(FILE_URL);
8
+ return getTxtWordList(FILE_URL, Locale.EN_US);
7
9
  };
8
10
 
9
11
  export default getEnUsWordList;
@@ -1,9 +1,11 @@
1
+ import { Locale } from '@scrabble-solver/types';
2
+
1
3
  import { getTxtWordList } from './lib';
2
4
 
3
5
  const FILE_URL = 'https://raw.githubusercontent.com/kamilmielnik/fise-2/master/fise-2.txt';
4
6
 
5
7
  const getEsEsWordList = async (): Promise<string[]> => {
6
- const words = await getTxtWordList(FILE_URL);
8
+ const words = await getTxtWordList(FILE_URL, Locale.ES_ES);
7
9
  return words.map(normalizeWord);
8
10
  };
9
11
 
@@ -0,0 +1,11 @@
1
+ import { Locale } from '@scrabble-solver/types';
2
+
3
+ import { getTxtWordList } from './lib';
4
+
5
+ const FILE_URL = 'https://raw.githubusercontent.com/MansourM/persian-to-persian-dictionary/main/moein/words.txt';
6
+
7
+ const getFaIrWordList = async (): Promise<string[]> => {
8
+ return getTxtWordList(FILE_URL, Locale.FA_IR);
9
+ };
10
+
11
+ export default getFaIrWordList;
@@ -1,3 +1,5 @@
1
+ import { Locale } from '@scrabble-solver/types';
2
+
1
3
  import { getTxtWordList } from './lib';
2
4
 
3
5
  const FILE_URL =
@@ -5,7 +7,7 @@ const FILE_URL =
5
7
  'https://raw.githubusercontent.com/hbenbel/French-Dictionary/a573eab10cc798d7d5da7daab4d2ac0259bb46a3/dictionary/dictionary.txt';
6
8
 
7
9
  const getFrFrWordList = async (): Promise<string[]> => {
8
- const words = await getTxtWordList(FILE_URL);
10
+ const words = await getTxtWordList(FILE_URL, Locale.FR_FR);
9
11
  return words.map(normalizeWord);
10
12
  };
11
13
 
@@ -1,22 +1,22 @@
1
1
  import { load } from 'cheerio';
2
- import { fs } from 'memfs';
2
+ import fs from 'fs';
3
3
  import unzipper from 'unzipper';
4
4
  import { URL } from 'url';
5
5
 
6
- import { downloadFile, downloadHtml, extractWords, getTempFilename } from './lib';
6
+ import { downloadFile, downloadHtml, extractWords, getTempFilepath } from './lib';
7
7
 
8
8
  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 tempFilename = getTempFilename();
12
+ const tempFilepath = getTempFilepath();
13
13
  const zipUrl = await fetchZipUrl(PAGE_URL);
14
14
  const zipTempFilename = await downloadFile(zipUrl);
15
- await unzip(zipTempFilename, tempFilename);
15
+ await unzip(zipTempFilename, tempFilepath);
16
16
  fs.unlinkSync(zipTempFilename);
17
- const file = fs.readFileSync(tempFilename, 'utf-8');
18
- fs.unlinkSync(tempFilename);
19
- const words = extractWords(file.toLocaleString());
17
+ const file = fs.readFileSync(tempFilepath, 'utf-8');
18
+ fs.unlinkSync(tempFilepath);
19
+ const words = extractWords(file.toLocaleString(), 'pl-PL');
20
20
  return words;
21
21
  };
22
22
 
@@ -4,6 +4,7 @@ import getDeDeWordList from './getDeDeWordList';
4
4
  import getEnGbWordList from './getEnGbWordList';
5
5
  import getEnUsWordList from './getEnUsWordList';
6
6
  import getEsEsWordList from './getEsEsWordList';
7
+ import getFaIrWordList from './getFaIrWordList';
7
8
  import getFrFrWordList from './getFrFrWordList';
8
9
  import getPlPlWordList from './getPlPlWordList';
9
10
 
@@ -12,6 +13,7 @@ const localeMap: Record<Locale, () => Promise<string[]>> = {
12
13
  [Locale.EN_GB]: getEnGbWordList,
13
14
  [Locale.EN_US]: getEnUsWordList,
14
15
  [Locale.ES_ES]: getEsEsWordList,
16
+ [Locale.FA_IR]: getFaIrWordList,
15
17
  [Locale.FR_FR]: getFrFrWordList,
16
18
  [Locale.PL_PL]: getPlPlWordList,
17
19
  };
@@ -1,13 +1,13 @@
1
1
  import { http, https } from 'follow-redirects';
2
- import { fs } from 'memfs';
2
+ import fs from 'fs';
3
3
 
4
- import getTempFilename from './getTempFilename';
4
+ import getTempFilepath from './getTempFilepath';
5
5
 
6
6
  const downloadFile = (url: string): Promise<string> => {
7
7
  return new Promise((resolve, reject) => {
8
- const tempFilename = getTempFilename();
8
+ const tempFilepath = getTempFilepath();
9
9
  const protocol = url.startsWith('https') ? https : http;
10
- const writeStream = fs.createWriteStream(tempFilename);
10
+ const writeStream = fs.createWriteStream(tempFilepath);
11
11
  const request = protocol.get(url, (response) => {
12
12
  if (typeof response.statusCode === 'undefined' || response.statusCode >= 400) {
13
13
  reject(new Error(`Cannot download file: ${url}`));
@@ -22,7 +22,7 @@ const downloadFile = (url: string): Promise<string> => {
22
22
  response.on('end', () => {
23
23
  writeStream.on('finish', () => {
24
24
  writeStream.close();
25
- resolve(tempFilename);
25
+ resolve(tempFilepath);
26
26
  });
27
27
  });
28
28
 
@@ -1,12 +1,18 @@
1
1
  import findFirstWordIndex from './findFirstWordIndex';
2
2
 
3
- const extractWords = (file: string): string[] => {
4
- const lines = file.replace(/\r/g, '').split('\n');
5
- const firstWordIndex = findFirstWordIndex(lines);
6
- const words = lines
7
- .slice(firstWordIndex)
8
- .filter((word) => word.trim().length > 0)
9
- .map((word) => word.toLocaleLowerCase());
3
+ const extractWords = (file: string, locale: string): string[] => {
4
+ const lines = file.split(/\r?\n/g);
5
+ const firstWordIndex = findFirstWordIndex(lines, locale);
6
+ const words: string[] = [];
7
+
8
+ for (let i = firstWordIndex; i < lines.length; ++i) {
9
+ const trimmed = lines[i].trim();
10
+
11
+ if (trimmed.length > 0) {
12
+ words.push(trimmed.toLocaleLowerCase());
13
+ }
14
+ }
15
+
10
16
  return words;
11
17
  };
12
18
 
@@ -1,7 +1,7 @@
1
- const findFirstWordIndex = (lines: string[]): number => {
1
+ const findFirstWordIndex = (lines: string[], locale: string): number => {
2
2
  const firstWordIndex = lines.findIndex((line, index) => {
3
3
  const nextLine = line[index + 1] || '';
4
- const isNextLineInOrder = line.localeCompare(nextLine) === 1;
4
+ const isNextLineInOrder = line.localeCompare(nextLine, locale) > 0;
5
5
  const hasWhitespace = Boolean(line.match(/\s/));
6
6
  const isEmpty = line.trim().length === 0;
7
7
 
@@ -0,0 +1,13 @@
1
+ import os from 'os';
2
+ import path from 'path';
3
+
4
+ import getHash from './getHash';
5
+
6
+ const OUTPUT_DIRECTORY = path.resolve(os.homedir(), '.scrabble-solver');
7
+
8
+ const getTempFilepath = (): string => {
9
+ const filename = `${getHash()}.txt`;
10
+ return path.join(OUTPUT_DIRECTORY, filename);
11
+ };
12
+
13
+ export default getTempFilepath;
@@ -1,12 +1,12 @@
1
- import { fs } from 'memfs';
1
+ import fs from 'fs';
2
2
 
3
3
  import downloadFile from './downloadFile';
4
4
  import extractWords from './extractWords';
5
5
 
6
- const getTxtWordList = async (url: string): Promise<string[]> => {
6
+ const getTxtWordList = async (url: string, locale: string): Promise<string[]> => {
7
7
  const tempFilename = await downloadFile(url);
8
8
  const file = fs.readFileSync(tempFilename, 'utf-8');
9
- const words = extractWords(file.toLocaleString());
9
+ const words = extractWords(file.toLocaleString(), locale);
10
10
  fs.unlinkSync(tempFilename);
11
11
  return words;
12
12
  };
package/src/lib/index.ts CHANGED
@@ -3,5 +3,5 @@ export { default as downloadHtml } from './downloadHtml';
3
3
  export { default as extractWords } from './extractWords';
4
4
  export { default as findFirstWordIndex } from './findFirstWordIndex';
5
5
  export { default as getHash } from './getHash';
6
- export { default as getTempFilename } from './getTempFilename';
6
+ export { default as getTempFilepath } from './getTempFilepath';
7
7
  export { default as getTxtWordList } from './getTxtWordList';
@@ -1,2 +0,0 @@
1
- declare const getTempFilename: () => string;
2
- export default getTempFilename;
@@ -1,10 +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 getHash_1 = __importDefault(require("./getHash"));
7
- const getTempFilename = () => {
8
- return `/${(0, getHash_1.default)()}.txt`;
9
- };
10
- exports.default = getTempFilename;
@@ -1,7 +0,0 @@
1
- import getHash from './getHash';
2
-
3
- const getTempFilename = (): string => {
4
- return `/${getHash()}.txt`;
5
- };
6
-
7
- export default getTempFilename;